Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Thumbs.db

# uv
uv.lock
.python-version

# docs
site/
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tools]
prek = "latest"
uv = "latest"

[tasks.check]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
24 changes: 20 additions & 4 deletions src/submit_aml/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
# ---------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading