{"id":13764344,"url":"https://github.com/GabDug/sync-pre-commit-lock","last_synced_at":"2025-05-10T19:30:51.983Z","repository":{"id":178130678,"uuid":"660338127","full_name":"GabDug/sync-pre-commit-lock","owner":"GabDug","description":"Automatically sync your pre-commit hooks version from your PDM or Poetry lockfile, and install them automatically.","archived":false,"fork":false,"pushed_at":"2025-05-10T12:16:30.000Z","size":713,"stargazers_count":28,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-10T13:26:33.827Z","etag":null,"topics":["pdm-plugin","poetry-plugin","pre-commit","pre-commit-config","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GabDug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-29T19:31:59.000Z","updated_at":"2025-04-19T10:58:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"800aadba-13ca-48c5-a9ef-5a0f9ce19508","html_url":"https://github.com/GabDug/sync-pre-commit-lock","commit_stats":null,"previous_names":["gabdug/sync-pre-commit-lock"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabDug%2Fsync-pre-commit-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabDug%2Fsync-pre-commit-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabDug%2Fsync-pre-commit-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabDug%2Fsync-pre-commit-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GabDug","download_url":"https://codeload.github.com/GabDug/sync-pre-commit-lock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253422039,"owners_count":21905854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pdm-plugin","poetry-plugin","pre-commit","pre-commit-config","python"],"created_at":"2024-08-03T16:00:19.264Z","updated_at":"2025-05-10T19:30:51.972Z","avatar_url":"https://github.com/GabDug.png","language":"Python","readme":"# sync-pre-commit-lock\n\n[![Tests](https://github.com/GabDug/sync-pre-commit-lock/actions/workflows/ci.yml/badge.svg)](https://github.com/GabDug/sync-pre-commit-lock/actions/workflows/ci.yml)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/GabDug/sync-pre-commit-lock/main.svg)](https://results.pre-commit.ci/latest/github/GabDug/sync-pre-commit-lock/main)\n[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7529/badge)](https://bestpractices.coreinfrastructure.org/projects/7529)\n[![pypi version](https://img.shields.io/pypi/v/sync-pre-commit-lock.svg)](https://pypi.org/project/sync-pre-commit-lock/)\n[![License](https://img.shields.io/pypi/l/sync-pre-commit-lock.svg)](https://pypi.python.org/pypi/sync-pre-commit-lock)\n[![Python version](https://img.shields.io/pypi/pyversions/sync-pre-commit-lock.svg)](https://pypi.python.org/pypi/sync-pre-commit-lock)\n[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev)\n[![Ruff](https://img.shields.io/badge/ruff-lint-red)](https://github.com/charliermarsh/ruff)\n\nPDM and Poetry plugin to sync your pre-commit versions with your lockfile and automatically install pre-commit hooks.\n\n![Sample output](.github/sample_command.png)\n\n## Features\n\n- 🔁 Sync pre-commit versions (including `additional_dependencies`) with your lockfile\n- ⏩ Run every time you run the lockfile is updated, not as a pre-commit hook\n- 🔄 Install pre-commit hooks automatically, no need to run `pre-commit install` manually\n- 💫 Preserve your pre-commit config file formatting\n- 🍃 Lightweight, only depends on [strictyaml](https://pypi.org/project/strictyaml/) and [packaging](https://pypi.org/project/packaging/)\n\n## Supported versions\n\n- Python 3.9+ to 3.13+\n- PDM 2.7.4 to 2.24+\n  - Python 3.12.7+ requires PDM 2.20.1+\n- Poetry 1.6 to 2.1+\n\n\u003e ℹ️ While we only test these versions, it should work with more recent versions.\n\u003e\n\u003e ⚠️ Only the latest patch version for each minor version is tested.\n\u003e\n\u003e 👉 We recommend using a recent version of Python, and a recent version of PDM/Poetry.\n\n## Installation\n\n### For PDM\n\nInstall it [just like any other PDM plugin](https://pdm.fming.dev/latest/dev/write/#activate-the-plugin):\n\n```bash\npdm self add \"sync-pre-commit-lock\"\n```\n\nOptionally, you can also specify [the plugin in your project](https://pdm.fming.dev/latest/dev/write/#specify-the-plugins-in-project) `pyproject.toml`, to make it installable with `pdm install --plugins`:\n\n```toml\n[tool.pdm]\nplugins = [\n    \"sync-pre-commit-lock\"\n]\n```\n\n\u003e Note: we have an extra group `[pdm]`, that adds PDM version constraints.\n\u003e While it's safer, it might result in PDM being installed twice.\n\n### For Poetry\n\nInstall [like any other Poetry plugin](https://python-poetry.org/docs/plugins/#using-plugins), e.g.:\n\n```bash\npoetry self add \"sync-pre-commit-lock[poetry]\"\n```\n\n\u003e Only Poetry 1.6.0+ is supported.\n\n## Configuration\n\nThis plugin is configured using the `tool.sync-pre-commit-lock` section in your `pyproject.toml` file.\n\nHere is the default configuration:\n\n```toml\n[tool.sync-pre-commit-lock]\n# Run `pre-commit install` automatically if applicable\nautomatically-install-hooks = true\n# Should we sync your pre-commit versions with your lockfile (when running lock, add, update, remove, etc.)?\ndisable-sync-from-lock = false\n# Packages to ignore when syncing from lock\nignore = []\n# Name of the pre-commit config file to sync with\npre-commit-config-file = \".pre-commit-config.yaml\"\n# Additional mapping of URLs to python packages\n# Default is empty, but will merge with the default mapping\n# \"rev\" indicates the format of the Git tags\ndependency-mapping = {\"package-name\"= {\"repo\"= \"https://github.com/example/package-name\", \"rev\"= \"v${rev}\"}}\n```\n\n\u003e 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.\n\u003e Repos urls will be normalized to http(s), with the trailing slash removed.\n\n### From environment\n\nSome settings are overridable by environment variables with the following `SYNC_PRE_COMMIT_LOCK_*` prefixed environment variables:\n\n| `toml` setting                | environment                            | format                            |\n| ------------------------------|----------------------------------------|-----------------------------------|\n| `automatically-install-hooks` | `SYNC_PRE_COMMIT_LOCK_INSTALL`         | `bool` as string (`true`, `1`...) |\n| `disable-sync-from-lock`      | `SYNC_PRE_COMMIT_LOCK_DISABLED`        | `bool` as string (`true`, `1`...) |\n| `ignore`                      | `SYNC_PRE_COMMIT_LOCK_IGNORE`          | comma-separated list              |\n| `pre-commit-config-file`      | `SYNC_PRE_COMMIT_LOCK_PRE_COMMIT_FILE` | `str`                             |\n\n## Usage\n\nOnce 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`.\n\n\u003e There should be a message in the output, when the sync or install or pre-commit is triggered.\n\nYou can manually trigger the sync with the CLI command:\n\n```bash\npdm sync-pre-commit\n```\n\nor\n\n```bash\npoetry sync-pre-commit\n```\n\nBoth commands support `--dry-run` and verbosity options.\n\n### PDM Github Action support\n\nIf you use [pdm-project/update-deps-actions](https://github.com/pdm-project/update-deps-action) Github Action, you can get automatically update `your .pre-commit-config.yaml` file by adding the plugin in your `pyproject.toml` and setting a flag in your workflow:\n\n```yaml\n# In your workflow\n      - name: Update dependencies\n        uses: pdm-project/update-deps-action@main\n        with:\n          # Whether to install PDM plugins before update (defaults to \"false\")\n          install-plugins: \"true\"\n```\n\n```toml\n# In your pyproject.toml\n[tool.pdm]\nplugins = [\"sync-pre-commit-lock\"]\n```\n\n## Supported packages for pre-commits\n\nHere is the list of default packages supported by this plugin, from [`db.py`](https://github.com/GabDug/sync-pre-commit-lock/blob/main/src/sync_pre_commit_lock/db.py). You can add more packages using the `dependency-mapping` configuration.\n\n\u003c!-- GENERATED-PACKAGES-LIST --\u003e\n\u003c!-- @generated by scripts/db_md.py --\u003e\n- [autopep8](https://github.com/hhatto/autopep8)\n- [bandit](https://github.com/PyCQA/bandit)\n- [black](https://github.com/psf/black-pre-commit-mirror)\n- [check-jsonschema](https://github.com/python-jsonschema/check-jsonschema)\n- [codespell](https://github.com/codespell-project/codespell)\n- [commitizen](https://github.com/commitizen-tools/commitizen)\n- [djade](https://github.com/adamchainz/djade-pre-commit)\n- [djhtml](https://github.com/rtts/djhtml)\n- [docformatter](https://github.com/PyCQA/docformatter)\n- [flake8](https://github.com/pycqa/flake8)\n- [flakeheaven](https://github.com/flakeheaven/flakeheaven)\n- [isort](https://github.com/pycqa/isort)\n- [mypy](https://github.com/pre-commit/mirrors-mypy)\n- [pdm](https://github.com/pdm-project/pdm)\n- [poetry](https://github.com/python-poetry/poetry)\n- [pycln](https://github.com/hadialqattan/pycln)\n- [pyroma](https://github.com/regebro/pyroma)\n- [pyupgrade](https://github.com/asottile/pyupgrade)\n- [rtscheck](https://github.com/rstcheck/rstcheck)\n- [ruff](https://github.com/astral-sh/ruff-pre-commit)\n- [yamllint](https://github.com/adrienverge/yamllint)\n\u003c!-- END-GENERATED-PACKAGES-LIST --\u003e\n\n\u003e Note: `pdm` or `poetry` version will be added, from the current instance version, and not from the lockfile.\n\n## Improvement ideas\n\nFeel free to open an issue or a PR if you have any idea, or if you want to help!\n\n### Release / CI / DX\n\n- [ ] Add a changelog\n- [ ] Add \"E2E\" tests\n- [ ] Add docs\n\n### Features or fixes\n\n- [X] Support hooks URL aliases for the same Python package\n  - [ ] Support user configuration of aliases\n- [ ] Support `pdm config` and clear configuration precedence\n- [ ] Create a more verbose command\n- [ ] Add support for other lockfiles / project managers (pipenv, flit, hatch, etc.)\n- [ ] Expose a pre-commit hook to sync the lockfile\n- [x] Support nested `additional_dependencies`, (i.e. mypy types)\n- [ ] Support reading DB from a Python module?\n- [ ] Support reordering DB inputs (file/global config/python module/cli)?\n- [ ] Test using SSH/file dependencies?\n- [ ] Check ref existence before writing?\n- [ ] New feature to convert from pre-commit online to local?\n- [ ] Warning if pre-commit CI auto update is also set?\n- [x] Support automatic repository URL update (from legacy aliased repositories)\n\n\n## Inspiration\n\nThis project is inspired by @floatingpurr's [sync_with_pdm](https://github.com/floatingpurr/sync_with_pdm/) and [sync_with_poetry](https://github.com/floatingpurr/sync_with_poetry/).\n\nThe code to install pre-commit hooks automatically is **adapted** from @vstrimaitis's [poetry-pre-commit-plugin](https://github.com/vstrimaitis/poetry-pre-commit-plugin/), licensed under GPL-3.\n","funding_links":[],"categories":["Plugins"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGabDug%2Fsync-pre-commit-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGabDug%2Fsync-pre-commit-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGabDug%2Fsync-pre-commit-lock/lists"}