From e37796b577499e44380c313ee36d9aa4a7a19dbd Mon Sep 17 00:00:00 2001 From: Alexander Berger Date: Fri, 21 Aug 2026 13:05:54 -0400 Subject: [PATCH] Fix missing click dependency in container image; release 0.2.8 The v0.2.7 image aborted every `mouse-tracking` invocation with `ModuleNotFoundError: No module named 'click'`, because: 1. `cli/infer.py` imports `click` and uses `click.Choice` in 18 places, but `click` was never declared in `[project.dependencies]` -- it was only satisfied transitively through typer. 2. Typer 0.26.0 (2026-05-26) dropped `click` from its runtime requirements and vendored it as `typer._click`. 3. The Dockerfile installed dependencies twice: `uv sync --frozen` into `.venv`, then `uv pip install --system .`. `uv pip install` does not read uv.lock, so the packages that actually executed at runtime came from an unlocked re-resolution against PyPI -- which picked up typer >= 0.26 and therefore no `click`. Only (3) changed between v0.2.6 and v0.2.7; v0.2.6 pointed at the v0.2.5 image, which had been built before typer 0.26.0 was published. Changes: - Declare `click>=8.1.7,<8.3` and bound `typer>=0.12.4,<0.26`. The typer upper bound is required: with typer >= 0.26 the vendored parser does not recognise an external `click.Choice`, so the option silently renders a `` metavar instead of its values. Migrating the 18 call sites to `Enum`/`Literal` is a separate work item. - Install from the locked resolution in the Dockerfile: `uv export --frozen` to a requirements file, then `uv pip install --system --no-deps .` so the project install cannot re-resolve. - Add `RUN mouse-tracking --help` as a build-time smoke test so import-time regressions fail the image build, not a production batch. - Pin the uv image to 0.8.17 instead of :latest. - Add tests/cli/test_click_choice_options.py, which fails on both the missing-import and the `` metavar failure modes. - Bump version to 0.2.8 in pyproject.toml, nextflow.config manifest, and params.image_version. Co-Authored-By: Claude Opus 5 (1M context) --- Dockerfile | 22 +++++--- nextflow.config | 4 +- pyproject.toml | 5 +- tests/cli/test_click_choice_options.py | 75 ++++++++++++++++++++++++++ uv.lock | 18 ++++--- 5 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 tests/cli/test_click_choice_options.py diff --git a/Dockerfile b/Dockerfile index a401f9c..2033557 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM aberger4/mouse-tracking-base:python3.10-slim -# Install uv -COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv +# Install uv. Pinned rather than :latest so the resolver that reads uv.lock is +# the same one that wrote it. +COPY --from=ghcr.io/astral-sh/uv:0.8.17 /uv /usr/local/bin/uv ENV UV_SYSTEM_PYTHON=1 \ UV_PYTHON=/usr/local/bin/python \ @@ -10,14 +11,23 @@ ENV UV_SYSTEM_PYTHON=1 \ # Copy metadata first for layer caching COPY pyproject.toml uv.lock* README.md support_code ./ -# Only install runtime dependencies -RUN uv sync --frozen --no-group dev --no-group test --no-group lint --no-install-project +# Install runtime dependencies from the lock file into the system interpreter. +# `uv pip install` does not read uv.lock, so export the locked resolution first; +# otherwise the dependencies that actually execute at runtime are an unlocked +# re-resolution against PyPI. +RUN uv export --frozen --no-group dev --no-group test --no-group lint \ + --no-emit-project -o /tmp/requirements.txt \ + && uv pip install --system -r /tmp/requirements.txt -# Now add source and install the project itself +# Now add source and install the project itself. `--no-deps` keeps the locked +# dependency set above from being re-resolved. COPY src ./src -RUN uv pip install --system . +RUN uv pip install --system --no-deps . COPY support_code ./support_code +# Fail the build (rather than a production batch) on import-time regressions. +RUN mouse-tracking --help + CMD ["mouse-tracking-runtime", "--help"] diff --git a/nextflow.config b/nextflow.config index ade8f3c..6d645dc 100644 --- a/nextflow.config +++ b/nextflow.config @@ -6,7 +6,7 @@ manifest { mainScript = "main.nf" defaultBranch = 'main' nextflowVersion = "!>=22.04.3" - version = "0.2.7" + version = "0.2.8" contributors = [ [name: 'Brian Geuther'], [name: 'Alexander Berger-Liedtka'] @@ -35,7 +35,7 @@ params { path_depth = 2 /* Image Versions */ - image_version = '0.2.7' + image_version = '0.2.8' jabs_postprocess_version = '0.5.4' jabs_behavior_version = '0.36.1' diff --git a/pyproject.toml b/pyproject.toml index 5b1d304..62d41f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "mouse-tracking" -version = "0.2.7" +version = "0.2.8" description = "Runtime environment for mouse tracking experiments" requires-python = ">=3.10,<3.11" packages = ["src/mouse_tracking"] @@ -12,7 +12,8 @@ dependencies = [ "imageio[ffmpeg]==2.31.6", "pillow==9.4.0", "matplotlib==3.7.1", - "typer>=0.12.4", + "typer>=0.12.4,<0.26", + "click>=8.1.7,<8.3", "absl-py==1.4.0", "pydantic==2.7.4", "networkx==3.3", diff --git a/tests/cli/test_click_choice_options.py b/tests/cli/test_click_choice_options.py new file mode 100644 index 0000000..589ef7d --- /dev/null +++ b/tests/cli/test_click_choice_options.py @@ -0,0 +1,75 @@ +"""Regression tests for the ``click`` dependency used by the CLI options. + +``mouse_tracking.cli.infer`` builds enumerated options with +``typer.Option(click_type=click.Choice([...]))``. That idiom depends on the +top-level ``click`` distribution being installed *and* on typer consuming the +same ``click`` rather than a vendored copy. Typer 0.26 dropped ``click`` from +its runtime requirements and vendored it as ``typer._click``, which breaks the +idiom in two distinct ways: + +* ``click`` disappears entirely, so importing the module raises + ``ModuleNotFoundError`` and every CLI invocation aborts before parsing. +* ``click`` is installed alongside typer >= 0.26, so the import succeeds but the + vendored parser no longer recognises the external ``Choice`` instance and the + option renders a ```` metavar instead of the enumerated values. + +These tests fail loudly for both, so the version constraints in +``pyproject.toml`` cannot be relaxed without the call sites being migrated. +""" + +import click +import typer +from typer.testing import CliRunner + +from mouse_tracking.cli.main import app + + +def _choice_options(): + """Yield ``(command_path, option_name, choices)`` for every Choice option.""" + root = typer.main.get_command(app) + + def walk(command, path): + subcommands = getattr(command, "commands", None) + if subcommands: + for name, sub in subcommands.items(): + yield from walk(sub, [*path, name]) + return + for param in command.params: + if isinstance(param.type, click.Choice): + yield path, param.name, list(param.type.choices) + + yield from walk(root, []) + + +def test_choice_options_are_discovered(): + """Guard the test itself: the CLI must expose Choice-typed options.""" + # Arrange & Act + discovered = list(_choice_options()) + + # Assert + assert discovered, "no click.Choice options found; has the CLI been migrated?" + + +def test_choice_options_render_their_choices(): + """Test that every Choice option advertises its values in --help output.""" + # Arrange + runner = CliRunner() + help_cache = {} + + # Act & Assert + for path, option_name, choices in _choice_options(): + key = tuple(path) + if key not in help_cache: + result = runner.invoke(app, [*path, "--help"]) + assert result.exit_code == 0, f"{' '.join(path)} --help failed" + help_cache[key] = result.output + output = help_cache[key] + + assert "