Skip to main content

Sync '.pre-commit-config.yaml' from 'uv.lock'.

Project description

sync-with-uv

Tests uv Ruff Black codecov
PyPI version PyPI platforms Total downloads
Made Using tsvikas/python-template GitHub Discussion PRs Welcome

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 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.

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

Note: Place this hook after hooks that modify uv.lock (like uv-lock), and before hooks that read versions from .pre-commit-config.yaml (like sync-pre-commit-deps).

That's it! The hook will automatically sync versions for any tools present in both your pre-commit config and uv.lock.

To add a tool to your uv dependencies, use uv add --group dev tool-name (the tool must be available on PyPI).

Alternative: Command Line Interface

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

Advanced Configuration

Most users don't need this section - the tool works out of the box with popular tools like black, ruff, and mypy, as well as commonly used mirrors for those tools.

Mapping from repo URL to package name

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, 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

For each repo in .pre-commit-config.yaml 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sync_with_uv-0.5.0.tar.gz (97.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sync_with_uv-0.5.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file sync_with_uv-0.5.0.tar.gz.

File metadata

  • Download URL: sync_with_uv-0.5.0.tar.gz
  • Upload date:
  • Size: 97.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sync_with_uv-0.5.0.tar.gz
Algorithm Hash digest
SHA256 236f9029e09c1edf0b13231be7f410119188ff77556069b4bed1c11947bb942c
MD5 9720adb4911fc729d119dfe3f928b4a3
BLAKE2b-256 5f95d187e24af4722f83bfef5fe7e050b183c1ae4a4064eb07bd15f7d153dbd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_with_uv-0.5.0.tar.gz:

Publisher: build-and-publish.yml on tsvikas/sync-with-uv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sync_with_uv-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: sync_with_uv-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sync_with_uv-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c05052bfa27552e159be61bd191d4d7b04b5d7621e7c126f9a67bf4a6881809
MD5 5e0d672965b17926821464516dfcf3dd
BLAKE2b-256 2496b5413e21f78d9e477a5a6c327812e74237d6d254ed0b8bd03bbc7acd3b2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sync_with_uv-0.5.0-py3-none-any.whl:

Publisher: build-and-publish.yml on tsvikas/sync-with-uv

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page