From d42be2685a993826cd3261dc220a3b0e496197c6 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 9 Dec 2024 16:35:03 -0800 Subject: [PATCH] rename allcaps --- .env.sample | 4 ++-- docs/api/stream_daq.md | 2 +- docs/guide/config.md | 30 +++++++++++++++--------------- mio/models/config.py | 6 +++--- pdm.lock | 2 +- tests/fixtures.py | 4 ++-- tests/test_config.py | 14 +++++++------- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/.env.sample b/.env.sample index f3de5db..6d6fcbd 100644 --- a/.env.sample +++ b/.env.sample @@ -1,2 +1,2 @@ -MINISCOPE_IO_BASE_DIR="~/.config/mio" -MINISCOPE_IO_LOGS__LEVEL="INFO" \ No newline at end of file +MIO_BASE_DIR="~/.config/mio" +MIO_LOGS__LEVEL="INFO" \ No newline at end of file diff --git a/docs/api/stream_daq.md b/docs/api/stream_daq.md index 18003af..20d2eff 100644 --- a/docs/api/stream_daq.md +++ b/docs/api/stream_daq.md @@ -8,7 +8,7 @@ One example of this command is the following: ```bash $ mio stream capture -c .path/to/device/config.yml -o output_filename.avi -m ``` -A window displaying the image transferred from the Miniscope and a graph plotting metadata (`-m` option) should pop up. Additionally, the indexes of captured frames and their statuses will be logged in the terminal. The `MINISCOPE_IO_STREAM_HEADER_PLOT_KEY` defines plotted header fields (see `.env.sample`). +A window displaying the image transferred from the Miniscope and a graph plotting metadata (`-m` option) should pop up. Additionally, the indexes of captured frames and their statuses will be logged in the terminal. The `MIO_STREAM_HEADER_PLOT_KEY` defines plotted header fields (see `.env.sample`). ## Prerequisites - **Data capture hardware:** Opal Kelly XEM7310-A75 FPGA board (connected via USB) diff --git a/docs/guide/config.md b/docs/guide/config.md index 769f2d8..c927b36 100644 --- a/docs/guide/config.md +++ b/docs/guide/config.md @@ -24,7 +24,7 @@ Config values can be set (in order of priority from high to low, where higher priorities override lower priorities) * in the arguments passed to the class constructor (not user configurable) -* in environment variables like `export MINISCOPE_IO_LOG_DIR=~/` +* in environment variables like `export MIO_LOG_DIR=~/` * in a `.env` file in the working directory * in a `mio_config.yaml` file in the working directory * in the `tool.mio.config` table in a `pyproject.toml` file in the working directory @@ -82,13 +82,13 @@ For now, please edit the configuration files directly. #### Prefix Keys for environment variables (i.e. set in a shell with e.g. `export` or in a `.env` file) -are prefixed with `MINISCOPE_IO_` to not shadow other environment variables. -Keys in `toml` or `yaml` files are not prefixed with `MINISCOPE_IO_` . +are prefixed with `MIO_` to not shadow other environment variables. +Keys in `toml` or `yaml` files are not prefixed with `MIO_` . #### Nesting Keys for nested models are separated by a `__` double underscore in `.env` -files or environment variables (eg. `MINISCOPE_IO_LOGS__LEVEL`) +files or environment variables (eg. `MIO_LOGS__LEVEL`) Keys in `toml` or `yaml` files do not have a dunder separator because they can represent the nesting directly (see examples below) @@ -99,7 +99,7 @@ When setting values from the cli, keys for nested models are separated with a `. Keys are case-insensitive, i.e. these are equivalent:: - export MINISCOPE_IO_LOGS__LEVEL=INFO + export MIO_LOGS__LEVEL=INFO export mio_logs__level=INFO ### Examples @@ -117,20 +117,20 @@ logs: ```` ````{tab-item} env vars ```{code-block} bash -export MINISCOPE_IO_USER_DIR='~/.config/mio' -export MINISCOPE_IO_LOG_DIR='~/config/mio/logs' -export MINISCOPE_IO_LOGS__LEVEL_FILE='INFO' -export MINISCOPE_IO_LOGS__LEVEL_STREAM='WARNING' -export MINISCOPE_IO_LOGS__FILE_N=5 +export MIO_USER_DIR='~/.config/mio' +export MIO_LOG_DIR='~/config/mio/logs' +export MIO_LOGS__LEVEL_FILE='INFO' +export MIO_LOGS__LEVEL_STREAM='WARNING' +export MIO_LOGS__FILE_N=5 ``` ```` ````{tab-item} .env file ```{code-block} python -MINISCOPE_IO_USER_DIR='~/.config/mio' -MINISCOPE_IO_LOG_DIR='~/config/mio/logs' -MINISCOPE_IO_LOG__LEVEL_FILE='INFO' -MINISCOPE_IO_LOG__LEVEL_STREAM='WARNING' -MINISCOPE_IO_LOG__FILE_N=5 +MIO_USER_DIR='~/.config/mio' +MIO_LOG_DIR='~/config/mio/logs' +MIO_LOG__LEVEL_FILE='INFO' +MIO_LOG__LEVEL_STREAM='WARNING' +MIO_LOG__FILE_N=5 ``` ```` ````{tab-item} pyproject.toml diff --git a/mio/models/config.py b/mio/models/config.py index e00d87d..3884dc8 100644 --- a/mio/models/config.py +++ b/mio/models/config.py @@ -69,8 +69,8 @@ class Config(BaseSettings, YAMLMixin): See https://docs.pydantic.dev/latest/concepts/pydantic_settings/ Set values either in an ``.env`` file or using environment variables - prefixed with ``MINISCOPE_IO_*``. Values in nested models are separated with ``__`` , - eg. ``MINISCOPE_IO_LOGS__LEVEL`` + prefixed with ``MIO_*``. Values in nested models are separated with ``__`` , + eg. ``MIO_LOGS__LEVEL`` See ``.env.example`` in repository root @@ -133,7 +133,7 @@ def settings_customise_sources( Read config settings from, in order of priority from high to low, where high priorities override lower priorities: * in the arguments passed to the class constructor (not user configurable) - * in environment variables like ``export MINISCOPE_IO_LOG_DIR=~/`` + * in environment variables like ``export MIO_LOG_DIR=~/`` * in a ``.env`` file in the working directory * in a ``mio_config.yaml`` file in the working directory * in the ``tool.mio.config`` table in a ``pyproject.toml`` file diff --git a/pdm.lock b/pdm.lock index de8b00f..010af76 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "all", "dev", "docs", "plot", "tests"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:cde2e6f75c9429dc0ca35f0c2cf766718ae038c3572e8e4a97ae528235287e8a" +content_hash = "sha256:45c1d1f2b3d9add57b72934ccc1ee0e8798c25bd2e094d76b91f9bc2fb61f3e1" [[metadata.targets]] requires_python = "~=3.9" diff --git a/tests/fixtures.py b/tests/fixtures.py index 0e9cf4d..1ae7ef5 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -158,7 +158,7 @@ def set_env(monkeypatch) -> Callable[[dict[str, Any]], None]: def _set_env(config: dict[str, Any]) -> None: for key, value in _flatten(config).items(): - key = "MINISCOPE_IO_" + key.upper() + key = "MIO_" + key.upper() monkeypatch.setenv(key, str(value)) return _set_env @@ -174,7 +174,7 @@ def set_dotenv(tmp_cwd) -> Callable[[dict[str, Any]], Path]: def _set_dotenv(config: dict[str, Any]) -> Path: with open(dotenv_path, "w") as dfile: for key, value in _flatten(config).items(): - key = "MINISCOPE_IO_" + key.upper() + key = "MIO_" + key.upper() dfile.write(f"{key}={value}\n") return dotenv_path diff --git a/tests/test_config.py b/tests/test_config.py index 572030d..585abe8 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -43,20 +43,20 @@ def test_config_from_environment(tmp_path): """ Setting environmental variables should set the config, including recursive models """ - os.environ["MINISCOPE_IO_USER_DIR"] = str(tmp_path) + os.environ["MIO_USER_DIR"] = str(tmp_path) # we can also override the default log dir name override_logdir = Path(tmp_path) / "fancylogdir" - os.environ["MINISCOPE_IO_LOG_DIR"] = str(override_logdir) + os.environ["MIO_LOG_DIR"] = str(override_logdir) # and also recursive models - os.environ["MINISCOPE_IO_LOGS__LEVEL"] = "error" + os.environ["MIO_LOGS__LEVEL"] = "error" config = Config() assert config.user_dir == Path(tmp_path) assert config.log_dir == override_logdir assert config.logs.level == "error".upper() - del os.environ["MINISCOPE_IO_USER_DIR"] - del os.environ["MINISCOPE_IO_LOG_DIR"] - del os.environ["MINISCOPE_IO_LOGS__LEVEL"] + del os.environ["MIO_USER_DIR"] + del os.environ["MIO_LOG_DIR"] + del os.environ["MIO_LOGS__LEVEL"] def test_config_from_dotenv(tmp_path): @@ -68,7 +68,7 @@ def test_config_from_dotenv(tmp_path): tmp_path.mkdir(exist_ok=True, parents=True) dotenv = tmp_path / ".env" with open(dotenv, "w") as denvfile: - denvfile.write(f"MINISCOPE_IO_USER_DIR={str(tmp_path)}") + denvfile.write(f"MIO_USER_DIR={str(tmp_path)}") config = Config(_env_file=dotenv, _env_file_encoding="utf-8") assert config.user_dir == Path(tmp_path)