Skip to content

refactor(config): read the python minor from the package metadata #6410

In review

Description

@dan-petty

Update 2026-11-26 (infra move): .github/renovate/base.json is gone. The shared preset is renovate/base.json of dan-petty/infra.

Validate .github/renovate.json only. The custom manager for DEFAULT_PYTHON_VERSION is not at index 5: find it by its pattern. No tools-lock pattern exists.


Problem

The Python minor version is copied into src/ in many places:

  • DEFAULT_PYTHON_VERSION (defaults.py:181) and the --python-version option of ci/typecheck.py:21.
  • _verify_python_314_environment (ci.py:246-258), a noqa'd UP036 copy of requires-python, with 20 call sites and the python_version_check gate row (ci.py:1306-1324, :1440-1450).
  • Literals in kb.py:561-562,574, analysis.py:635, canary.py:534,554, metadata.py:34-35,54 and DEFAULT_ANALYSIS_PYTHON_FLOOR (defaults.py:1359).
  • Seven python:3.14-slim defaults.

A Renovate custom manager (customManagers[5]) writes the defaults.py copy, and each such .py edit starts Fail-to-Pass. pyproject.toml (requires-python, [tool.mypy] python_version) already owns the value.

Change

  • Delete DEFAULT_PYTHON_VERSION (defaults.py:181) and the --python-version option of ci/typecheck.py:21. mypy reads [tool.mypy] python_version (pyproject.toml:202).
  • Delete _verify_python_314_environment, its 20 call sites, the python_version_check gate row, messages.py:2194,2275 and the unread mypy_check at :2231, and errors.py:291-292. Fix docs/SDLC.md:173,206.
  • One helper gives the Python minor: the requires-python of the reviewed project, else the Requires-Python of devops-cli from importlib.metadata, else sys.version_info. It replaces the literals at kb.py:561-562,574, analysis.py:635, canary.py:534,554, metadata.py:34-35,54 and DEFAULT_ANALYSIS_PYTHON_FLOOR.
  • The seven python:3.14-slim defaults (defaults.py:166,784, docker.py:404, sandbox.py:121, test_cmd.py:339, docker_plans.py:97, sandbox_plans.py:15) become one default computed from sys.version_info. The image stays a user option.
  • Change the tests that hard-code 3.14 or --python-version 3.14: test_typecheck.py:23-24, test_ci.py:383,471-480, test_metadata.py:42,51,80,104, the implement step tests, test_language_catalogs.py:95, test_sandbox.py:47, test_sandbox_dry_run.py:123-124, test_ai_gateway_tune.py:422, test_test_runner.py:490 and test_sandbox_trace_context.py.

Renovate. Remove the src/devops_cli/config/defaults.py pattern and the DEFAULT_PYTHON_VERSION alternative of customManagers[5]. Keep its pyproject.toml pattern (a manifest). Drop the sentence 'python:3.-slim defaults under src/' from the python-runtime prBodyNotes (packageRule 18).

Risk. Low. A person who runs the source tree on an older Python without uv sees an import error and not the gate message. The sandbox defaults follow the minor of the running interpreter.

Proof

  • The typecheck row of uv run devops ci passes with no --python-version.
  • git grep -nE 'python:3\.14-slim|"py314"|\(3, 14\)|DEFAULT_PYTHON_VERSION' origin/main -- 'src/**/*.py' returns nothing. (The pattern is limited to Python files, because a shipped Dockerfile can name a python image.)
  • Scoped pytest passes. docs/MCP_TOOLS.md and the MCP snapshot do not change, because the computed value equals the literal of today.

Depends on: #5585, #4388

Alternatives check of 2026-11-27: not-applicable.
Class: refactor, no model call.
Tool: none found.

Proposed design

Problem statement

The Python minor version is copied into many source files, tests, a CI gate and Renovate rules. The copies drift from pyproject.toml. This change keeps one helper for the minor and one container-image default. It removes the duplicate CI gate, the --python-version option and the Renovate source edit.

Acceptance criteria

Requirement: Single Python minor helper

The project SHALL expose one helper get_project_python_version that returns the Python minor of the reviewed project, the installed package or the running interpreter.

Scenario: Reviewed project floor

  • WHEN the test writes requires-python = ">=3.13" to a temporary pyproject.toml and calls the helper on it
  • THEN the helper returns 3.13

Requirement: Installed package fallback

The helper SHALL use the Requires-Python value of the installed devops-cli distribution when the reviewed project gives no usable requires-python.

Scenario: Package metadata fallback

  • WHEN the project file is invalid and importlib.metadata.metadata returns Requires-Python: >=3.13
  • THEN the helper returns 3.13

Requirement: Running interpreter fallback

The helper MUST read sys.version_info at call time and use it when the project and the package give no version.

Scenario: Interpreter fallback

  • WHEN both sources fail and the test patches sys.version_info to major 3 and minor 13
  • THEN the helper returns 3.13

