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.

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

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[pdm]""

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[pdm]"
]

We add the extra group [pdm] to the plugin name, to make sure version constraints are met.

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.

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 / Dev

  • Upload build artifacts on GitHub release
  • Add a changelog
  • Add "E2E" tests
  • Add PDM scripts for dev and CI
  • Add docs

Features or fixes

  • Create a more verbose command
  • Add support for other lockfiles / project managers (pipenv, flit, hatch, etc.)
  • Add a PDM/Poetry CLI command to sync manually
  • Add a dedicated CLI command to manage sync/install
  • 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?
  • Support multiple hooks repos for the same dependency? E.g. ruff new and old repo
  • 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.3.0.tar.gz (47.9 kB view hashes)

Uploaded Source

Built Distribution

sync_pre_commit_lock-0.3.0-py3-none-any.whl (39.7 kB view hashes)

Uploaded Python 3

Supported by

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