Skip to content
Snippets Groups Projects
Verified Commit 2094493e authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: PYLINKAHEADINI instead of PYCAOSDBINI

parent 47f3223d
No related branches found
No related tags found
1 merge request!143Release 0.15.0
Pipeline #52491 passed with warnings
......@@ -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 ###
......
# 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
......
# 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.
......
......@@ -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.
......
......@@ -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))
......
......@@ -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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment