Refactor package selection logic into independent module #1
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.
Extracts package selection logic from the build API into a standalone module, enabling independent package queries without triggering full ImageBuilder container operations.
Changes
New Module:
asu/package_selection.pyExtracted functions from inline logic in
build.py:get_default_packages()- Parse ImageBuilder default packagesget_profile_packages()- Parse profile-specific packagescalculate_package_selection()- Apply diff_packages logic and package changesvalidate_package_manifest()- Verify package versionsNew API Endpoints:
asu/routers/packages.pyPOST /api/v1/packages/select- Calculate package selection without buildingGET /api/v1/packages/defaults/{version}/{target}/{subtarget}- Query default packagesGET /api/v1/packages/profile/{version}/{target}/{subtarget}/{profile}- Query profile packagesRefactored:
asu/build.pyReplaced 24 lines of inline regex parsing and package selection logic with calls to new module:
Backward Compatibility
All existing
/api/v1/buildbehavior unchanged - identical package selection logic, request/response formats, and error handling maintained.Original prompt
Objective
Refactor the ASU codebase to separate package selection logic from the build API, enabling two independent services:
The refactoring must maintain 100% backward compatibility with the current API - all existing endpoints, request/response formats, and behaviors must remain unchanged.
Current Architecture Analysis
The current implementation in
asu/build.pyhandles both:diff_packagesThe API endpoint
/api/v1/build(inasu/api.pyorasu/routers/api.py) combines these operations.Required Changes
1. Create New Package Selection Module (
asu/package_selection.py)Extract package selection logic into a new standalone module with the following functions:
2. Create Package Selection API Router (
asu/routers/packages.py)Create a new API router with endpoints:
3. Refactor Build Module (
asu/build.py)Modify the
_build()function to:package_selectionmodulecalculate_package_selection()4. Update API Router
If using newer router structure (
asu/routers/api.py):/api/v1/buildcontinues to work identicallyIf using legacy structure (
asu/api.py):5. Add Tests
Create
tests/test_package_selection.py:/api/v1/buildtestsUpdate
tests/test_api.py:Constraints
asu/openapi.ymlonly to add new endpointsImplementation Notes
BuildRequestclass fromasu/build_request.pyasu/util.py(e.g.,get_request_hash,parse_manifest,check_manifest)Success Criteria
/api/v1/buildendpoint behavior is unchangedThis pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.