Skip to content

fix(install): drop undeclared packaging import from the .mcp.json heal gate - #3909

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-fix-packaging-runtime-import
Nov 19, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-fix-packaging-runtime-import

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

apm install failed with [x] Error installing dependencies: No module named 'packaging' when APM was installed without dev extras, for example with pip install apm-cli. lock_predates_root_mcp_json in src/apm_cli/install/mcp/retired_destinations.py imported packaging.version, and packaging is not a runtime dependency. The import came in with #3875; #3899 put it on every install path.

The fix reads the PEP 440 release from the lock's apm_version with a stdlib regex instead. I compared it with packaging on 24 version strings (None, empty, unknown, pre-releases, dev and local versions, post releases, epochs, a v prefix, garbage): the results are identical.

New guard: tests/unit/test_runtime_import_declarations.py statically scans src/apm_cli and requires every third-party import root to map to a [project].dependencies entry. The only exceptions are certifi and urllib3, which requests hard-requires, and the unreachable importlib_metadata fallback. It fails on main, naming packaging.

Why CI missed it: every CI job installs --extra dev, and pytest and pylint bring packaging in. The PyInstaller binary bundles packaging because PyInstaller itself depends on it. No job exercised a plain runtime install. The static guard does not depend on the environment.

Issue and approved scope

Issue: Fixes #3908

Human scope-approval comment: #3908 (comment)

Does this PR complete the issue, or what remains? It completes the issue.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Commands and results:

  1. uv venv /tmp/cleanvenv && VIRTUAL_ENV=/tmp/cleanvenv uv pip install .. import packaging raises ModuleNotFoundError, which confirms packaging is not installed.
  2. apm install on a fixture with a 0.36.1 lock and a copilot MCP claim:
    • main: [x] Error installing dependencies: No module named 'packaging'
    • this PR: Installed 1 MCP server, exit code 0, .mcp.json written.
  3. .venv/bin/python -m pytest tests/unit/test_runtime_import_declarations.py tests/unit/install/test_copilot_project_mcp_destination.py -p no:xdist -q: 44 passed. The guard fails with the fix reverted.
  4. Lint chain: ruff check, ruff format, pylint R0801, the auth-signal lint and the architecture linter are clean.

Changelog

  • One line under ## [Unreleased] in CHANGELOG.md: user-visible
    effect first, 25 words or fewer, ending with (#PR); see
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…l gate

apm install failed with "No module named 'packaging'" when APM was
installed without dev extras. lock_predates_root_mcp_json now reads the
lock apm_version release with the standard library (same results as
packaging for PEP 440 versions), and a static test checks that every
third-party import under src/apm_cli maps to a declared runtime
dependency.

apm-spec-waiver: dependency-hygiene fix with no OpenAPM-observable behaviour change

Fixes #3908

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 19, 2026
Copilot AI balanced review requested due to automatic review settings November 19, 2026 09:20
Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change removing the undeclared packaging dependency from the MCP migration gate.

No open issues 🎉

What changed in this PR

Fixes #3908 by removing the undeclared packaging dependency from the lockfile gate used to migrate Copilot MCP configuration to root .mcp.json, restoring apm install without dev extras.

Changes:

  • Replaces packaging.version parsing with a standard-library regex.
  • Adds a static guard checking third-party imports against declared runtime dependencies, with explicit exceptions.
  • Documents the installation fix in the changelog.
File Description
tests/​unit/​test_runtime_import_declarations.py Adds static checks for undeclared runtime imports.
src/​apm_cli/​install/​mcp/​retired_destinations.py Removes the gate’s dependency on packaging.
CHANGELOG.md Records the fix for installations without dev extras.

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 7b2cd3a into main Nov 19, 2026
33 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-fix-packaging-runtime-import branch November 19, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] apm install fails without dev extras: No module named 'packaging'

2 participants