diff --git a/CHANGELOG.md b/CHANGELOG.md index e01686cd6eaa87990cdda9a9ae7f83557d532d5b..7a97a2b7bd39d78f7176607dc59f59c6824a35cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### +* Using environment variable PYLINKAHEADINI instead of PYCAOSDBINI. + ### Deprecated ### ### Removed ### diff --git a/examples/pylinkahead.ini b/examples/pylinkahead.ini index f37e24e0e5b754ec58a07b034ba2755096f0b441..84d1eb8526201c817d6614e7eb74f35a932c5d78 100644 --- a/examples/pylinkahead.ini +++ b/examples/pylinkahead.ini @@ -1,7 +1,7 @@ # To be found be the caosdb package, the INI file must be located either in # - $CWD/pylinkahead.ini # - $HOME/.pylinkahead.ini -# - the location given in the env variable PYCAOSDBINI +# - the location given in the env variable PYLINKAHEADINI [Connection] # URL of the CaosDB server diff --git a/src/doc/configuration.md b/src/doc/configuration.md index 54ae251b9db9ef000545e701406b979aa58043f8..427551db4e1e97d7ca5f9820df6d5916e3496020 100644 --- a/src/doc/configuration.md +++ b/src/doc/configuration.md @@ -1,6 +1,6 @@ # Configuration of PyLinkAhead # The behavior of PyLinkAhead is defined via a configuration that is provided using configuration files. -PyLinkAhead tries to read from the inifile specified in the environment variable `PYCAOSDBINI` or +PyLinkAhead tries to read from the inifile specified in the environment variable `PYLINKAHEADINI` or alternatively in `~/.pylinkahead.ini` upon import. After that, the ini file `pylinkahead.ini` in the current working directory will be read additionally, if it exists. diff --git a/src/linkahead/__init__.py b/src/linkahead/__init__.py index 3a8c5ba39c88deaa5dc945135e3828945fd39d58..cd54f8f4e05326579521fbbf226f027d32fa616e 100644 --- a/src/linkahead/__init__.py +++ b/src/linkahead/__init__.py @@ -24,7 +24,7 @@ """LinkAhead Python bindings. -Tries to read from the inifile specified in the environment variable `PYCAOSDBINI` or +Tries to read from the inifile specified in the environment variable `PYLINKAHEADINI` or alternatively in `~/.pylinkahead.ini` upon import. After that, the ini file `pylinkahead.ini` in the current working directory will be read additionally, if it exists. diff --git a/src/linkahead/configuration.py b/src/linkahead/configuration.py index b020467c8c53e26d464a6a2fb473cc912b0e0612..f3f50ae3c39e029229d02231605e2bf57f3201ee 100644 --- a/src/linkahead/configuration.py +++ b/src/linkahead/configuration.py @@ -102,7 +102,7 @@ def validate_yaml_schema(valobj: dict[str, dict[str, Union[int, str, bool]]]): def _read_config_files() -> list[str]: """Read config files from different paths. - Read the config from either ``$PYCAOSDBINI`` or home directory (``~/.pylinkahead.ini``), and + Read the config from either ``$PYLINKAHEADINI`` or home directory (``~/.pylinkahead.ini``), and additionally adds config from a config file in the current working directory (``pylinkahead.ini``). If deprecated names are used (starting with 'pycaosdb'), those used in addition but the files @@ -131,15 +131,18 @@ def _read_config_files() -> list[str]: warnings.warn("\n\nYou have a config file with the old naming scheme (pycaosdb.ini). " f"Please use the new version and rename\n" f" {ini_cwd_caosdb}\nto\n {ini_cwd}", DeprecationWarning) + if "PYCAOSDBINI" in environ: + warnings.warn("\n\nYou have an environment variable PYCAOSDBINI. " + f"Please rename it to PYLINKAHEADINI.", DeprecationWarning) # End: LinkAhead rename block ################################################## - if "PYCAOSDBINI" in environ: - if not isfile(expanduser(environ["PYCAOSDBINI"])): + if "PYLINKAHEADINI" in environ: + if not isfile(expanduser(environ["PYLINKAHEADINI"])): raise RuntimeError( - f"No configuration file found at\n{expanduser(environ['PYCAOSDBINI'])}" - "\nwhich was given via the environment variable PYCAOSDBINI" + f"No configuration file found at\n{expanduser(environ['PYLINKAHEADINI'])}" + "\nwhich was given via the environment variable PYLINKAHEADINI" ) - return_var.extend(configure(expanduser(environ["PYCAOSDBINI"]))) + return_var.extend(configure(expanduser(environ["PYLINKAHEADINI"]))) else: if isfile(ini_user_caosdb): return_var.extend(configure(ini_user_caosdb)) diff --git a/unittests/test_configuration.py b/unittests/test_configuration.py index 40506e878b18473587da8b694d9381c15bdbd860..95bc906c6c044c51548aa864326cc93f29a6042a 100644 --- a/unittests/test_configuration.py +++ b/unittests/test_configuration.py @@ -45,24 +45,24 @@ def temp_ini_files(): remove("pylinkahead.ini") if created_temp_ini_home: remove(expanduser("~/.pylinkahead.ini")) - environ["PYCAOSDBINI"] = "~/.pylinkahead.ini" + environ["PYLINKAHEADINI"] = "~/.pylinkahead.ini" def test_config_ini_via_envvar(temp_ini_files): with raises(KeyError): - environ["PYCAOSDBINI"] + environ["PYLINKAHEADINI"] - environ["PYCAOSDBINI"] = "bla bla" - assert environ["PYCAOSDBINI"] == "bla bla" + environ["PYLINKAHEADINI"] = "bla bla" + assert environ["PYLINKAHEADINI"] == "bla bla" # test wrong configuration file in envvar with pytest.raises(RuntimeError): db.configuration._read_config_files() # test good configuration file in envvar - environ["PYCAOSDBINI"] = "~/.pylinkahead.ini" + environ["PYLINKAHEADINI"] = "~/.pylinkahead.ini" assert expanduser("~/.pylinkahead.ini") in db.configuration._read_config_files() # test without envvar - environ.pop("PYCAOSDBINI") + environ.pop("PYLINKAHEADINI") assert expanduser("~/.pylinkahead.ini") in db.configuration._read_config_files() # test configuration file in cwd assert join(getcwd(), "pylinkahead.ini") in db.configuration._read_config_files()