-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Description of the requested feature
This relates to the use_json_input and use_json_output user settings through options and environment variables (see ?qgis_using_json_input
). And about controlling how input to and output from qgis_process
are interfaced: either using JSON or using the legacy (no-JSON) method.
Current behaviour
Currently we have this behaviour:
- with no options set, will favour JSON input and JSON output whenever possible. Essential indeed.
- do I use JSON output? (= outcome of
qgis_using_json_output()
) Withquery = TRUE
(as implemented byqgis_configure()
) takes on the use_json_output user setting if present (if absent try to use JSON output); withquery = FALSE
(default) returns the cacheduse_json_output
value – the use_json_output user setting is neglected. The cacheduse_json_output
value is only updated whenqgis_configure()
is run (i.e. reconfigure the package). - do I use JSON input? (= outcome of
qgis_using_json_input()
) This is determined by minimum required QGIS version (3.23.0) and JSON output, but if the json_input user setting is set, that setting is taken for granted. qgis_using_json_output()
and the cacheduse_json_output
value are ignored byqgis_run_algorithm()
whenqgis_using_json_input()
isTRUE
, makingqgis_run_algorithm()
behave in harmony withqgis_process
. But this leaves us with inconsistency wrt the return value ofqgis_using_json_output()
and the cacheduse_json_output
value: these can beFALSE
even whileqgis_run_algorithm()
is implementingTRUE
when the json_input user setting isTRUE
.qgis_using_json_input()
always queries the user settings, whileqgis_using_json_output()
doesn't unless it gets the argumentquery = TRUE
.- while the use_json_input user setting has immediate effect, both before or after loading the package, the use_json_output user setting does not affect the cached
use_json_output
value, also not when set before loading the package. Only actively callingqgis_configure()
will do that, since the latter usesqgis_using_json_output(query = TRUE)
.
Note that caching use_json_output
makes sense since using JSON output (i.e. calling qgis_process
with --json
) determines the form and richness of data returned from qgis_algorithms()
, which is cached too. Also the value of qgis_plugins()
may be different, notably the row order.
Future behaviour?
I believe the following changes or additions will make behaviour more consistent and intuitive:
- consistently make sure, regardless of the user settings and cached
use_json_output
value, thatqgis_using_json_output()
cannot returnFALSE
whenqgis_using_json_input()
returnsTRUE
. Given that these functions can take into account user settings, this also means not accepting the corresponding conflicting user setting (or cache value) combination.- if
qgis_using_json_input()
returnsTRUE
, thenqgis_using_json_output()
must beTRUE
. Equivalent to: ifqgis_using_json_output()
returnsFALSE
, thenqgis_using_json_input()
must beFALSE
.
- if
- if the json_input user setting is
TRUE
, it should be verified that this request can be granted by the backend. - if the json_input user setting is
TRUE
and if it can be granted, it should determine the outcome ofqgis_using_json_input()
,qgis_using_json_output()
and the cacheduse_json_output
value: they should all becomeTRUE
. - just like
qgis_using_json_input()
instantly queries (and validates) the use_json_input setting and immediately affects package behaviour,qgis_using_json_output()
should instantly query and validate the use_json_output setting (validation also taking into account the use_json_input setting), update the cacheduse_json_output
value to its outcome and immediately affect package behaviour; noqgis_configure()
needed. Only when the use_json_output setting is missing andquery = FALSE
, return the cached value instead. qgis_configure()
is still needed to persistently store the cacheduse_json_output
value and make sure it is aligned with the return value ofqgis_algorithms()
.- take into account the presence of JSON input/output user settings when validating the cache file during package loading, and reconfigure the package (i.e. including the cache file) if the outcome of those user settings conflicts with the cached
use_json_output
value. In other words, include this in the checks run byqgis_configure(use_cached_data = TRUE)
.
I think I have implemented all of this in the json
branch. Unit tests are still to be added; so for now still to be regarded as experimental (at least R CMD check
is still OK on my machine). Changes should not affect typical use of the package, but only make the experience more intuitive when one wants to fiddle with JSON input/output.
Feel free to check yourself or discuss.
Additional context
Some of these ideas grew out of exploring #185.