Skip to content

Commit 0daa5b1

Browse files
authored
Merge pull request #212 from r-spatial/plugin_skip_reconfig
handle_plugins(): only reconfigure package upon successful enabling/disabling
2 parents af218df + ebc8805 commit 0daa5b1

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: qgisprocess
22
Title: Use 'QGIS' Processing Algorithms
3-
Version: 0.3.0.9001
3+
Version: 0.3.0.9002
44
Authors@R: c(
55
person("Dewey", "Dunnington", , "[email protected]", role = "aut",
66
comment = c(ORCID = "0000-0002-9415-4582", affiliation = "Voltron Data")),

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
- Speed up various calls to the `qgis_process` backend by automatically implementing `--skip-loading-plugins` where possible (#201).
44
This benefits package startup time and the timing of `qgis_run_algorithm()`, `qgis_show_help()`, and several other functions.
55
This feature needs QGIS >= 3.36.
6+
- Don't renew the package cache when no plugins were successfully enabled or disabled (#212).
67
- Update the 'getting started' vignette (#206, #207):
7-
- advise using `qgis_search_algorithms()`.
8+
- advise to use `qgis_search_algorithms()`.
89
- in QGIS >= 3.36 the GRASS GIS provider is called `grass` instead of `grass7`.
910

1011
# qgisprocess 0.3.0

R/qgis-plugins.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,20 @@ handle_plugins <- function(names = NULL, quiet = FALSE, mode) {
221221
"{paste(names, collapse = ', ')}"
222222
))
223223

224-
if (mode == "enable") for (p in names) enable_plugin(p, quiet = quiet)
225-
if (mode == "disable") for (p in names) disable_plugin(p, quiet = quiet)
224+
counter <- 0L
225+
if (mode == "enable") for (p in names) {
226+
counter <- enable_plugin(p, quiet = quiet) + counter
227+
}
228+
if (mode == "disable") for (p in names) {
229+
counter <- disable_plugin(p, quiet = quiet) + counter
230+
}
226231

227-
if (!quiet) message("\nRebuilding cache to reflect current plugin state ...\n")
228-
qgis_configure(use_cached_data = FALSE, quiet = quiet)
232+
if (counter > 0L) {
233+
if (!quiet) {
234+
message("\nRebuilding cache to reflect current plugin state ...\n")
235+
}
236+
qgis_configure(use_cached_data = FALSE, quiet = quiet)
237+
}
229238

230239
invisible(qgis_plugins())
231240
}
@@ -234,6 +243,7 @@ handle_plugins <- function(names = NULL, quiet = FALSE, mode) {
234243

235244
#' @keywords internal
236245
enable_plugin <- function(name, quiet = FALSE) {
246+
error_detected <- FALSE
237247
tryCatch(
238248
{
239249
qgis_run(args = c("plugins", "enable", name))
@@ -244,14 +254,17 @@ enable_plugin <- function(name, quiet = FALSE) {
244254
"'{name}' was not successfully enabled. Error message was:\n\n{e}\n",
245255
ifelse("stderr" %in% names(e) && nchar(e$stderr) > 0, e$stderr, "")
246256
))
257+
assign("error_detected", TRUE, envir = parent.env(environment()))
247258
}
248259
)
260+
if (error_detected) invisible(FALSE) else invisible(TRUE)
249261
}
250262

251263

252264

253265
#' @keywords internal
254266
disable_plugin <- function(name, quiet = FALSE) {
267+
error_detected <- FALSE
255268
tryCatch(
256269
{
257270
qgis_run(args = c("plugins", "disable", name))
@@ -262,6 +275,8 @@ disable_plugin <- function(name, quiet = FALSE) {
262275
"'{name}' was not successfully disabled. Error message was:\n\n{e}\n",
263276
ifelse("stderr" %in% names(e) && nchar(e$stderr) > 0, e$stderr, "")
264277
))
278+
assign("error_detected", TRUE, envir = parent.env(environment()))
265279
}
266280
)
281+
if (error_detected) invisible(FALSE) else invisible(TRUE)
267282
}

0 commit comments

Comments
 (0)