Skip to content

Commit d78eb34

Browse files
authored
Update pre-commit file and configuration (#3412)
* Update pre-commit file and configuration * test * Update contributing guide * Exclude docs * Update git blame ignore * Migrate pytest settings to pyproject.toml * Skip failing tests on pytorch>=2.8 for nightly builds * Remove bat file * Change test skip to test xfail * Improve contributing guide and remove requirements-check
1 parent ce71692 commit d78eb34

15 files changed

+156
-156
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33

44
# Run pre-commit to fix end-of-file-fixer and trailing-whitespace (#3418)
55
fe5a29b6942829ff2870181b6c1a68ebd2af9add
6+
# Fix code style (#3423)
7+
f9e8ca106a0d3f386f26f3a9481fd2eb341999f0

.github/workflows/code-style.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ on:
77
- "setup.cfg"
88
- "requirements-dev.txt"
99
- "pyproject.toml"
10-
- "tests/run_code_style.sh"
1110
- ".github/workflows/code-style.yml"
1211
- "!assets/**"
1312
- "!docker/**"
1413
- "!docs/**"
1514
- "!conda.recipe"
1615

17-
1816
jobs:
1917
code-style:
2018
runs-on: ubuntu-latest
@@ -25,8 +23,8 @@ jobs:
2523
with:
2624
python-version: "3.11"
2725
- run: |
28-
bash ./tests/run_code_style.sh install
29-
bash ./tests/run_code_style.sh fmt
26+
pip install -r requirements-dev.txt
27+
pre-commit run -a
3028
3129
- name: Commit and push changes
3230
uses: stefanzweifel/git-auto-commit-action@v6

.github/workflows/gpu-hvd-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
- "ignite/**"
66
- "tests/ignite/**"
77
- "tests/run_gpu_tests.sh"
8-
- "tests/run_code_style.sh"
98
- "examples/**.py"
109
- "requirements-dev.txt"
1110
- ".github/workflows/gpu-hvd-tests.yml"

.github/workflows/gpu-tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
- "ignite/**"
66
- "tests/ignite/**"
77
- "tests/run_gpu_tests.sh"
8-
- "tests/run_code_style.sh"
98
- "examples/**.py"
109
- "requirements-dev.txt"
1110
- ".github/workflows/gpu-tests.yml"

.github/workflows/mps-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ on:
77
paths:
88
- "ignite/**"
99
- "tests/ignite/**"
10-
- "tests/run_code_style.sh"
1110
- "examples/**.py"
1211
- "requirements-dev.txt"
1312
- ".github/workflows/mps-tests.yml"
1413
pull_request:
1514
paths:
1615
- "ignite/**"
1716
- "tests/ignite/**"
18-
- "tests/run_code_style.sh"
1917
- "examples/**.py"
2018
- "requirements-dev.txt"
2119
- ".github/workflows/mps-tests.yml"

.github/workflows/tpu-tests.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ on:
88
- "ignite/**"
99
- "tests/ignite/**"
1010
- "tests/run_tpu_tests.sh"
11-
- "tests/run_code_style.sh"
1211
- "requirements-dev.txt"
1312
- ".github/workflows/tpu-tests.yml"
1413
pull_request:
1514
paths:
1615
- "ignite/**"
1716
- "tests/ignite/**"
1817
- "tests/run_tpu_tests.sh"
19-
- "tests/run_code_style.sh"
2018
- "requirements-dev.txt"
2119
- ".github/workflows/tpu-tests.yml"
2220
workflow_dispatch:

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,14 @@ jobs:
100100
101101
- name: Check code formatting
102102
run: |
103-
bash ./tests/run_code_style.sh install
104-
bash ./tests/run_code_style.sh lint
103+
pre-commit run -a
105104
106105
- name: Run Mypy
107106
# https://github.com/pytorch/ignite/pull/2780
108107
#
109108
if: ${{ matrix.os == 'ubuntu-latest' }}
110109
run: |
111-
bash ./tests/run_code_style.sh mypy
110+
mypy
112111
113112
# Download MNIST: https://github.com/pytorch/ignite/issues/1737
114113
# to "/tmp" for unit tests

.pre-commit-config.yaml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
exclude: "^conda.recipe"
1+
exclude: "^conda.recipe|assets|docs"
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v3.4.0
4+
rev: v5.0.0
55
hooks:
66
- id: check-toml
77
- id: check-yaml
@@ -14,16 +14,18 @@ repos:
1414
- id: prettier
1515
exclude_types: ["python", "jupyter", "shell", "gitignore"]
1616

17-
- repo: https://github.com/omnilib/ufmt
18-
rev: v2.7.3
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.11.13
1919
hooks:
20-
- id: ufmt
21-
additional_dependencies:
22-
- black == 24.10.0
23-
- usort == 1.0.8.post1
20+
# Run the linter
21+
- id: ruff-check
22+
types_or: [python, pyi]
23+
# TODO: Enable when black and ruff format converge
24+
# Run the formatter
25+
# - id: ruff-format
26+
# types_or: [python, pyi]
2427

25-
- repo: https://github.com/pycqa/flake8
26-
rev: 7.1.1
28+
- repo: https://github.com/psf/black
29+
rev: 24.10.0
2730
hooks:
28-
- id: flake8
29-
args: ["--config", "setup.cfg"]
31+
- id: black

CONTRIBUTING.md

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ into the following categories:
3535
- [Installation](#installation)
3636
- [Code development](#code-development)
3737
- [Codebase structure](#codebase-structure)
38-
- [Formatting Code](#formatting-code)
39-
- [Formatting without pre-commit](#formatting-without-pre-commit)
40-
- [Formatting with pre-commit](#formatting-with-pre-commit)
38+
- [Checking Code Style](#checking-code-style)
39+
- [Formatting the code](#formatting-the-code)
40+
- [Formatting the code with a pre-commit hook](#formatting-the-code-with-a-pre-commit-hook)
4141
- [Run tests](#run-tests)
4242
- [Run distributed tests only on CPU](#run-distributed-tests-only-on-cpu)
4343
- [Run Mypy checks](#run-mypy-checks)
@@ -80,31 +80,33 @@ conda activate pytorch-ignite-dev
8080

8181
### Installation
8282

83-
1) Make a fork of the repository on the GitHub (see [here](https://github.com/firstcontributions/first-contributions#fork-this-repository) for details).
84-
As a result, for example your username is `happy-ignite-developer`, then you should be able to see your fork on the GitHub, e.g https://github.com/happy-ignite-developer/ignite.git
83+
1. Make a fork of the repository on the GitHub (see [here](https://github.com/firstcontributions/first-contributions#fork-this-repository) for details).
84+
As a result, for example your username is `happy-ignite-developer`, then you should be able to see your fork on the GitHub, e.g https://github.com/happy-ignite-developer/ignite.git
8585

86-
2) Clone your fork locally and setup `upstream`. Assuming your username is `happy-ignite-developer`:
86+
2. Clone your fork locally and setup `upstream`. Assuming your username is `happy-ignite-developer`:
8787

8888
```bash
8989
git clone https://github.com/happy-ignite-developer/ignite.git
9090
cd ignite
9191
git remote add upstream https://github.com/pytorch/ignite.git
9292
git remote -v
9393
```
94+
9495
You might see the following output:
96+
9597
```
9698
origin https://github.com/happy-ignite-developer/ignite.git (fetch)
9799
origin https://github.com/happy-ignite-developer/ignite.git (push)
98100
upstream https://github.com/pytorch/ignite (fetch)
99101
upstream https://github.com/pytorch/ignite (push)
100102
```
101-
3) Sync and install all necessary dependencies:
103+
104+
3. Sync and install all necessary dependencies:
102105

103106
```bash
104107
git pull upstream master
105108
pip install -e .
106109
pip install -r requirements-dev.txt
107-
bash ./tests/run_code_style.sh install
108110
```
109111

110112
### Code development
@@ -136,48 +138,39 @@ If you modify the code, you will most probably also need to code some tests to e
136138
New code should be compatible with Python 3.X versions. Once you finish implementing a feature or bugfix and tests,
137139
please run lint checking and tests:
138140

139-
#### Formatting Code
141+
#### Checking Code Style
140142

141-
To ensure the codebase complies with a style guide, we use [flake8](https://flake8.pycqa.org/en/latest/)
142-
and [ufmt](https://ufmt.omnilib.dev/) ([black](https://black.readthedocs.io/en/stable/) and
143-
[usort](https://usort.readthedocs.io/en/stable/)) to format and check codebase for compliance with PEP8.
143+
To ensure the codebase complies with the PEP8 style guide, we use [ruff](https://docs.astral.sh/ruff/)
144+
and [black](https://black.readthedocs.io/en/stable/) to lint and format the codebase respectively.
144145

145-
##### Formatting without pre-commit
146+
##### Formatting the code
146147

147-
If you choose not to use pre-commit, you can take advantage of IDE extensions configured to black format or invoke
148-
black manually to format files and commit them.
149-
150-
To install `flake8`, `ufmt` and `mypy`, please run
151-
152-
```bash
153-
bash ./tests/run_code_style.sh install
154-
```
148+
To automate the process, we have configured the repo with [pre-commit](https://pre-commit.com/).
155149

156150
To format files and commit changes:
157151

158152
```bash
159-
# This should autoformat the files
160-
bash ./tests/run_code_style.sh fmt
153+
# This should lint and autoformat the files
154+
pre-commit -a
161155
# If everything is OK, then commit
162156
git add .
163157
git commit -m "Added awesome feature"
164158
```
165159

166-
##### Formatting with pre-commit
160+
##### Formatting the code with a pre-commit hook
167161

168-
To automate the process, we have configured the repo with [pre-commit hooks](https://pre-commit.com/) to use µfmt to autoformat the staged files to ensure every commit complies with a style guide. This requires some setup, which is described below:
162+
To enable the `pre-commit` hooks follow the steps described below:
169163

170-
1. Install pre-commit in your python environment.
171-
2. Run pre-commit install that configures a virtual environment to invoke ufmt and flake8 on commits.
164+
1. Run `pre-commit install` to configures a virtual environment to invoke linters and formatters on commits.
172165

173166
```bash
174167
pip install pre-commit
175168
pre-commit install
176169
```
177170

178-
3. When files are committed:
179-
- If the stages files are not compliant with black or µsort, µfmt will autoformat the staged files. If this were to happen, files should be staged and committed again. See example code below.
180-
- If the staged files are not compliant with flake8, errors will be raised. These errors should be fixed and the files should be committed again. See example code below.
171+
2. When files are committed:
172+
- If the stages files are not compliant, the tools autoformat the staged files. If this were to happen, files should be staged and committed again. See example code below.
173+
- If the staged files are not compliant errors will be raised. These errors should be fixed and the files should be committed again. See example code below.
181174

182175
```bash
183176
git add .
@@ -226,7 +219,7 @@ CUDA_VISIBLE_DEVICES="" pytest --dist=each --tx $WORLD_SIZE*popen//python=python
226219
To run mypy to check the optional static type:
227220

228221
```bash
229-
bash ./tests/run_code_style.sh mypy
222+
mypy
230223
```
231224

232225
To change any config for specif folder, please see the file mypy.ini
@@ -292,9 +285,7 @@ for formatting docstrings, specially from an example of `Google style with Pytho
292285
- [`.. versionchanged::`] directive for adding new arguments, changing internal behaviours, fixing bugs and
293286
- [`.. deprecated::`] directive for deprecations.
294287

295-
Examples: ``versionadded`` usage [link](https://github.com/pytorch/ignite/blob/52c69251dd9d97c32da1df0477ec3854e5702029/ignite/handlers/state_param_scheduler.py#L24), ``versionchanged`` usage [link](https://github.com/pytorch/ignite/blob/d2020e4e253ac1455a757c2db895c68ccfd2b958/ignite/metrics/metric.py#L281-L282)
296-
297-
288+
Examples: `versionadded` usage [link](https://github.com/pytorch/ignite/blob/52c69251dd9d97c32da1df0477ec3854e5702029/ignite/handlers/state_param_scheduler.py#L24), `versionchanged` usage [link](https://github.com/pytorch/ignite/blob/d2020e4e253ac1455a757c2db895c68ccfd2b958/ignite/metrics/metric.py#L281-L282)
298289

299290
Length of line inside docstrings block must be limited to 120 characters.
300291

0 commit comments

Comments
 (0)