Skip to content

Commit

Permalink
rename allcaps
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Dec 10, 2024
1 parent fa21f1b commit d42be26
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MINISCOPE_IO_BASE_DIR="~/.config/mio"
MINISCOPE_IO_LOGS__LEVEL="INFO"
MIO_BASE_DIR="~/.config/mio"
MIO_LOGS__LEVEL="INFO"
2 changes: 1 addition & 1 deletion docs/api/stream_daq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 15 additions & 15 deletions docs/guide/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions mio/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit d42be26

Please sign in to comment.