Skip to content

Commit 19af3b7

Browse files
authored
Merge pull request #198 from r-spatial/warn_deprecated_algs
Handle deprecated algorithms explicitly
2 parents f63925a + d32d03b commit 19af3b7

File tree

9 files changed

+104
-11
lines changed

9 files changed

+104
-11
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.2.0.9002
3+
Version: 0.2.0.9003
44
Authors@R: c(
55
person("Dewey", "Dunnington", , "dewey@fishandwhistle.net", role = "aut",
66
comment = c(ORCID = "0000-0002-9415-4582", affiliation = "Voltron Data")),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ importFrom(assertthat,assert_that)
122122
importFrom(assertthat,is.flag)
123123
importFrom(assertthat,is.number)
124124
importFrom(assertthat,is.string)
125+
importFrom(assertthat,noNA)
125126
importFrom(glue,glue)
126127
importFrom(rlang,"%||%")
127128
importFrom(rlang,abort)

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
- More consistent and intuitive handling of JSON input / output user settings (#195, #196; see `?qgis_using_json_output`).
44
- Fix bug in support for environment variable `R_QGISPROCESS_DETECT_NEWER_QGIS` (#197).
5+
- QGIS or third-party providers can expose deprecated algorithms that may be removed from future versions.
6+
`{qgisprocess}` now handles these algorithms explicitly (#198):
7+
- `qgis_run_algorithm()` and other functions (such as `qgis_show_help()` and `qgis_get_description()`) will warn if a deprecated algorithm is passed (feature request #194; original issue #193).
8+
- `qgis_search_algorithms()` now **excludes** deprecated algorithms by default; they can still be included by setting the `include_deprecated` argument to `TRUE`.
9+
- `qgis_algorithms()` can _optionally_ restrict its results to non-deprecated algorithms (set the `include_deprecated` argument to `FALSE`). By default they are included, just as before.
510

611
# qgisprocess 0.2.0
712

R/qgis-algorithms.R

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#' for a detailed description of the algorithms provided
88
#' 'out of the box' on QGIS.
99
#'
10+
#' The `include_deprecated` argument in `qgis_algorithms()` does not affect the
11+
#' cached value. The latter always includes deprecated algorithms if these are
12+
#' returned by 'qgis_process' (this requires the JSON output method).
13+
#'
1014
#' @family topics about information on algorithms & processing providers
1115
#' @family topics about reporting the QGIS state
1216
#' @concept functions to manage and explore QGIS and qgisprocess
@@ -16,6 +20,7 @@
1620
#' status in QGIS (enabled or disabled).
1721
#' Must be one of: `"all"`, `"enabled"`, `"disabled"`.
1822
#' @param ... Only used by other functions calling this function.
23+
#' @param include_deprecated Logical. Should deprecated algorithms be included?
1924
#' @inheritParams qgis_path
2025
#'
2126
#' @returns
@@ -25,11 +30,18 @@
2530
#'
2631
#' @examplesIf has_qgis()
2732
#' qgis_algorithms()
33+
#' qgis_algorithms(include_deprecated = FALSE)
2834
#' qgis_providers()
2935
#' qgis_plugins(quiet = FALSE)
3036
#' qgis_plugins(which = "disabled")
3137
#'
32-
qgis_algorithms <- function(query = FALSE, quiet = TRUE) {
38+
qgis_algorithms <- function(
39+
query = FALSE,
40+
quiet = TRUE,
41+
include_deprecated = TRUE) {
42+
assert_that(is.flag(query), noNA(query))
43+
assert_that(is.flag(quiet), noNA(quiet))
44+
assert_that(is.flag(include_deprecated), noNA(include_deprecated))
3345
if (query) {
3446
qgisprocess_cache$algorithms <- qgis_query_algorithms(quiet = quiet)
3547
}
@@ -38,13 +50,25 @@ qgis_algorithms <- function(query = FALSE, quiet = TRUE) {
3850
"access to { nrow(qgisprocess_cache$algorithms) } algorithms ",
3951
"from { nrow(qgis_providers()) } QGIS processing providers."
4052
))
41-
qgisprocess_cache$algorithms
53+
algs <- qgisprocess_cache$algorithms
54+
if (!include_deprecated && "deprecated" %in% colnames(algs)) {
55+
algs[!algs$deprecated, ]
56+
} else {
57+
algs
58+
}
4259
}
4360

4461
#' @rdname qgis_algorithms
4562
#' @export
46-
qgis_providers <- function(query = FALSE, quiet = TRUE) {
47-
algs <- qgis_algorithms(query = query, quiet = quiet)
63+
qgis_providers <- function(
64+
query = FALSE,
65+
quiet = TRUE,
66+
include_deprecated = TRUE) {
67+
algs <- qgis_algorithms(
68+
query = query,
69+
quiet = quiet,
70+
include_deprecated = include_deprecated
71+
)
4872
counted <- stats::aggregate(
4973
algs[[1]],
5074
by = list(algs$provider, algs$provider_title),
@@ -70,10 +94,29 @@ assert_qgis_algorithm <- function(algorithm) {
7094
)
7195
}
7296

97+
check_algorithm_deprecation(algorithm)
98+
7399
invisible(algorithm)
74100
}
75101

76102

103+
#' @keywords internal
104+
check_algorithm_deprecation <- function(algorithm) {
105+
algs <- qgis_algorithms()
106+
if ("deprecated" %in% colnames(algs)) {
107+
deprecated_algs <- algs$algorithm[algs$deprecated]
108+
if (algorithm %in% deprecated_algs) {
109+
warning(
110+
glue(
111+
"Algorithm '{ algorithm }' is deprecated and may be removed in a later ",
112+
"QGIS version!\nCurrently using QGIS { qgis_version() }."
113+
),
114+
call. = FALSE
115+
)
116+
}
117+
}
118+
}
119+
77120

78121
#' @keywords internal
79122
qgis_query_algorithms <- function(quiet = FALSE) {
@@ -228,6 +271,7 @@ qgis_query_algorithms <- function(quiet = FALSE) {
228271
#' `provider_title` value from the output of [qgis_algorithms()].
229272
#' @param group Regular expression to match the `group` value
230273
#' from the output of [qgis_algorithms()].
274+
#' @inheritParams qgis_algorithms
231275
#'
232276
#' @returns A tibble.
233277
#'
@@ -241,12 +285,17 @@ qgis_query_algorithms <- function(quiet = FALSE) {
241285
qgis_search_algorithms <- function(
242286
algorithm = NULL,
243287
provider = NULL,
244-
group = NULL) {
288+
group = NULL,
289+
include_deprecated = FALSE) {
245290
assert_that(
246291
!is.null(algorithm) || !is.null(provider) || !is.null(group),
247292
msg = "You must provide at least one of the arguments."
248293
)
249-
result <- qgis_algorithms(query = FALSE, quiet = TRUE)
294+
result <- qgis_algorithms(
295+
query = FALSE,
296+
quiet = TRUE,
297+
include_deprecated = include_deprecated
298+
)
250299
assert_that(inherits(result, "data.frame"))
251300
assert_that(
252301
nrow(result) > 0L,

R/qgis-help.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ qgis_get_output_specs <- function(algorithm) {
9494
qgis_help_json <- function(algorithm) {
9595
cached <- help_cache_file(algorithm, json = TRUE)
9696
if (qgis_using_cached_help() && file.exists(cached)) {
97+
check_algorithm_deprecation(algorithm)
9798
try(return(jsonlite::fromJSON(readRDS(cached))))
9899
}
99100

@@ -116,6 +117,7 @@ qgis_help_json <- function(algorithm) {
116117
qgis_help_text <- function(algorithm) {
117118
cached <- help_cache_file(algorithm, json = FALSE)
118119
if (qgis_using_cached_help() && file.exists(cached)) {
120+
check_algorithm_deprecation(algorithm)
119121
try(return(readRDS(cached)))
120122
}
121123

R/qgisprocess-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#' @importFrom assertthat
1414
#' assert_that
1515
#' is.flag
16+
#' noNA
1617
#' is.string
1718
#' is.number
1819
## usethis namespace: end

man/qgis_algorithms.Rd

Lines changed: 10 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/qgis_search_algorithms.Rd

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-qgis-algorithms.R

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_that("qgis_algorithms() works", {
44
expect_true(tibble::is_tibble(algs))
55
expect_gt(nrow(algs), 200)
66
expect_gt(ncol(algs), 20)
7+
expect_gte(nrow(algs), nrow(qgis_algorithms(include_deprecated = FALSE)))
78
old_names <- c(
89
"provider", "provider_title", "algorithm",
910
"algorithm_id", "algorithm_title"
@@ -23,12 +24,28 @@ test_that("qgis_providers() works", {
2324
)
2425
})
2526

26-
test_that("assert_qgis_algorithm() works", {
27+
test_that("Internal function assert_qgis_algorithm() works", {
2728
skip_if_not(has_qgis())
2829
expect_error(assert_qgis_algorithm("notanalgorithm"))
2930
expect_identical(assert_qgis_algorithm("native:filedownloader"), "native:filedownloader")
3031
})
3132

33+
test_that("Internal function check_algorithm_deprecation() works", {
34+
skip_if_not(has_qgis())
35+
algs <- qgis_algorithms()
36+
skip_if_not(
37+
"deprecated" %in% colnames(algs) && sum(algs$deprecated) > 0,
38+
paste(
39+
"There are no deprecated algorithms available.",
40+
"Unless using no-JSON output, rewrite this test to simulate deprecated algorithms."
41+
)
42+
)
43+
alg_deprecated <- sample(algs$algorithm[algs$deprecated], 1)
44+
alg_non_deprecated <- sample(algs$algorithm[!algs$deprecated], 1)
45+
expect_warning(check_algorithm_deprecation(alg_deprecated))
46+
expect_no_warning(check_algorithm_deprecation(alg_non_deprecated))
47+
})
48+
3249
test_that("qgis_search_algorithms() works", {
3350
skip_if_not(has_qgis())
3451
expect_error(qgis_search_algorithms(), "at least one of the arguments")
@@ -46,4 +63,7 @@ test_that("qgis_search_algorithms() works", {
4663
expect_gt(nrow(res1), 0L)
4764
res2 <- qgis_search_algorithms(algorithm = "point.*line")
4865
expect_gt(nrow(res2), nrow(res1))
66+
res3 <- qgis_search_algorithms(algorithm = "raster")
67+
res4 <- qgis_search_algorithms(algorithm = "raster", include_deprecated = TRUE)
68+
expect_gte(nrow(res4), nrow(res3))
4969
})

0 commit comments

Comments
 (0)