Skip to main content

Simple CLI tool to check and update pre-commit hooks.

Project description

pre-commit-update

Version Downloads Formatter License

pre-commit-update is a simple CLI tool to check and update pre-commit hooks.

Table of contents

  1. Reasoning
  2. Installation
  3. Usage
    1. Pipeline usage example
    2. pre-commit hook usage example

1. Reasoning

pre-commit is a nice little tool that helps you polish your code before releasing it into the wild. It is fairly easy to use. A single pre-commit-config.yaml file can hold multiple hooks (checks) that will go through your code or repository and do certain checks. The trick is that file is static and once you pin your hook versions after a while they get outdated.

pre-commit has a CLI that helps with that by making use of pre-commit autoupdate command so the question is why the f* are you reading this?

pre-commit-update was created mostly because there is no easy way to update your hooks by using pre-commit autoupdate and avoiding non-stable (alpha, beta, ...) hook versions. pre-commit-update comes with a CLI that can be configured to solve that problem - along with other use cases.

Other than that - I was bored ^^

2. Installation

pre-commit-update is available on PyPI:

$ python -m pip install pre-commit-update

Python >= 3.7 is supported.

NOTE: Please make sure that git is installed.

3. Usage

pre-commit-update CLI can be used as below:

Usage: pre-commit-update [OPTIONS]

Options:
  -d, --dry-run       Dry run only checks for the new versions without
                      updating
  -a, --all-versions  Include the alpha/beta versions when updating
  -v, --verbose       Display the complete output
  -e, --exclude TEXT  Exclude specific repo(s) by the `repo` url trim
  -k, --keep TEXT     Keep the version of specific repo(s) by the `repo` url trim (still checks for the new versions)
  -h, --help          Show this message and exit.

If you want to just check for updates (without updating pre-commit-config.yaml), for example, you would use:

pre-commit-update -d
OR
pre-commit-update --dry-run

NOTE: If you are to use the exclude or keep options, please pass the repo url trim as a parameter. Keep in mind that if you have multiple hooks (id's) configured for a single repo and you exclude that repo, NONE of the hooks will be updated, whole repo will be excluded.

Example of repo url trim: https://github.com/ambv/black -> black (you will only pass black as a parameter to exclude or keep)

Pipeline usage example

GitLab job:

pre-commit-hooks-update:
  stage: update
  script:
    # install git if not present in the image
    - pip install pre-commit-update
    - pre-commit-update --dry-run
  except:
    - main
  when: manual
  allow_failure: true

NOTE: This is just an example, feel free to do your own configuration

pre-commit hook usage example

You can also use pre-commit-update as a hook in your pre-commit hooks:

- repo: local
  hooks:
    - id: pre-commit-update
      entry: pre-commit-update
      language: python
      name: pre-commit-update
      pass_filenames: false
      args: [--dry-run --exclude black --exclude isort]

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

pre_commit_update-0.0.7.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

pre_commit_update-0.0.7-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pre_commit_update-0.0.7.tar.gz.

File metadata

  • Download URL: pre_commit_update-0.0.7.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.3 Linux/6.2.12-1-MANJARO

File hashes

Hashes for pre_commit_update-0.0.7.tar.gz
Algorithm Hash digest
SHA256 52cae4a3fb16ec50bbf84c12165610d002d7afb1e098082fba79dc65b2419b6b
MD5 93a92c580fc75ae9055f12cf76222d41
BLAKE2b-256 14a102be5b7e9b3b387204a90a6cf26662b5c4e3d32e21f5e683f97153c7977a

See more details on using hashes here.

File details

Details for the file pre_commit_update-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: pre_commit_update-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.3 Linux/6.2.12-1-MANJARO

File hashes

Hashes for pre_commit_update-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 097291b7fb2f71d0b90893a41f52510cab0fe14420fc554ce4c169677e2c684b
MD5 247cb15e257d846892a7bef00c5cb5e4
BLAKE2b-256 4c251f56404843bb5bf22af7eba38ab1537f8687da50f07cd6f05fbd25da80a4

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