[education/rkward] /: Add command line option --setup (esp. useful to force re-installation of R package during development)
Thomas Friedrichsmeier
null at kde.org
Sat Jun 8 23:21:01 BST 2024
Git commit b5c6844135f490a5c8eeed9ef6fb5dc620b297b3 by Thomas Friedrichsmeier.
Committed on 08/06/2024 at 22:08.
Pushed by tfry into branch 'master'.
Add command line option --setup (esp. useful to force re-installation of R package during development)
M +1 -0 ChangeLog
M +2 -0 rkward/misc/rkcommandlineargs.cpp
M +1 -0 rkward/rbackend/rkfrontendtransmitter.cpp
M +12 -11 rkward/rbackend/rkrbackend.cpp
M +3 -3 rkward/rbackend/rkrbackend.h
M +5 -2 rkward/rbackend/rkrbackendprotocol_backend.cpp
M +3 -4 rkward/rkward.cpp
M +3 -2 rkward/settings/rksettingsmodulegeneral.cpp
https://invent.kde.org/education/rkward/-/commit/b5c6844135f490a5c8eeed9ef6fb5dc620b297b3
diff --git a/ChangeLog b/ChangeLog
index e2387eeb8..4e65eb34b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+- Added: Command line option "--setup" to force (re-)initialization as if a new version of RKWard had been installed
- Fixed: R functions loadhistory(), savehistory(), and timestamp() broken
- Changed: R shared library is now loaded, dynamically, rather than linked at compile time.
This allows more flexibility on which R version to use at runtime, esp. in the context of AppImage binaries
diff --git a/rkward/misc/rkcommandlineargs.cpp b/rkward/misc/rkcommandlineargs.cpp
index 6fdb06ae4..e463438bd 100644
--- a/rkward/misc/rkcommandlineargs.cpp
+++ b/rkward/misc/rkcommandlineargs.cpp
@@ -35,6 +35,7 @@ RKCommandLineArgs::RKCommandLineArgs(KAboutData *about, QCoreApplication &app) {
parser.addOption(QCommandLineOption("autoreuse", i18n("Behaves like --reuse, if any file arguments are also given, starts a new instance, otherwise. Intended for use in the .desktop file.")));
parser.addOption(QCommandLineOption("nowarn-external", i18n("When used in conjunction with rkward://runplugin/-URLs specified on the command line, suppresses the warning about application-external (untrusted) links.")));
parser.addOption(QCommandLineOption("quirkmode", i18n("Disable some startup validation code. Experimental option, not intended for regular use.")));
+ parser.addOption(QCommandLineOption("setup", i18n("Act as if the version of RKWard had changed (show setup wizard, and (re-)install rkward R package).")));
parser.addPositionalArgument("files", i18n("File or files to open, typically a workspace, or an R script file. When loading several things, you should specify the workspace, first."), "[Files...]");
parser.process(app);
@@ -51,6 +52,7 @@ RKCommandLineArgs::RKCommandLineArgs(KAboutData *about, QCoreApplication &app) {
storage[AutoReuse] = parser.isSet("autoreuse");
storage[NoWarnExternal] = parser.isSet("nowarn-external");
storage[QuirkMode] = parser.isSet("quirkmode");
+ storage[Setup] = parser.isSet("setup");
QStringList url_args = parser.positionalArguments ();
if (!url_args.isEmpty ()) {
for (int i = 0; i < url_args.size(); ++i) {
diff --git a/rkward/rbackend/rkfrontendtransmitter.cpp b/rkward/rbackend/rkfrontendtransmitter.cpp
index cc8a6d9a7..8b4307e7c 100644
--- a/rkward/rbackend/rkfrontendtransmitter.cpp
+++ b/rkward/rbackend/rkfrontendtransmitter.cpp
@@ -187,6 +187,7 @@ void RKFrontendTransmitter::run () {
args.append(backend_executable);
#endif
+ if (RKSettingsModuleGeneral::rkwardVersionChanged()) args.append(QStringLiteral("--setup"));
args.append (QStringLiteral("--debug-level=") + QString::number (RK_Debug::RK_Debug_Level));
// NOTE: QProcess quotes its arguments, *but* properly passing all spaces and quotes through the R CMD wrapper, seems near(?) impossible on Windows. Instead, we use percent encoding, internally.
args.append (QStringLiteral("--server-name=") + server->fullServerName ().toUtf8 ().toPercentEncoding ());
diff --git a/rkward/rbackend/rkrbackend.cpp b/rkward/rbackend/rkrbackend.cpp
index b3b99f88c..6130f18c1 100644
--- a/rkward/rbackend/rkrbackend.cpp
+++ b/rkward/rbackend/rkrbackend.cpp
@@ -1,6 +1,6 @@
/*
rkrbackend - This file is part of RKWard (https://rkward.kde.org). Created: Sun Jul 25 2004
-SPDX-FileCopyrightText: 2004-2020 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2004-2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -1443,12 +1443,12 @@ void RKRBackend::printAndClearCapturedMessages (bool with_header) {
catToOutputFile (out);
}
-void RKRBackend::run (const QString &locale_dir) {
+void RKRBackend::run(const QString &locale_dir, bool setup) {
RK_TRACE (RBACKEND);
killed = NotKilled;
previous_command = nullptr;
- initialize (locale_dir);
+ initialize(locale_dir, setup);
enterEventLoop();
}
@@ -1589,7 +1589,7 @@ GenericRRequestResult RKRBackend::doRCallRequest(const QString &call, const QVar
return request.getResult();
}
-void RKRBackend::initialize (const QString &locale_dir) {
+void RKRBackend::initialize(const QString &locale_dir, bool setup) {
RK_TRACE (RBACKEND);
// in RInterface::RInterface() we have created a fake RCommand to capture all the output/errors during startup. Fetch it
@@ -1604,12 +1604,13 @@ void RKRBackend::initialize (const QString &locale_dir) {
// Try to load rkward package. If that fails, or is the wrong version, try to install
// rkward package, then load again.
QString libloc = getLibLoc();
- QString versioncheck = QString ("stopifnot(.rk.app.version==\"%1\")\n").arg (RKWARD_VERSION);
+ QString versioncheck = QString("stopifnot(.rk.app.version==\"%1\")").arg(RKWARD_VERSION);
QString command = "local({\n"
- " libloc <- " + RKRSharedFunctionality::quote (libloc) + "\n"
+ " libloc <- " + RKRSharedFunctionality::quote(libloc) + "\n"
" if (!dir.exists (libloc)) dir.create(libloc, recursive=TRUE)\n"
" ok <- FALSE\n"
- " suppressWarnings (try ({library (\"rkward\", lib.loc=libloc); " + versioncheck + "; ok <- TRUE}))\n"
+ + (setup ? "# skipping: " : "") +
+ " suppressWarnings (try ({library (\"rkward\", lib.loc=libloc); " + versioncheck + "; ok <- TRUE}))\n"
" if (!ok) {\n"
" suppressWarnings (try (detach(\"package:rkward\", unload=TRUE)))\n"
" install.packages(normalizePath(paste(libloc, \"..\", c (\"rkward.tgz\", \"rkwardtests.tgz\"), sep=\"/\")), lib=libloc, repos=NULL, type=\"source\", INSTALL_opts=\"--no-multiarch\")\n"
@@ -1617,10 +1618,10 @@ void RKRBackend::initialize (const QString &locale_dir) {
" }\n"
" .libPaths(c(.libPaths(), libloc))\n" // Add to end search path: Will be avaiable for help serach, but hopefully, not get into the way, otherwise
"})\n";
- if (!runDirectCommand (command)) lib_load_fail = true;
- RK_setupGettext (locale_dir); // must happen *after* package loading, since R will re-set it
- if (!runDirectCommand (versioncheck)) lib_load_fail = true;
- if (!runDirectCommand (".rk.fix.assignments ()\n")) sink_fail = true;
+ if (!runDirectCommand(command)) lib_load_fail = true;
+ RK_setupGettext(locale_dir); // must happen *after* package loading, since R will re-set it
+ if (!runDirectCommand(versioncheck + "\n")) lib_load_fail = true;
+ if (!runDirectCommand(".rk.fix.assignments ()\n")) sink_fail = true;
// error/output sink and help browser
if (!runDirectCommand ("options (error=quote (.rk.do.error ()))\n")) sink_fail = true;
diff --git a/rkward/rbackend/rkrbackend.h b/rkward/rbackend/rkrbackend.h
index b79231576..e13c4aa95 100644
--- a/rkward/rbackend/rkrbackend.h
+++ b/rkward/rbackend/rkrbackend.h
@@ -1,6 +1,6 @@
/*
rkrbackend - This file is part of the RKWard project. Created: Sun Jul 25 2004
-SPDX-FileCopyrightText: 2004-2020 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2004-2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -73,7 +73,7 @@ public:
/** initializes the R-backend. Emits an RCallbackType::Started-request (with any error messages) when done.
Note that you should call initialize only once in a application */
- void initialize (const QString &locale_dir);
+ void initialize(const QString &locale_dir, bool setup);
void enterEventLoop ();
protected:
@@ -160,7 +160,7 @@ public:
/** A list of symbols that have been assigned new values during the current command */
QStringList changed_symbol_names;
/** the main loop. See \ref RKRBackend for a more detailed description */
- void run (const QString &locale_dir);
+ void run(const QString &locale_dir, bool setup);
static void scheduleInterrupt ();
void startOutputCapture ();
diff --git a/rkward/rbackend/rkrbackendprotocol_backend.cpp b/rkward/rbackend/rkrbackendprotocol_backend.cpp
index b4882daef..02e670619 100644
--- a/rkward/rbackend/rkrbackendprotocol_backend.cpp
+++ b/rkward/rbackend/rkrbackendprotocol_backend.cpp
@@ -93,7 +93,8 @@ SPDX-License-Identifier: GPL-2.0-or-later
QString servername, rkd_server_name;
QString data_dir, locale_dir;
- QStringList args = app.arguments ();
+ QStringList args = app.arguments();
+ bool setup = false;
for (int i = 1; i < args.count (); ++i) {
if (args[i].startsWith (QLatin1String ("--debug-level"))) {
RK_Debug::RK_Debug_Level = args[i].section ('=', 1).toInt ();
@@ -105,6 +106,8 @@ SPDX-License-Identifier: GPL-2.0-or-later
locale_dir = QUrl::fromPercentEncoding (args[i].section ('=', 1).toUtf8 ());
} else if (args[i].startsWith (QLatin1String ("--rkd-server-name"))) {
rkd_server_name = QUrl::fromPercentEncoding (args[i].section ('=', 1).toUtf8 ());
+ } else if (args[i] == QLatin1String("--setup")) {
+ setup = true;
} else {
printf ("unknown argument %s", qPrintable (args[i]));
}
@@ -128,7 +131,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
RKRBackendProtocolBackend::p_transmitter = &transmitter; // cppcheck-suppress danglingLifetime ; -> valid for the lifetime of the backend
RKRBackendProtocolBackend backend (data_dir, rkd_server_name);
transmitter.start ();
- RKRBackend::this_pointer->run (locale_dir);
+ RKRBackend::this_pointer->run(locale_dir, setup);
// NOTE:: Since some unknown version of R (4.3.0 at the latest, but probably much earlier), run_Rmainloop() does not return, it will
// eventually exit, instead.
RKRBackendProtocolBackend::doExit();
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index a750416e8..1905784d1 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -372,12 +372,11 @@ void RKWardMainWindow::startR () {
// This may look redundant at first (since the package still needs to be installed from the
// backend. However, if frontend and backend are on different machines (eventually), only the
// filesPath is shared between both.
- QStringList packages;
- packages << "rkward.tgz" << "rkwardtests.tgz";
+ QStringList packages({"rkward.tgz", "rkwardtests.tgz"});
for (int i = 0; i < packages.size (); ++i) {
QString package = QDir (packages_path).absoluteFilePath (packages[i]);
- if (RKSettingsModuleGeneral::rkwardVersionChanged ()) {
- RK_DEBUG(APP, DL_INFO, "RKWard version changed. Discarding cached package at %s", qPrintable (package));
+ if (RKSettingsModuleGeneral::rkwardVersionChanged() || RKCommandLineArgs::get(RKCommandLineArgs::Setup).toBool()) {
+ RK_DEBUG(APP, DL_INFO, "RKWard version changed or setup requested. Discarding cached package at %s", qPrintable(package));
if(QFileInfo::exists(package)) RK_ASSERT(QFile::remove(package));
}
if (!QFileInfo::exists(package)) {
diff --git a/rkward/settings/rksettingsmodulegeneral.cpp b/rkward/settings/rksettingsmodulegeneral.cpp
index 27b8207fc..e7ed808bc 100644
--- a/rkward/settings/rksettingsmodulegeneral.cpp
+++ b/rkward/settings/rksettingsmodulegeneral.cpp
@@ -1,6 +1,6 @@
/*
rksettingsmodulegeneral - This file is part of RKWard (https://rkward.kde.org). Created: Fri Jul 30 2004
-SPDX-FileCopyrightText: 2004-2022 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
+SPDX-FileCopyrightText: 2004-2024 by Thomas Friedrichsmeier <thomas.friedrichsmeier at kdemail.net>
SPDX-FileContributor: The RKWard Team <rkward-devel at kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -22,6 +22,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
#include "../misc/getfilenamewidget.h"
#include "../misc/rkspinbox.h"
#include "../misc/rkcommonfunctions.h"
+#include "../misc/rkcommandlineargs.h"
#include "../misc/rkstandardicons.h"
#include "../misc/rkstyle.h"
@@ -172,7 +173,7 @@ void RKSettingsModuleGeneral::syncConfig(KConfig *config, RKConfigBase::ConfigSy
config->deleteGroup(groups[i]);
}
}
- rkward_version_changed = (cg.readEntry("previous runtime version", QString()) != RKWARD_VERSION);
+ rkward_version_changed = (cg.readEntry("previous runtime version", QString()) != RKWARD_VERSION) || RKCommandLineArgs::get(RKCommandLineArgs::Setup).toBool();
} else {
cg.writeEntry("config file version", (int) RKWardConfig_Latest);
cg.writeEntry("previous runtime version", QString(RKWARD_VERSION));
More information about the rkward-tracker
mailing list