Skip to content

fix: Refactor command and model modules for readability and maintainability (#231) - #232

Merged
Daniel Meppiel (danielmeppiel) merged 3 commits into
microsoft:mainfrom
sergio-sisternes-epam:fix/231-refactor-command-model-modules
Mar 19, 2026
Merged

fix: Refactor command and model modules for readability and maintainability (#231)#232
Daniel Meppiel (danielmeppiel) merged 3 commits into
microsoft:mainfrom
sergio-sisternes-epam:fix/231-refactor-command-model-modules

Conversation

@sergio-sisternes-epam

Copy link
Copy Markdown
Collaborator

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

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

Testing

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

CopilotAI 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.

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.py and 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 Exception clauses.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 5 comments.

Show a summary per file
FileDescription
tests/unit/test_install_command.pyUpdates mocks to use InstallResult instead of a tuple.
src/apm_cli/models/validation.pyUses shared constants for filenames/dirs; narrows exception types.
src/apm_cli/models/results.pyAdds typed dataclass result containers.
src/apm_cli/models/dependency/types.pyExtracts enums/dataclasses and parse_git_reference.
src/apm_cli/models/dependency/reference.pyMoves DependencyReference parsing logic into a dedicated module.
src/apm_cli/models/dependency/mcp.pyMoves MCPDependency into its own module.
src/apm_cli/models/dependency/init.pyRe-exports dependency types/models from the new package.
src/apm_cli/models/dependency.pyRemoves the former 1000+ line dependency “god file”.
src/apm_cli/models/init.pyExposes InstallResult/PrimitiveCounts at the models package level.
src/apm_cli/constants.pyAdds shared constants (filenames/dirs) and InstallMode enum.
src/apm_cli/commands/update.pyNarrows exception handling in update flow.
src/apm_cli/commands/uninstall/engine.pyIntroduces uninstall engine helpers (validation/removal/cleanup/reintegration).
src/apm_cli/commands/uninstall/cli.pyIntroduces a new uninstall CLI wiring that delegates to the engine.
src/apm_cli/commands/uninstall/init.pyExposes uninstall command and helper functions from the new package.
src/apm_cli/commands/uninstall.pyRemoves the former monolithic uninstall implementation.
src/apm_cli/commands/runtime.pyNarrows broad exception handling.
src/apm_cli/commands/run.pyNarrows broad exception handling in script listing/execution.
src/apm_cli/commands/prune.pyUses shared constants; narrows exceptions; restructures deployed-file cleanup loop.
src/apm_cli/commands/mcp.pyNarrows broad exception handling around registry calls.
src/apm_cli/commands/list_cmd.pyNarrows broad exception handling in Rich fallback.
src/apm_cli/commands/install.pyUses shared constants; adds InstallMode; returns InstallResult; extracts integration helper.
src/apm_cli/commands/init.pyUses shared constants; narrows prompt exception handling.
src/apm_cli/commands/deps/cli.pyFixes imports, uses constants, and moves helper logic to deps/_utils.py.
src/apm_cli/commands/deps/_utils.pyNew helper module for deps commands (counts, nested detection, updates).
src/apm_cli/commands/deps/init.pyExposes deps CLI and helpers via package exports.
src/apm_cli/commands/config.pyUses shared constants for apm.yml checks.
src/apm_cli/commands/compile/watcher.pyExtracts watch-mode logic into a dedicated module.
src/apm_cli/commands/compile/cli.pyUses shared constants; factors out summary/next-step display; imports watcher module.
src/apm_cli/commands/compile/init.pyExposes compile command and helper functions via package exports.
src/apm_cli/commands/_helpers.pyUses shared constants; narrows exceptions; updates gitignore handling.
.vscode/tasks.jsonAdds local VS Code tasks (currently machine-path specific).

You can also share your feedback on Copilot code review. Take the survey.

Comment threadsrc/apm_cli/commands/install.py Outdated
Comment threadsrc/apm_cli/models/dependency/reference.py Outdated
Comment threadsrc/apm_cli/commands/uninstall/cli.py Outdated
Comment threadsrc/apm_cli/commands/uninstall/engine.py Outdated
Comment threadsrc/apm_cli/commands/install.py Outdated
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

CopilotAI 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.

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.

Comment threadsrc/apm_cli/commands/compile/watcher.py Outdated
Comment threadapm.code-workspace Outdated
Comment threadsrc/apm_cli/models/dependency/types.py Outdated
Comment threadsrc/apm_cli/models/dependency/reference.py
Comment threadsrc/apm_cli/commands/uninstall/cli.py Outdated
Comment threadsrc/apm_cli/commands/uninstall/engine.py Outdated
Comment threadsrc/apm_cli/commands/prune.py Outdated
…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>
@sergio-sisternes-epam

Copy link
Copy Markdown
CollaboratorAuthor

Addressing Copilot Review Feedback — 6940765

All 7 new review comments resolved:

CommentFileResolution
Unused APM_MODULES_DIR importcompile/watcher.py✅ Removed
Hardcoded apm.code-workspacerepo root✅ Removed from tracking, added *.code-workspace to .gitignore
Trailing whitespacedependency/types.py✅ Removed
@alias parsing in reference.pydependency/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 guarduninstall/cli.py✅ Removed — switched to direct imports
Unused shutil + dead guarduninstall/engine.py✅ Removed both
Unused yaml importprune.py✅ Removed

All 2104 unit tests passing.

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit cc4cc28 into microsoft:mainMar 19, 2026
7 checks passed
Sergio Sisternes (sergio-sisternes-epam) added a commit that referenced this pull request May 19, 2026
…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>
Sign up for freeto 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.

[TASK] Refactor command and model modules for readability and maintainability

3 participants

@sergio-sisternes-epam@danielmeppiel