Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle_plugins(): only reconfigure package upon successful enabling/disabling #212

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading