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
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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'

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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",
Expand Down
75 changes: 75 additions & 0 deletions tests/cli/test_click_choice_options.py
Original file line number Diff line number Diff line change
@@ -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 ``<function>`` 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 "<function" not in output, (
f"{' '.join(path)} renders a function metavar; typer is not using the "
"installed click"
)
for choice in choices:
assert choice in output, (
f"{' '.join(path)} --{option_name} does not advertise {choice!r}"
)
18 changes: 10 additions & 8 deletions uv.lock

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

Loading