Requirement: One container image default

The project SHALL compute the default container image as python:<major>.<minor>-slim from sys.version_info in one function.

Scenario: Image default from the interpreter

  • WHEN the test patches sys.version_info to major 3 and minor 13 and calls default_python_image
  • THEN the function returns python:3.13-slim

Requirement: Review floor from the helper

The review analysis MUST build its py<major><minor> Python floor from get_project_python_version and SHALL hold no DEFAULT_ANALYSIS_PYTHON_FLOOR constant.

Scenario: Review floor for a project on 3.13

  • WHEN the test builds the analysis config of a project with requires-python = ">=3.13"
  • THEN the Python floor is py313

Requirement: No duplicated Python version literals

The Python files under src/ SHALL hold no DEFAULT_PYTHON_VERSION, DEFAULT_ANALYSIS_PYTHON_FLOOR, "py314", (3, 14) or python:3.14-slim literal.

Scenario: Source literal scan

  • WHEN git grep -nE 'DEFAULT_PYTHON_VERSION|DEFAULT_ANALYSIS_PYTHON_FLOOR|"py314"|\(3, 14\)|python:3\.14-slim' -- 'src/**/*.py' runs
  • THEN it returns no match

Requirement: Typecheck option removed

The typecheck command MUST NOT pass --python-version to mypy and SHALL take the version from [tool.mypy] python_version.

Scenario: Typecheck options

  • WHEN the test imports TYPECHECK_OPTIONS from devops_cli.ci.typecheck
  • THEN no entry is --python-version and no entry starts with --python-version=

Requirement: Python environment gate removed

The ci command MUST NOT run _verify_python_314_environment or write a python_version_check gate row.

Scenario: Removed gate scan

  • WHEN git grep -nE '_verify_python_314_environment|python_version_check' -- src/devops_cli/commands/ci.py src/devops_cli/lang/en/messages.py runs
  • THEN it returns no match

Requirement: Renovate configuration valid

The Renovate configuration SHALL stay valid after it drops the src/devops_cli/config/defaults.py pattern and keeps the pyproject.toml pattern.

Scenario: Renovate config validation

  • WHEN npx --yes --package renovate renovate-config-validator --strict .github/renovate.json runs
  • THEN the validator exits 0 and reports no error

Requirement: SDLC documentation updated

docs/SDLC.md SHALL name pyproject.toml and mypy as the source of the Python minor and MUST NOT name the python_version_check gate or DEFAULT_PYTHON_VERSION.

Scenario: SDLC documentation check

  • WHEN uv run devops ci --check --only docs runs and git grep -nE 'python_version_check|DEFAULT_PYTHON_VERSION' docs/SDLC.md runs
  • THEN the docs row exits 0 and the grep returns no match

Requirement: Scoped tests pass

The changed tests SHALL pass with no hard-coded 3.14 expectation and no --python-version 3.14 argument.

Scenario: Scoped test run

  • WHEN uv run pytest tests/ci/test_typecheck.py tests/config/test_metadata.py tests/commands/test_ci.py runs
  • THEN all selected tests pass

Existing Tool Considered

The alternatives check in the issue body holds the verdict (not-applicable); it names no tool. packaging is open and maintained, and pyproject.toml pins it as packaging==26.3. It covers the parse of requires-python through packaging.specifiers.SpecifierSet. It lacks the project-to-package-to-interpreter fallback, the py<major><minor> review floor and the python:<major>.<minor>-slim image default. The change adds these in src/devops_cli/config/metadata.py and src/devops_cli/config/defaults.py: about 2,000 tokens to build, about 500 tokens per later change to keep, and about 2 hours.

