Skip to main content

PDM plugin to sync your pre-commit versions with your lockfile, and install them, all automatically.

Project description

sync-pre-commit-lock

Tests pre-commit.ci status OpenSSF Best Practices pypi version License Python version pdm-managed Ruff Code style: black

PDM and Poetry plugin to sync your pre-commit versions with your lockfile and automatically install pre-commit hooks.

Sample output

Features

  • 🔁 Sync pre-commit versions with your lockfile
  • ⏩ Run every time you run the lockfile is updated, not as a pre-commit hook
  • 🔄 Install pre-commit hooks automatically, no need to run pre-commit install manually
  • 💫 Preserve your pre-commit config file formatting
  • 🍃 Lightweight, only depends on strictyaml

Supported versions

  • Python 3.10+
  • PDM 2.7.4+
  • Poetry 1.6.0+

Installation

For PDM

Install it just like any other PDM plugin:

pdm self add "sync-pre-commit-lock"

Optionally, you can also specify the plugin in your project pyproject.toml, to make it installable with pdm install --plugins:

[tool.pdm]
plugins = [
    "sync-pre-commit-lock"
]

Note: we have an extra group [pdm], that adds PDM version constraints. While it's safer, it might result in PDM being installed twice.

For Poetry

Install like any other Poetry plugin, e.g.:

poetry self plugin add "sync-pre-commit-lock[poetry]"

Only Poetry 1.6.0+ is supported.

Configuration

This plugin is configured using the tool.sync-pre-commit-lock section in your pyproject.toml file.

Here is the default configuration:

[tool.sync-pre-commit-lock]
# Run `pre-commit install` automatically if applicable
automaticall-install-hooks = true
# Should we sync your pre-commit versions with your lockfile (when running lock, add, update, remove, etc.)?
disable-sync-from-lock = false
# Packages to ignore when syncing from lock
ignore = []
# Name of the pre-commit config file to sync with
pre-commit-config-file = ".pre-commit-config.yaml"
# Additional mapping of URLs to python packages
# Default is empty, but will merge with the default mapping
# "rev" indicates the format of the Git tags
dependency-mapping = {"package-name"= {"repo"= "https://github.com/example/package-name", "rev"= "v${rev}"}}

Note: the dependency-mapping is merged with the default mapping, so you don't need to specify the default mapping if you want to add a new mapping. Repos urls will be normalized to http(s), with the trailing slash removed.

From environment

Some settings are overridable by environment variables with the following SYNC_PRE_COMMIT_LOCK_* prefixed environment variables:

toml setting environment format
automatically-install-hooks SYNC_PRE_COMMIT_LOCK_INSTALL bool as string (true, 1...)
disable-sync-from-lock SYNC_PRE_COMMIT_LOCK_DISABLED bool as string (true, 1...)
ignore SYNC_PRE_COMMIT_LOCK_IGNORE comma-separated list
pre-commit-config-file SYNC_PRE_COMMIT_LOCK_PRE_COMMIT_FILE str

Usage

Once installed, and optionally configured, the plugin usage should be transparent, and trigger when you run applicable PDM or Poetry commands, like pdm lock, or poetry lock.

There should be a message in the output, when the sync or install or pre-commit is triggered.

You can manually trigger the sync with the CLI command:

pdm sync-pre-commit

or

poetry sync-pre-commit

Both commands support --dry-run and verbosity options.

Improvement ideas

Feel free to open an issue or a PR if you have any idea, or if you want to help!

Release / CI / DX

  • Upload build artifacts on GitHub release
  • Add a changelog
  • Add "E2E" tests
  • Add docs

Features or fixes

  • Support hooks URL aliases for the same Python package
    • Support user configuration of aliases
  • Support pdm config and clear configuration precedence
  • Create a more verbose command
  • Add support for other lockfiles / project managers (pipenv, flit, hatch, etc.)
  • Expose a pre-commit hook to sync the lockfile
  • Support nested params for some repos? Like mypy types
  • Support reading DB from a Python module?
  • Support reordering DB inputs (file/global config/python module/cli)?
  • Test using SSH/file dependencies?
  • Check ref existence before writing?
  • New feature to convert from pre-commit online to local?
  • Warning if pre-commit CI auto update is also set?

Inspiration

This project is inspired by @floatingpurr's sync_with_pdm and sync_with_poetry.

The code to install pre-commit hooks automatically is adapted from @vstrimaitis's poetry-pre-commit-plugin, licensed under GPL-3.

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_pre_commit_lock-0.5.1rc4.tar.gz (50.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_pre_commit_lock-0.5.1rc4-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

Details for the file sync_pre_commit_lock-0.5.1rc4.tar.gz.

File metadata

  • Download URL: sync_pre_commit_lock-0.5.1rc4.tar.gz
  • Upload date:
  • Size: 50.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.11.1 CPython/3.10.12

File hashes

Hashes for sync_pre_commit_lock-0.5.1rc4.tar.gz
Algorithm Hash digest
SHA256 b75f4c3f518d61b62fb40f0e10295872c4863993cd225936f0f49be49284e951
MD5 0a8aea875d04677c27a9827ba17ca934
BLAKE2b-256 9c68912dffdd6e8ada1d27fa20fa083cde6b1ca6f58b78df74219a37236a226d

See more details on using hashes here.

File details

Details for the file sync_pre_commit_lock-0.5.1rc4-py3-none-any.whl.

File metadata

File hashes

Hashes for sync_pre_commit_lock-0.5.1rc4-py3-none-any.whl
Algorithm Hash digest
SHA256 bb14daa8ce03ed67d7cf41e8b169b8052b080963d7e049b12838446e826dd157
MD5 72d780e915aaebf5c013591ca62aa7c2
BLAKE2b-256 4ab89f1ab842cef96f92f34b45acffd750b4947ed35fbf2e67e1aa92b20cc705

See more details on using hashes here.

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