PEP 735 introduces dependency groups in pyproject.toml
,
allowing tools like black, ruff, and mypy to be managed centrally.
However, when these tools are also used in pre-commit hooks,
keeping versions in sync between uv.lock
and .pre-commit-config.yaml
can be tedious.
This package automatically updates the versions of dependencies in .pre-commit-config.yaml
to match their versions in uv.lock
,
ensuring everything stays aligned and is managed from a single source.
Any tool not specified in uv.lock
remains managed by .pre-commit-config.yaml
.
Simply add this pre-commit hook to your setup and enjoy consistent dependency management.
Recommended: Use as a pre-commit hook
Simply add these lines to your .pre-commit-config.yaml
file:
- repo: https://github.com/tsvikas/sync-with-uv
rev: main # replace with the latest version
hooks:
- id: sync-with-uv
That's it! The hook will automatically keep your pre-commit versions in sync with uv.lock
.
For manual usage or CI/CD integration, install and run directly:
pipx install sync-with-uv
# Update .pre-commit-config.yaml
sync-with-uv
# Preview changes only
sync-with-uv --diff
# Custom file paths
sync-with-uv -p custom-precommit.yaml -u custom-lock.toml
Most users don't need this section - the tool works out of the box with popular tools like black, ruff, and mypy.
For tools not included in the built-in mapping, you can add custom mappings in your pyproject.toml
:
# Map repository URLs to package names
[tool.sync-with-uv.repo-to-package]
"https://github.com/myorg/my-awesome-linter" = "awesome-linter"
# Define custom version templates (optional)
[tool.sync-with-uv.repo-to-version-template]
"https://github.com/myorg/my-awesome-linter" = "ver_${rev}"
Example scenario:
- Your
.pre-commit-config.yaml
has:repo: https://github.com/myorg/my-awesome-linter
withrev: ver_1.2.0
- Your
uv.lock
contains:awesome-linter = "1.5.0"
- With the mapping above, sync-with-uv will update the pre-commit version to
ver_1.5.0
Interested in contributing? See CONTRIBUTING.md for development setup and guideline.