Skip to content

Commit

Permalink
paquo: fix double under env var confusion
Browse files Browse the repository at this point in the history
Fix envvar override in a backwards compatible way.
Close #73.
  • Loading branch information
ap-- committed Jul 15, 2022
1 parent d67abbd commit 0c52260
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ paquo to use that version.
# available at: /some/path/on/your/machine/QuPath-0.3.2
#
# use via environment variable:
# $ export PAQUO__QUPATH_DIR=/some/path/on/your/machine/QuPath-0.3.2
# $ export PAQUO_QUPATH_DIR=/some/path/on/your/machine/QuPath-0.3.2
#
# use via .paquo.toml config file:
# qupath_dir="/some/path/on/your/machine/QuPath-0.3.2"
Expand Down
20 changes: 10 additions & 10 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ Environment variables
---------------------

All `paquo` settings can also be overridden by environment variables. Just prefix the particular
setting with :code:`PAQUO__` (double underscore!) and set the environment variable to what you
setting with :code:`PAQUO_` (single underscore!) and set the environment variable to what you
want it to be.

PAQUO__QUPATH_DIR = :code:`""`
PAQUO_QUPATH_DIR = :code:`""`
if set will skip search and try to use qupath from this folder

PAQUO__QUPATH_SEARCH_DIRS
PAQUO_QUPATH_SEARCH_DIRS
defaults to all default installation locations for QuPath this can be set to the folders that will be
searched for QuPath installations.

PAQUO__QUPATH_SEARCH_DIR_REGEX = :code:`"(?i)qupath.*"`
PAQUO_QUPATH_SEARCH_DIR_REGEX = :code:`"(?i)qupath.*"`
used to regex match qupath_dirs during search

PAQUO__QUPATH_SEARCH_CONDA = :code:`true`
PAQUO_QUPATH_SEARCH_CONDA = :code:`true`
should the conda installed QuPath be considered?

PAQUO__QUPATH_PREFER_CONDA = :code:`true`
PAQUO_QUPATH_PREFER_CONDA = :code:`true`
should the conda installed QuPath be preferred over another locally installed QuPath

PAQUO__JAVA_OPTS = :code:`["-XX:MaxRAMPercentage=50",]`
PAQUO_JAVA_OPTS = :code:`["-XX:MaxRAMPercentage=50",]`
a list of JVM options passed to the java virtual machine

PAQUO__MOCK_BACKEND = :code:`false`
PAQUO_MOCK_BACKEND = :code:`false`
an internal setting which allows building the docs without having qupath installed

PAQUO__CLI_FORCE_LOG_LEVEL_ERROR = :code:`true`
PAQUO_CLI_FORCE_LOG_LEVEL_ERROR = :code:`true`
only show paquo errors on cli

PAQUO__WARN_MICROSOFT_STORE_PYTHON = :code:`true`
PAQUO_WARN_MICROSOFT_STORE_PYTHON = :code:`true`
windows only, warn if paquo is run via a microsoft store python


Expand Down
6 changes: 3 additions & 3 deletions paquo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ def _download_cb(it, name):

print("#\n# use via environment variable:")
if system in {"Linux", "Darwin"}:
print(f"# $ export PAQUO__QUPATH_DIR={app}")
print(f"# $ export PAQUO_QUPATH_DIR={app}")
else:
print("# REM Windows CMD")
print(f'# C:\\> set PAQUO__QUPATH_DIR="{app}"')
print(f'# C:\\> set PAQUO_QUPATH_DIR="{app}"')
print("# # Windows PowerShell")
print(f'# PS C:\\> $env:PAQUO__QUPATH_DIR="{app}"')
print(f'# PS C:\\> $env:PAQUO_QUPATH_DIR="{app}"')
print("#\n# use via .paquo.toml config file:")
print(f'# qupath_dir="{app}"')
print(app)
Expand Down
23 changes: 22 additions & 1 deletion paquo/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,31 @@

PAQUO_CONFIG_FILENAME = '.paquo.toml'

_PAQUO_FIX_CONFIG_KEYS = {
# recover prefixed keys due to dynaconf weirdness
"_qupath_dir",
"_qupath_search_dirs",
"_qupath_search_dir_regex",
"_qupath_search_conda",
"_qupath_prefer_conda",
"_java_opts",
"_safe_truncate",
"_mock_backend",
"_cli_force_log_level_error",
"_warn_microsoft_store_python",
}


def to_kwargs(s: "Settings | DynaBox") -> Dict[str, Any]:
"""convert dynaconf settings to lowercase"""
return {k.lower(): v for k, v in s.to_dict().items()}
dct = s.to_dict()
out = {}
for key, value in dct.items():
k = key.lower()
if k in _PAQUO_FIX_CONFIG_KEYS:
k = k[1:]
out[k] = value
return out


def to_toml(s: Settings) -> str:
Expand Down

0 comments on commit 0c52260

Please sign in to comment.