Dependency Management¶
Overview¶
PinViz uses uv.lock to ensure reproducible builds across all environments. This lock file is critical for:
- Reproducible builds: Same dependencies everywhere
- Security: Dependabot monitors
uv.lockfor vulnerabilities - CI/CD: Automated testing with exact dependency versions
Quick Reference¶
Always Commit uv.lock¶
When you modify pyproject.toml, always commit the updated uv.lock file:
# After editing pyproject.toml
uv lock # Update lock file
uv sync --dev # Sync environment
git add uv.lock pyproject.toml
git commit -m "Add new dependency"
Verify Lock File¶
Check if uv.lock is in sync with pyproject.toml:
This command returns:
- Exit code 0: Lock file is in sync
- Exit code 1: Lock file is out of sync (run uv lock to fix)
Automated Protection¶
Pre-commit Hooks¶
Install pre-commit hooks to automatically validate uv.lock before commits:
The pre-commit configuration (.pre-commit-config.yaml) includes:
- uv-lock: Automatically updates lock file if out of sync
- ruff: Lints and formats code
- Basic checks: trailing whitespace, YAML validation, etc.
CI Pipeline¶
GitHub Actions automatically validates uv.lock on every push and PR:
If the CI fails with a lock file error:
- Pull the latest changes
- Run
uv locklocally - Commit and push the updated lock file
Common Scenarios¶
Adding a New Dependency¶
# Edit pyproject.toml to add dependency
vim pyproject.toml
# Update lock file
uv lock
# Install the dependency
uv sync --dev
# Commit both files
git add pyproject.toml uv.lock
git commit -m "Add requests dependency"
Dependabot Updates¶
When Dependabot creates a PR to update dependencies:
- Dependabot automatically updates
uv.lock - CI validates the lock file
- Review and merge the PR
Merge Conflicts¶
If you have local changes to uv.lock and remote changes conflict:
# Stash local changes
git stash
# Pull latest changes
git pull
# Regenerate lock file (if needed)
uv sync --dev
# Your environment is now in sync
Why This Matters¶
For Maintainers¶
- Security: Dependabot can only monitor dependencies it knows about
- Debugging: Exact dependency versions help reproduce issues
- Releases: Lock file ensures consistent release builds
For Contributors¶
- Onboarding: New contributors get exact working versions
- CI Reliability: Tests run with same dependencies locally and in CI
- No Surprises: No "works on my machine" issues
Troubleshooting¶
Lock file out of sync¶
Error: CI fails with "uv.lock is out of sync"
Solution:
Pre-commit hook fails¶
Error: pre-commit hook updates uv.lock
Solution: This is expected! The hook auto-fixes the lock file:
Missing dependencies¶
Error: Import errors after git pull
Solution:
Best Practices¶
- Always commit lock file changes: Never add
uv.lockto.gitignore - Run
uv lockafter editingpyproject.toml: Keep them in sync - Use pre-commit hooks: Catch issues before pushing
- Review Dependabot PRs promptly: Keep dependencies up to date
- Don't manually edit
uv.lock: Always useuv lockcommand