Safe Python Dependency Upgrade
This skill provides a structured process for safely upgrading Python dependencies using uv, ensuring project stability through pre-upgrade health checks and post-upgrade validation.
1. Preparation & Health Check
Before making any changes, verify the current state of the project:
- •Baseline Health Check:
- •Run the test suite:
make test. - •Constraint: If the baseline tests fail, resolve those issues before proceeding with upgrades.
- •Run the test suite:
- •Backup:
- •Backup
uv.lockandpyproject.toml:cp uv.lock uv.lock.bakandcp pyproject.toml pyproject.toml.bak.
- •Backup
2. Upgrade Execution
Choose the appropriate upgrade path based on the user's request. Refer to ../common-references/python-commands.md for project-specific commands.
Targeted Upgrade (Recommended)
Use this when the user specifies a package or a small set of packages.
- •Upgrade: Run
uv add <package>@latestoruv lock --upgrade-package <package>. - •Verify: Check
pyproject.tomloruv.lockto ensure the version has been updated.
Full Upgrade (Maintenance)
Use this for general dependency maintenance.
- •Upgrade: Run
uv lock --upgrade. - •Check for Changes: Review the
uv.lockchanges and check for major version bumps.
3. Validation & Verification
After the upgrade, ensure the project remains stable:
- •Re-sync: Run
uv sync --all-extrasto update the environment. - •Invoke Verifier: Use the
verifiersubagent (../../agents/verifier.md) to run the full build, lint, and test cycle (e.g.,make lint,make test,make build). - •Handle Failure: If any check reports persistent issues it cannot fix, analyze the breaking changes and apply manual fixes or roll back.
4. Finalization
- •Commit: Create a commit with the updated
pyproject.tomlanduv.lock.- •Message Suggestion:
chore(deps): upgrade dependencies
- •Message Suggestion:
- •Cleanup: Remove backup files:
rm *.bak.
Rollback Plan
If validation fails and cannot be easily fixed:
- •Restore:
mv pyproject.toml.bak pyproject.tomlandmv uv.lock.bak uv.lock. - •Re-sync: Run
uv sync --all-extrasto restore the environment. - •Report: Notify the user of the failure and the reasons (e.g., specific breaking changes).