Uh oh!
There was an error while loading. Please reload this page.
fix: Refactor command and model modules for readability and maintainability (#231) - #232
Conversation
There was a problem hiding this comment.
Pull request overview
This PR continues the phased refactor of APM command/model code by extracting shared constants and typed result containers, reorganizing dependency/uninstall/compile/deps modules into smaller submodules, and tightening some overly-broad exception handling.
Changes:
- Introduces
src/apm_cli/constants.pyand replaces hard-coded filenames/dirs across commands/models. - Extracts typed result containers (
InstallResult,PrimitiveCounts) and updates install tests/mocks accordingly. - Splits large modules into packages/submodules (dependency models, uninstall command, deps helpers, compile watcher) and narrows some
except Exceptionclauses.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_install_command.py | Updates mocks to use InstallResult instead of a tuple. |
| src/apm_cli/models/validation.py | Uses shared constants for filenames/dirs; narrows exception types. |
| src/apm_cli/models/results.py | Adds typed dataclass result containers. |
| src/apm_cli/models/dependency/types.py | Extracts enums/dataclasses and parse_git_reference. |
| src/apm_cli/models/dependency/reference.py | Moves DependencyReference parsing logic into a dedicated module. |
| src/apm_cli/models/dependency/mcp.py | Moves MCPDependency into its own module. |
| src/apm_cli/models/dependency/init.py | Re-exports dependency types/models from the new package. |
| src/apm_cli/models/dependency.py | Removes the former 1000+ line dependency “god file”. |
| src/apm_cli/models/init.py | Exposes InstallResult/PrimitiveCounts at the models package level. |
| src/apm_cli/constants.py | Adds shared constants (filenames/dirs) and InstallMode enum. |
| src/apm_cli/commands/update.py | Narrows exception handling in update flow. |
| src/apm_cli/commands/uninstall/engine.py | Introduces uninstall engine helpers (validation/removal/cleanup/reintegration). |
| src/apm_cli/commands/uninstall/cli.py | Introduces a new uninstall CLI wiring that delegates to the engine. |
| src/apm_cli/commands/uninstall/init.py | Exposes uninstall command and helper functions from the new package. |
| src/apm_cli/commands/uninstall.py | Removes the former monolithic uninstall implementation. |
| src/apm_cli/commands/runtime.py | Narrows broad exception handling. |
| src/apm_cli/commands/run.py | Narrows broad exception handling in script listing/execution. |
| src/apm_cli/commands/prune.py | Uses shared constants; narrows exceptions; restructures deployed-file cleanup loop. |
| src/apm_cli/commands/mcp.py | Narrows broad exception handling around registry calls. |
| src/apm_cli/commands/list_cmd.py | Narrows broad exception handling in Rich fallback. |
| src/apm_cli/commands/install.py | Uses shared constants; adds InstallMode; returns InstallResult; extracts integration helper. |
| src/apm_cli/commands/init.py | Uses shared constants; narrows prompt exception handling. |
| src/apm_cli/commands/deps/cli.py | Fixes imports, uses constants, and moves helper logic to deps/_utils.py. |
| src/apm_cli/commands/deps/_utils.py | New helper module for deps commands (counts, nested detection, updates). |
| src/apm_cli/commands/deps/init.py | Exposes deps CLI and helpers via package exports. |
| src/apm_cli/commands/config.py | Uses shared constants for apm.yml checks. |
| src/apm_cli/commands/compile/watcher.py | Extracts watch-mode logic into a dedicated module. |
| src/apm_cli/commands/compile/cli.py | Uses shared constants; factors out summary/next-step display; imports watcher module. |
| src/apm_cli/commands/compile/init.py | Exposes compile command and helper functions via package exports. |
| src/apm_cli/commands/_helpers.py | Uses shared constants; narrows exceptions; updates gitignore handling. |
| .vscode/tasks.json | Adds local VS Code tasks (currently machine-path specific). |
You can also share your feedback on Copilot code review. Take the survey.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f0285cd to
425f12eComparePhases 1-5 of command/model refactoring: - Extract constants and narrow exception handlers - Decompose god functions into focused helpers - Add InstallMode and VirtualPackageType enums - Split god files into focused sub-modules - Flatten nesting and add typed result dataclasses - Address Copilot review feedback - Clean-up support tasks
c9c2e66 to
2437fd1CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…d dead code - Remove unused APM_MODULES_DIR import from compile/watcher.py - Remove trailing whitespace in models/dependency/types.py - Remove dead APM_DEPS_AVAILABLE conditional import pattern from uninstall/cli.py and engine.py - Remove unused shutil import from uninstall/engine.py - Remove unused yaml import from prune.py - Remove apm.code-workspace from tracking and add *.code-workspace to .gitignore Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addressing Copilot Review Feedback — |
| Comment | File | Resolution |
|---|---|---|
Unused APM_MODULES_DIR import | compile/watcher.py | ✅ Removed |
Hardcoded apm.code-workspace | repo root | ✅ Removed from tracking, added *.code-workspace to .gitignore |
| Trailing whitespace | dependency/types.py | ✅ Removed |
@alias parsing in reference.py | dependency/reference.py | ℹ️ Pre-existing by design — shorthand @alias was intentionally removed (see test_package_identity.py tests). Alias is only set via YAML alias: field. |
Dead APM_DEPS_AVAILABLE guard | uninstall/cli.py | ✅ Removed — switched to direct imports |
Unused shutil + dead guard | uninstall/engine.py | ✅ Removed both |
Unused yaml import | prune.py | ✅ Removed |
All 2104 unit tests passing.
cc4cc28
into
microsoft:mainUh oh!
There was an error while loading. Please reload this page.
…bility (#231) (#232) * refactor: split god files into focused sub-modules (#231) Phases 1-5 of command/model refactoring: - Extract constants and narrow exception handlers - Decompose god functions into focused helpers - Add InstallMode and VirtualPackageType enums - Split god files into focused sub-modules - Flatten nesting and add typed result dataclasses - Address Copilot review feedback - Clean-up support tasks * refactor: address Copilot review feedback — cleanup unused imports and dead code - Remove unused APM_MODULES_DIR import from compile/watcher.py - Remove trailing whitespace in models/dependency/types.py - Remove dead APM_DEPS_AVAILABLE conditional import pattern from uninstall/cli.py and engine.py - Remove unused shutil import from uninstall/engine.py - Remove unused yaml import from prune.py - Remove apm.code-workspace from tracking and add *.code-workspace to .gitignore Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Sergio Sisternes <sergio.sisternes@epam.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Daniel Meppiel <51440732+danielmeppiel@users.noreply.github.com>
Description
Phased refactoring of command and model modules to bring all files under code quality thresholds (400-line file limit, 30-statement function limit).
Fixes#231
Type of change
Testing