diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 78f7227df24..a90a3c9d911 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -38,7 +38,7 @@ jobs: # Install formatting tools - name: Install formatting tools run: | - python -m pip install ruff pre-commit + python -m pip install ruff prek python -m pip list # Run "make format" and commit the change to the PR branch diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 9f1f698c0f4..9ae2f11aac3 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -38,13 +38,13 @@ jobs: - name: Install packages run: | - python -m pip install ruff pre-commit + python -m pip install ruff prek python -m pip list - - name: Formatting check (ruff + pre-commit) + - name: Formatting check (ruff + prek) run: | make check - pre-commit run --all-files + prek run --all-files - name: Ensure example scripts have at least one code block separator run: | diff --git a/Makefile b/Makefile index 2dd8243f95d..df373dd8ef0 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ test_no_images: _runtest format: ruff check --fix --exit-zero $(FORMAT_FILES) ruff format $(FORMAT_FILES) - pre-commit run --all-files + prek run --all-files check: ruff check $(FORMAT_FILES) diff --git a/doc/contributing.md b/doc/contributing.md index 36b0d76e984..b52879b5d91 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -481,10 +481,10 @@ the code yourself. Before committing, run it to automatically format your code: make format ``` -For consistency, we also use `pre-commit` hooks to enforce UNIX-style line endings -(`\n`) and file permission 644 (`-rw-r--r--`) throughout the whole project. -Don't worry if you forget to do it. Our continuous integration systems will -warn us and you can make a new commit with the formatted code. +For consistency, we also use `pre-commit` hooks (via [`prek`](https://prek.j178.dev/)) +to enforce UNIX-style line endings (`\n`) and file permission 644 (`-rw-r--r--`) +throughout the whole project. Don't worry if you forget to do it. Our continuous +integration systems will warn us and you can make a new commit with the formatted code. Even better, you can just write `/format` in the first line of any comment in a pull request to lint the code automatically. diff --git a/environment.yml b/environment.yml index f9fbe025aac..7cde2e70015 100644 --- a/environment.yml +++ b/environment.yml @@ -25,7 +25,7 @@ dependencies: - python-build # Dev dependencies (style checks) - codespell - - pre-commit + - prek - ruff>=0.12.0 # Dev dependencies (unit testing) - matplotlib-base