sync-with-uv
Overview
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/prek.toml can be tedious.
This package automatically updates the versions of dependencies in .pre-commit-config.yaml/prek.toml 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/prek.toml.
Simply add this pre-commit hook to your setup and enjoy consistent dependency management.
Usage
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
or to your prek.toml:
[[repos]]
repo = "https://github.com/tsvikas/sync-with-uv"
rev = "main" # replace with the latest version
hooks = [{ id = "sync-with-uv" }]
[!NOTE] Place this hook after hooks that modify
uv.lock(likeuv-lock), and before hooks that read versions from.pre-commit-config.yaml/prek.toml(likesync-pre-commit-deps).
That's it! The hook syncs versions for any tool present in both your pre-commit config and uv.lock.
To make a tool eligible, add it to your uv dependencies with uv add --group dev <tool-name>.
Alternative: Command Line Interface
For manual usage or CI/CD integration, install and run directly:
uv tool install sync-with-uv
# Update .pre-commit-config.yaml / prek.toml
sync-with-uv
# Preview changes only
sync-with-uv --diff
# Custom file paths
sync-with-uv -u custom-lock.toml
sync-with-uv -p custom-precommit.yaml
sync-with-uv -p custom-prek.toml
Syncing additional dependencies
Besides the rev of each hook, the tool can also sync version pins inside
additional_dependencies (or any other dependency line).
Because these lists can contain arbitrary packages,
syncing is strictly opt-in per line:
a dependency is only touched if its line carries a # sync-with-uv pragma comment.
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==23.9.1 # sync-with-uv
- some-other-lib==1.0.0 # left alone, no pragma
For every annotated line, the dependency is pinned to an exact version
(==) from uv.lock, adding a specifier when the dependency has none,
so the example above becomes black==<locked>.
The package name, extras (like black[jupyter]), environment markers
(like ; python_version < "3.11"), quoting, and the comment itself are preserved.
Because the pragma is an explicit request to sync a line, the tool errors (exit code 123) when an annotated line cannot be synced.
Advanced Configuration
The tool works out of the box with popular tools like black, ruff, and mypy, as well as commonly used mirrors for those tools. Most users don't need the settings below.
Mapping from repo URL to package name
Details and example
By default, the tool assumes the last part of a repo URL is the package name.
For example, if repo: https://github.com/my-org/my-awesome-linter is in .pre-commit-config.yaml/prek.toml,
the tool will sync with the version of my-awesome-linter in uv.lock.
The tool skips any repo without a corresponding package in uv.lock.
To link a repo to a different package name,
add an entry to the [tool.sync-with-uv.repo-to-package] section in pyproject.toml.
Use an empty value to disable syncing for a specific repo.
[tool.sync-with-uv.repo-to-package]
# sync this repo with the `awesome-linter` package
"https://github.com/my-org/my-awesome-linter" = "awesome-linter"
# do not sync this repo, even if `cool-tool` is in `uv.lock`
"https://github.com/my-org/cool-tool" = ""
Mapping from repo URL to version tag format
Details and example
For each repo in .pre-commit-config.yaml/prek.toml with a linked package,
the tool updates the rev field with the version from uv.lock, optionally preserving a leading v.
The tool preserves the original formatting and any comments on the rev line.
For example, if the uv.lock version is 1.2.3,
it will update rev: 1.0.0 to rev: 1.2.3,
and rev: v1.0.0 to rev: v1.2.3.
To use a custom format for the rev field,
add an entry to the [tool.sync-with-uv.repo-to-version-template] section in pyproject.toml,
using ${version} as a placeholder for the package version.
[tool.sync-with-uv.repo-to-version-template]
# for example, this project uses `version_1.2.3` format for tags
"https://github.com/my-org/my-awesome-linter" = "version_${version}"
Contributing
Interested in contributing? See CONTRIBUTING.md for development setup and guideline.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sync_with_uv-0.6.0.tar.gz.
File metadata
- Download URL: sync_with_uv-0.6.0.tar.gz
- Upload date:
- Size: 128.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb995f87e7863e281ff005e8e74fda043af320a8fcb6cef949a83dea0ac944bd
|
|
| MD5 |
0f84d96634876aa6df1d6a736133154a
|
|
| BLAKE2b-256 |
b703b152ef82e9de78584ac82537c98991723bec809e4994c1d3e2bb022469e4
|
Provenance
The following attestation bundles were made for sync_with_uv-0.6.0.tar.gz:
Publisher:
build-and-publish.yml on tsvikas/sync-with-uv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sync_with_uv-0.6.0.tar.gz -
Subject digest:
cb995f87e7863e281ff005e8e74fda043af320a8fcb6cef949a83dea0ac944bd - Sigstore transparency entry: 2167784974
- Sigstore integration time:
-
Permalink:
tsvikas/sync-with-uv@8b089a262058ae82383241b8054585115918746c -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/tsvikas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yml@8b089a262058ae82383241b8054585115918746c -
Trigger Event:
release
-
Statement type:
File details
Details for the file sync_with_uv-0.6.0-py3-none-any.whl.
File metadata
- Download URL: sync_with_uv-0.6.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acb634a3ddc406f0d713b9263106f52b7d4a7ee791d2105efe8d4a6f6abc42dd
|
|
| MD5 |
2699d45faaa01baa3d2aca8a4688dd52
|
|
| BLAKE2b-256 |
8cc3353b684b02ab653fbbd60172fac7a715b0d49d03a7c7da51db2a364dc061
|
Provenance
The following attestation bundles were made for sync_with_uv-0.6.0-py3-none-any.whl:
Publisher:
build-and-publish.yml on tsvikas/sync-with-uv
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sync_with_uv-0.6.0-py3-none-any.whl -
Subject digest:
acb634a3ddc406f0d713b9263106f52b7d4a7ee791d2105efe8d4a6f6abc42dd - Sigstore transparency entry: 2167784984
- Sigstore integration time:
-
Permalink:
tsvikas/sync-with-uv@8b089a262058ae82383241b8054585115918746c -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/tsvikas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-publish.yml@8b089a262058ae82383241b8054585115918746c -
Trigger Event:
release
-
Statement type: