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 ...@@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### ### Changed ###
* Using environment variable PYLINKAHEADINI instead of PYCAOSDBINI.
### Deprecated ### ### Deprecated ###
### Removed ### ### Removed ###
......
# To be found be the caosdb package, the INI file must be located either in # To be found be the caosdb package, the INI file must be located either in
# - $CWD/pylinkahead.ini # - $CWD/pylinkahead.ini
# - $HOME/.pylinkahead.ini # - $HOME/.pylinkahead.ini
# - the location given in the env variable PYCAOSDBINI # - the location given in the env variable PYLINKAHEADINI
[Connection] [Connection]
# URL of the CaosDB server # URL of the CaosDB server
......
# Configuration of PyLinkAhead # # Configuration of PyLinkAhead #
The behavior of PyLinkAhead is defined via a configuration that is provided using configuration files. 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 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. current working directory will be read additionally, if it exists.
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
"""LinkAhead Python bindings. """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 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. 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]]]): ...@@ -102,7 +102,7 @@ def validate_yaml_schema(valobj: dict[str, dict[str, Union[int, str, bool]]]):
def _read_config_files() -> list[str]: def _read_config_files() -> list[str]:
"""Read config files from different paths. """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 additionally adds config from a config file in the current working directory
(``pylinkahead.ini``). (``pylinkahead.ini``).
If deprecated names are used (starting with 'pycaosdb'), those used in addition but the files 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]: ...@@ -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). " 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"Please use the new version and rename\n"
f" {ini_cwd_caosdb}\nto\n {ini_cwd}", DeprecationWarning) 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 ################################################## # End: LinkAhead rename block ##################################################
if "PYCAOSDBINI" in environ: if "PYLINKAHEADINI" in environ:
if not isfile(expanduser(environ["PYCAOSDBINI"])): if not isfile(expanduser(environ["PYLINKAHEADINI"])):
raise RuntimeError( raise RuntimeError(
f"No configuration file found at\n{expanduser(environ['PYCAOSDBINI'])}" f"No configuration file found at\n{expanduser(environ['PYLINKAHEADINI'])}"
"\nwhich was given via the environment variable PYCAOSDBINI" "\nwhich was given via the environment variable PYLINKAHEADINI"
) )
return_var.extend(configure(expanduser(environ["PYCAOSDBINI"]))) return_var.extend(configure(expanduser(environ["PYLINKAHEADINI"])))
else: else:
if isfile(ini_user_caosdb): if isfile(ini_user_caosdb):
return_var.extend(configure(ini_user_caosdb)) return_var.extend(configure(ini_user_caosdb))
......
...@@ -45,24 +45,24 @@ def temp_ini_files(): ...@@ -45,24 +45,24 @@ def temp_ini_files():
remove("pylinkahead.ini") remove("pylinkahead.ini")
if created_temp_ini_home: if created_temp_ini_home:
remove(expanduser("~/.pylinkahead.ini")) remove(expanduser("~/.pylinkahead.ini"))
environ["PYCAOSDBINI"] = "~/.pylinkahead.ini" environ["PYLINKAHEADINI"] = "~/.pylinkahead.ini"
def test_config_ini_via_envvar(temp_ini_files): def test_config_ini_via_envvar(temp_ini_files):
with raises(KeyError): with raises(KeyError):
environ["PYCAOSDBINI"] environ["PYLINKAHEADINI"]
environ["PYCAOSDBINI"] = "bla bla" environ["PYLINKAHEADINI"] = "bla bla"
assert environ["PYCAOSDBINI"] == "bla bla" assert environ["PYLINKAHEADINI"] == "bla bla"
# test wrong configuration file in envvar # test wrong configuration file in envvar
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
db.configuration._read_config_files() db.configuration._read_config_files()
# test good configuration file in envvar # test good configuration file in envvar
environ["PYCAOSDBINI"] = "~/.pylinkahead.ini" environ["PYLINKAHEADINI"] = "~/.pylinkahead.ini"
assert expanduser("~/.pylinkahead.ini") in db.configuration._read_config_files() assert expanduser("~/.pylinkahead.ini") in db.configuration._read_config_files()
# test without envvar # test without envvar
environ.pop("PYCAOSDBINI") environ.pop("PYLINKAHEADINI")
assert expanduser("~/.pylinkahead.ini") in db.configuration._read_config_files() assert expanduser("~/.pylinkahead.ini") in db.configuration._read_config_files()
# test configuration file in cwd # test configuration file in cwd
assert join(getcwd(), "pylinkahead.ini") in db.configuration._read_config_files() 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.
Please register or to comment