diff --git a/.gitignore b/.gitignore index da4184b..33a54e3 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ Thumbs.db # uv uv.lock +.python-version # docs site/ diff --git a/mise.toml b/mise.toml index d61f977..a0623e7 100644 --- a/mise.toml +++ b/mise.toml @@ -1,4 +1,5 @@ [tools] +prek = "latest" uv = "latest" [tasks.check] diff --git a/pyproject.toml b/pyproject.toml index 7672fd4..5620afa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -100,5 +100,5 @@ convention = "google" [tool.uv] constraint-dependencies = [ - "click<8.2", # https://github.com/fastapi/typer/discussions/1215 + "click>=8.2", # typer>=0.16 uses click.Choice as a generic (PEP 585), which requires click>=8.2 ] diff --git a/src/submit_aml/config.py b/src/submit_aml/config.py index 71b1d31..bc8a336 100644 --- a/src/submit_aml/config.py +++ b/src/submit_aml/config.py @@ -20,7 +20,7 @@ if sys.version_info >= (3, 11): import tomllib else: - import tomli as tomllib # type: ignore[unresolved-import] + import tomli as tomllib # ty: ignore[unresolved-import] from .defaults import DEFAULT_COMMAND_PREFIX from .defaults import DEFAULT_COMPUTE_TARGET @@ -32,11 +32,27 @@ from .defaults import DEFAULT_TENSORBOARD_DIR from .logger import logger -CONFIG_PATH: Path = Path("~/.config/submit-aml/config.toml").expanduser() -"""Default location for the user-level TOML config file.""" - _ENV_PREFIX: str = "SUBMIT_AML_" +_CONFIG_PATH_ENV_VAR: str = f"{_ENV_PREFIX}CONFIG" +"""Environment variable that overrides the TOML config file location.""" + + +def _resolve_config_path() -> Path: + """Resolve the TOML config path, honoring the override env var.""" + override = os.environ.get(_CONFIG_PATH_ENV_VAR) + if override: + return Path(override).expanduser() + return Path("~/.config/submit-aml/config.toml").expanduser() + + +CONFIG_PATH: Path = _resolve_config_path() +"""Default location for the user-level TOML config file. + +Set the ``SUBMIT_AML_CONFIG`` environment variable to point at a different +file (or at a non-existent path to skip TOML config entirely). +""" + # --------------------------------------------------------------------------- # Registry: flat key → (TOML (section, key), package default) # --------------------------------------------------------------------------- diff --git a/tests/conftest.py b/tests/conftest.py index ffa5e0c..53cf8d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,10 +2,22 @@ from __future__ import annotations +import os from pathlib import Path import pytest +# Point the CLI at a guaranteed non-existent config file BEFORE ``submit_aml`` +# is imported anywhere in the test session, so that Typer option defaults +# (evaluated at import time) do not pick up the developer's real +# ``~/.config/submit-aml/config.toml``. Likewise drop any ``SUBMIT_AML_*`` +# variables that may leak from the host shell. +os.environ["SUBMIT_AML_CONFIG"] = "/nonexistent/submit-aml/config.toml" +for _var in [ + k for k in os.environ if k.startswith("SUBMIT_AML_") and k != "SUBMIT_AML_CONFIG" +]: + del os.environ[_var] + @pytest.fixture def toml_config_file(tmp_path: Path) -> Path: