Skip to content

Commit

Permalink
Merge pull request #212 from r-spatial/plugin_skip_reconfig
Browse files Browse the repository at this point in the history
handle_plugins(): only reconfigure package upon successful enabling/disabling
  • Loading branch information
florisvdh authored May 20, 2024
2 parents af218df + ebc8805 commit 0daa5b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qgisprocess
Title: Use 'QGIS' Processing Algorithms
Version: 0.3.0.9001
Version: 0.3.0.9002
Authors@R: c(
person("Dewey", "Dunnington", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0002-9415-4582", affiliation = "Voltron Data")),
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
- Speed up various calls to the `qgis_process` backend by automatically implementing `--skip-loading-plugins` where possible (#201).
This benefits package startup time and the timing of `qgis_run_algorithm()`, `qgis_show_help()`, and several other functions.
This feature needs QGIS >= 3.36.
- Don't renew the package cache when no plugins were successfully enabled or disabled (#212).
- Update the 'getting started' vignette (#206, #207):
- advise using `qgis_search_algorithms()`.
- advise to use `qgis_search_algorithms()`.
- in QGIS >= 3.36 the GRASS GIS provider is called `grass` instead of `grass7`.

# qgisprocess 0.3.0
Expand Down
23 changes: 19 additions & 4 deletions R/qgis-plugins.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,20 @@ handle_plugins <- function(names = NULL, quiet = FALSE, mode) {
"{paste(names, collapse = ', ')}"
))

if (mode == "enable") for (p in names) enable_plugin(p, quiet = quiet)
if (mode == "disable") for (p in names) disable_plugin(p, quiet = quiet)
counter <- 0L
if (mode == "enable") for (p in names) {
counter <- enable_plugin(p, quiet = quiet) + counter
}
if (mode == "disable") for (p in names) {
counter <- disable_plugin(p, quiet = quiet) + counter
}

if (!quiet) message("\nRebuilding cache to reflect current plugin state ...\n")
qgis_configure(use_cached_data = FALSE, quiet = quiet)
if (counter > 0L) {
if (!quiet) {
message("\nRebuilding cache to reflect current plugin state ...\n")
}
qgis_configure(use_cached_data = FALSE, quiet = quiet)
}

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

#' @keywords internal
enable_plugin <- function(name, quiet = FALSE) {
error_detected <- FALSE
tryCatch(
{
qgis_run(args = c("plugins", "enable", name))
Expand All @@ -244,14 +254,17 @@ enable_plugin <- function(name, quiet = FALSE) {
"'{name}' was not successfully enabled. Error message was:\n\n{e}\n",
ifelse("stderr" %in% names(e) && nchar(e$stderr) > 0, e$stderr, "")
))
assign("error_detected", TRUE, envir = parent.env(environment()))
}
)
if (error_detected) invisible(FALSE) else invisible(TRUE)
}



#' @keywords internal
disable_plugin <- function(name, quiet = FALSE) {
error_detected <- FALSE
tryCatch(
{
qgis_run(args = c("plugins", "disable", name))
Expand All @@ -262,6 +275,8 @@ disable_plugin <- function(name, quiet = FALSE) {
"'{name}' was not successfully disabled. Error message was:\n\n{e}\n",
ifelse("stderr" %in% names(e) && nchar(e$stderr) > 0, e$stderr, "")
))
assign("error_detected", TRUE, envir = parent.env(environment()))
}
)
if (error_detected) invisible(FALSE) else invisible(TRUE)
}

0 comments on commit 0daa5b1

Please sign in to comment.