diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml deleted file mode 100644 index a8760c3534..0000000000 --- a/.github/workflows/pre-commit.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: pre-commit - -on: - pull_request: - push: - branches: [main] - -jobs: - pre-commit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/prek.yml b/.github/workflows/prek.yml new file mode 100644 index 0000000000..11cc08cffc --- /dev/null +++ b/.github/workflows/prek.yml @@ -0,0 +1,13 @@ +name: prek checks + +on: + pull_request: + push: + branches: [main] + +jobs: + prek: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5.0.0 + - uses: j178/prek-action@v1.0.11 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b3c97d1df2..e7f33ed0e6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v6.0.0" + rev: v6.0.0 hooks: - id: check-added-large-files args: ["--maxkb=1024"] @@ -27,39 +27,47 @@ repos: - id: fix-byte-order-marker - id: mixed-line-ending - id: trailing-whitespace + - repo: https://github.com/asottile/pyupgrade - rev: "v3.21.0" + rev: v3.21.0 hooks: - id: pyupgrade args: [--py312] + - repo: https://github.com/adamchainz/django-upgrade - rev: "1.29.1" + rev: 1.29.1 hooks: - id: django-upgrade args: [--target-version, "5.2"] + - repo: https://github.com/psf/black-pre-commit-mirror rev: 25.9.0 hooks: - id: black + - repo: https://github.com/rbubley/mirrors-prettier - rev: "v3.6.2" + rev: v3.6.2 hooks: - id: prettier exclude_types: [html, json, scss] exclude: '(^djangoproject\/static\/js\/lib\/.*$)' + - repo: https://github.com/pycqa/isort - rev: "7.0.0" + rev: 7.0.0 hooks: - id: isort + - repo: https://github.com/pycqa/flake8 - rev: "7.3.0" + rev: 7.3.0 hooks: - id: flake8 + - repo: https://github.com/rtts/djhtml - rev: "3.0.10" + rev: 3.0.10 hooks: - id: djhtml files: .*/templates/.*\.html$ + - repo: https://github.com/mrtazz/checkmake.git rev: 0.2.2 hooks: diff --git a/README.rst b/README.rst index 6af48d35f6..ae30efa166 100644 --- a/README.rst +++ b/README.rst @@ -370,26 +370,20 @@ Running Locally with Docker 7. View the docs at http://docs.djangoproject.localhost:8000/. -Pre-commit checks ------------------ +git hooks +--------- + `pre-commit `_ is a framework to run hooks written in many languages, and it manages the language toolchain and dependencies for running the hooks. -`pre-commit `_ is a framework for managing pre-commit -hooks. These hooks help to identify simple issues before committing code for -review. By checking for these issues before code review it allows the reviewer -to focus on the change itself, and it can also help to reduce the number of CI -runs. + prek is a reimagined version of pre-commit, built in Rust. It is designed to be a faster, dependency-free and drop-in alternative for it, while also providing some additional long-requested features. -To use the tool, first install ``pre-commit`` and then the git hooks +\- quoted from `prek's README.md `_ -.. code-block:: console +To use git hooks locally, first install ``prek`` and then the git hooks: - $ python3 -m pip install pre-commit - $ python3 -m pre_commit install +* Depending on your choice of platform and tooling, you can use the related installation instructions from https://prek.j178.dev/installation/ +* Install git hooks using ``prek install`` command: https://prek.j178.dev/cli/#prek-install -On the first commit ``pre-commit`` will install the hooks, these are -installed in their own environments and will take a short while to -install on the first run. Subsequent checks will be significantly faster. -If the an error is found an appropriate error message will be displayed. -If the error was with ``isort`` then the tool will go ahead and fix them for -you. Review the changes and re-stage for commit if you are happy with -them. +The installed hooks will be triggered during each commit, or can be manually triggered via +``prek run`` command: https://prek.j178.dev/cli/#prek-run If an error is found an appropriate +error message will be displayed. If the error was with ``isort`` then the tool will go ahead +and fix them for you. Review the changes and re-stage for commit if you are happy with them. diff --git a/requirements/dev.txt b/requirements/dev.txt index efb11df029..2c0ede37f8 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,6 +1,6 @@ -r common.txt black==25.9.0 # Used by Django's find_formatters and run_formatters django-debug-toolbar==6.0.0 -pre-commit~=4.3.0 +prek==0.2.5 psycopg[binary]==3.2.10 watchdog==6.0.0