From 69fb6df78bc47fd0c8e96cb7de144d34eccdb799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Sat, 11 Oct 2025 23:48:50 +0300 Subject: [PATCH 1/3] Migrate to prek # Conflicts: # README.rst --- .github/workflows/pre-commit.yml | 16 ---------------- .github/workflows/prek.yml | 13 +++++++++++++ README.rst | 30 ++++++++++++------------------ requirements/dev.txt | 2 +- 4 files changed, 26 insertions(+), 35 deletions(-) delete mode 100644 .github/workflows/pre-commit.yml create mode 100644 .github/workflows/prek.yml 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/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 From 12f898be94d61859482d83a37de6b933a6222842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Mon, 3 Nov 2025 02:14:50 +0300 Subject: [PATCH 2/3] Reformat version strings with "prek autoupdate" --- .pre-commit-config.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b3c97d1df2..95fa16d7b8 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"] @@ -28,12 +28,12 @@ repos: - 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"] @@ -42,21 +42,21 @@ repos: 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$ From 7f22ce6990f86b080d93c583a6f2b04324a4e29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Clgen=20Sar=C4=B1kavak?= Date: Mon, 3 Nov 2025 02:17:40 +0300 Subject: [PATCH 3/3] Add whitespaces to improve readability --- .pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 95fa16d7b8..e7f33ed0e6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 hooks: - id: pyupgrade args: [--py312] + - repo: https://github.com/adamchainz/django-upgrade 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 hooks: - id: prettier exclude_types: [html, json, scss] exclude: '(^djangoproject\/static\/js\/lib\/.*$)' + - repo: https://github.com/pycqa/isort rev: 7.0.0 hooks: - id: isort + - repo: https://github.com/pycqa/flake8 rev: 7.3.0 hooks: - id: flake8 + - repo: https://github.com/rtts/djhtml rev: 3.0.10 hooks: - id: djhtml files: .*/templates/.*\.html$ + - repo: https://github.com/mrtazz/checkmake.git rev: 0.2.2 hooks: