Refactor cli.py and apm_package.py into focused modules (#172)#224
Merged
sergio-sisternes-epam merged 5 commits intomicrosoft:mainfrom Mar 10, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the APM CLI and package model layers by splitting historically large modules into smaller, focused modules while maintaining backward-compatible imports and updating tests to point at the new module paths.
Changes:
- Extracted CLI commands into
src/apm_cli/commands/*and reducedcli.pyto a thin wiring layer. - Split
apm_package.pyintomodels/dependency.pyandmodels/validation.py, with re-exports preserved viamodels/__init__.pyandmodels/apm_package.py. - Updated unit/integration tests to patch/import functions from their new module locations.
Reviewed changes
Copilot reviewed 26 out of 28 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_transitive_deps.py | Updates orphan-check helper import to new commands helpers module. |
| tests/unit/test_install_command.py | Updates patch paths to commands.install module. |
| tests/unit/test_canonicalization.py | Updates patch paths/imports for install canonicalization helper. |
| tests/unit/test_auth_scoping.py | Updates patch paths/imports for install validation helper. |
| tests/unit/integration/test_skill_integrator.py | Updates patch path for _rich_warning to utils.console. |
| tests/unit/compilation/test_compilation.py | Updates imports for compile validation display helpers. |
| tests/integration/test_version_notification.py | Updates patch path for update-check helper to commands._helpers. |
| tests/integration/test_selective_install_mcp.py | Updates patch paths to commands._helpers and commands.install. |
| tests/integration/test_generic_git_url_install.py | Updates patch paths/imports for install canonicalization helper. |
| src/apm_cli/models/validation.py | New module containing package validation logic and related enums/types. |
| src/apm_cli/models/dependency.py | New module containing dependency parsing/canonicalization/reference models. |
| src/apm_cli/models/apm_package.py | Slimmed core package dataclasses + re-exports for backward compatibility. |
| src/apm_cli/models/init.py | Centralized model re-exports updated to new module structure. |
| src/apm_cli/integration/skill_integrator.py | Updates warning helper import location to avoid CLI circular imports. |
| src/apm_cli/commands/_helpers.py | New shared helpers module (console/theme, YAML loaders, orphan detection, etc.). |
| src/apm_cli/commands/init.py | New init command module extracted from former CLI monolith. |
| src/apm_cli/commands/install.py | New install command module (not shown in excerpts) targeted by tests. |
| src/apm_cli/commands/uninstall.py | New uninstall command module with transitive cleanup + reintegration. |
| src/apm_cli/commands/prune.py | New prune command module using shared orphan-detection helpers. |
| src/apm_cli/commands/compile.py | New compile command module including watch/validate modes. |
| src/apm_cli/commands/run.py | New run + preview command module. |
| src/apm_cli/commands/list_cmd.py | New list command module for scripts display. |
| src/apm_cli/commands/config.py | New config group module, including invoke-without-command behavior. |
| src/apm_cli/commands/runtime.py | New runtime group module for runtime setup/list/remove/status. |
| src/apm_cli/commands/mcp.py | New mcp group module for registry browsing (search/show/list). |
| src/apm_cli/commands/update.py | New update command module to check/install latest CLI version. |
You can also share your feedback on Copilot code review. Take the survey.
danielmeppiel
approved these changes
Mar 10, 2026
…ed apm_package modules Phase 2 of microsoft#172: Extract models into focused files. - Created models/dependency.py (DependencyReference, ResolvedReference, GitReferenceType, MCPDependency, parse_git_reference) - Created models/validation.py (ValidationResult, ValidationError, PackageType, PackageContentType, validate_apm_package + validators) - Slimmed models/apm_package.py to APMPackage, PackageInfo, cache logic (~240 lines) - Updated models/__init__.py with re-exports from all three modules - Backward-compatible re-exports in apm_package.py for direct imports
Phase 1 of microsoft#172: Split cli.py (4511 lines) into 12 command modules. cli.py is now an 80-line thin wiring layer. Updated test patch paths to match new module locations.
f4f8c94 to
13e8163
Compare
danielmeppiel
approved these changes
Mar 10, 2026
This was referenced Mar 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refactors the two largest source files into focused, maintainable modules. No user-facing behavior changes.
Fixes #172
Phase 1 — Extract CLI commands from
cli.pyintocommands/Reduced
cli.pyfrom 4,511 → 80 lines (thin wiring layer). Created 12 command modules:commands/_helpers.pycommands/init.pycommands/install.pycommands/uninstall.pycommands/prune.pycommands/update.pycommands/compile.pycommands/run.pycommands/list_cmd.pycommands/config.pycommands/runtime.pycommands/mcp.pyPhase 2 — Split
apm_package.pyinto focused model filesReduced
apm_package.pyfrom 1,577 → 239 lines. Created 2 new modules:models/dependency.pymodels/validation.pyBackward compatibility
models/__init__.pyre-exports all symbolsapm_package.pyincludes re-exports for direct imports (from apm_cli.models.apm_package import X)Type of change
Testing
Verification