Key questions

  • Where should the single Python minor helper live?: Extend src/devops_cli/config/metadata.py with get_project_python_version. The module already finds the project file, parses its requires-python and falls back to the installed distribution. (best practice) [sources: src/devops_cli/config/metadata.py:39, src/devops_cli/config/metadata.py:49, pyproject.toml]
    • Chosen: Extend src/devops_cli/config/metadata.py. It already holds the project file search, the version parse and the distribution fallback, so the change adds no second loader.
    • Rejected: New module src/devops_cli/config/python_version.py. It duplicates the loader, the path search and the distribution fallback.
    • Rejected: src/devops_cli/review/canary.py. Its parsers serve a review tree only, and the typecheck, sandbox and analysis call sites are outside the review.
  • How should the helper read the minor from a requires-python specifier?: Parse the specifier with packaging.specifiers.SpecifierSet and take the lowest version of the >= or ~= bounds. If it holds no lower bound, use the next source. (best practice) [sources: pyproject.toml, src/devops_cli/config/metadata.py:49]
    • Chosen: packaging.specifiers.SpecifierSet. It is open, maintained and already pinned, and it handles ~=, != and compound specifiers.
    • Rejected: The current regular expression. It reads only a leading >=, so ~=3.14 and >=3.13,<4 give the wrong minor.
    • Rejected: sys.version_info only. It ignores the Python floor that the reviewed project declares.
  • In which order should the helper read the Python minor?: The reviewed project's requires-python, then the Requires-Python of the installed devops-cli distribution, then sys.version_info read inside the call. (best practice) [sources: pyproject.toml, src/devops_cli/config/metadata.py:39]
    • Chosen: Project, package, interpreter. The reviewed project floor has priority, and the package and the interpreter are fallbacks.
    • Rejected: Package, project, interpreter. A review of another project would use the devops-cli version before the project floor.
    • Rejected: Interpreter, project, package. It hides the Python floor that the project declares.
  • Should the ci Python environment gate stay?: No. Remove _verify_python_314_environment, its call sites, the python_version_check gate row and its messages. pyproject.toml and [tool.mypy] python_version own the value. (best practice) [sources: src/devops_cli/commands/ci.py, src/devops_cli/lang/en/messages.py, pyproject.toml]
    • Chosen: Remove the gate. It removes a duplicate version source and the noqa'd UP036 copy, and mypy still reads the one setting.
    • Rejected: Keep a non-gating check. It still duplicates the version and still starts Fail-to-Pass on each edit.
    • Rejected: Replace the gate with a helper call. It adds no gate value over pyproject.toml and mypy.
  • Should the typecheck command keep --python-version?: No. Remove it from TYPECHECK_OPTIONS at src/devops_cli/ci/typecheck.py:21. mypy reads [tool.mypy] python_version from pyproject.toml. (best practice) [sources: src/devops_cli/ci/typecheck.py:21, pyproject.toml, tests/ci/test_typecheck.py]
    • Chosen: Remove --python-version. It leaves one version source in pyproject.toml.
    • Rejected: Keep the option with a helper default. It duplicates the mypy setting and gives two values that can drift.
  • How should the seven container image defaults become one?: Add one default_python_image() function to src/devops_cli/config/defaults.py that returns python:{sys.version_info.major}.{sys.version_info.minor}-slim. Call it at the seven former literal sites. The image stays a user option. (best practice) [sources: src/devops_cli/config/defaults.py, src/devops_cli/commands/sandbox.py, src/devops_cli/sandbox/sandbox_plans.py]
    • Chosen: One default_python_image() from sys.version_info. The image follows the running interpreter, as the issue states, and has one definition.
    • Rejected: One default from the helper. The image would follow the reviewed project and not the runner.
    • Rejected: Keep seven literals. The literals drift and start Fail-to-Pass on each edit.
  • What should happen to DEFAULT_ANALYSIS_PYTHON_FLOOR and the review literals?: Remove the constant at src/devops_cli/config/defaults.py:1434 and build the py<major><minor> floor from the helper in src/devops_cli/review/analysis.py. The py314 fallbacks in src/devops_cli/review/canary.py use the same helper. (best practice) [sources: src/devops_cli/config/defaults.py:1434, src/devops_cli/review/analysis.py, src/devops_cli/review/canary.py]
    • Chosen: Remove the constant and derive the floor. It removes a second version source and leaves the helper as the one source.
    • Rejected: Keep it as an alias. It leaves a duplicate value that can drift.
  • How should the Renovate custom manager change?: Remove the src/devops_cli/config/defaults.py pattern and the DEFAULT_PYTHON_VERSION alternative of customManagers[5]. Keep the pyproject.toml and tools-lock patterns. Drop the python:3.<minor>-slim sentence of packageRule 18 and the DEFAULT_PYTHON_VERSION mentions in .github/renovate.json and docs/SDLC.md. (best practice) [sources: .github/renovate.json, docs/SDLC.md]
    • Chosen: Keep only the manifest and tools-lock patterns. pyproject.toml is a manifest and already owns requires-python, and no source copy remains.
    • Rejected: Keep the defaults.py pattern. It edits source and starts Fail-to-Pass.
    • Rejected: Move the pattern to packageRule 18. It keeps a source copy of the version.
  • How should the tests that hard-code 3.14 change?: Derive the expected value from the helper or from sys.version_info. The metadata tests compare with _parse_python_version, the typecheck tests assert on TYPECHECK_OPTIONS, and the sandbox tests read default_python_image. Add no new 3.14 literal. (best practice) [sources: tests/config/test_metadata.py, tests/ci/test_typecheck.py]
    • Chosen: Derive the expected value. The tests then follow the one version source and do not break when the minor changes.
    • Rejected: Keep 3.14 literals. The tests break when the Python minor changes.
    • Rejected: Skip the affected tests. It removes coverage of the version path.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#5585, #4388

Activity

  1. added
    type/refactor
    on Nov 19, 2026
  2. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor
  3. added
    scope/config
    source/agent
    status/new
    value/medium
    effort/high
    priority/p2-medium
    on Nov 19, 2026
  4. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  5. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  6. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highowner/agentpriority/p2-mediumscope/configsource/agentstatus/in-progresstype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions