Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

# Run pre-commit to fix end-of-file-fixer and trailing-whitespace (#3418)
fe5a29b6942829ff2870181b6c1a68ebd2af9add
# Fix code style (#3423)
f9e8ca106a0d3f386f26f3a9481fd2eb341999f0
6 changes: 2 additions & 4 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ on:
- "setup.cfg"
- "requirements-dev.txt"
- "pyproject.toml"
- "tests/run_code_style.sh"
- ".github/workflows/code-style.yml"
- "!assets/**"
- "!docker/**"
- "!docs/**"
- "!conda.recipe"


jobs:
code-style:
runs-on: ubuntu-latest
Expand All @@ -25,8 +23,8 @@ jobs:
with:
python-version: "3.11"
- run: |
bash ./tests/run_code_style.sh install
bash ./tests/run_code_style.sh fmt
pip install -r requirements-check.txt
pre-commit run -a

- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v6
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/gpu-hvd-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_gpu_tests.sh"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/gpu-hvd-tests.yml"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/gpu-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_gpu_tests.sh"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/gpu-tests.yml"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/mps-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ on:
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/mps-tests.yml"
pull_request:
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/mps-tests.yml"
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/tpu-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ on:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_tpu_tests.sh"
- "tests/run_code_style.sh"
- "requirements-dev.txt"
- ".github/workflows/tpu-tests.yml"
pull_request:
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_tpu_tests.sh"
- "tests/run_code_style.sh"
- "requirements-dev.txt"
- ".github/workflows/tpu-tests.yml"
workflow_dispatch:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ jobs:

- name: Check code formatting
run: |
bash ./tests/run_code_style.sh install
bash ./tests/run_code_style.sh lint
pip install -r requirements-check.txt
pre-commit run -a

- name: Run Mypy
# https://github.com/pytorch/ignite/pull/2780
#
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
bash ./tests/run_code_style.sh mypy
mypy

# Download MNIST: https://github.com/pytorch/ignite/issues/1737
# to "/tmp" for unit tests
Expand Down
26 changes: 14 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: "^conda.recipe"
exclude: "^conda.recipe|assets|docs"
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v5.0.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -14,16 +14,18 @@ repos:
- id: prettier
exclude_types: ["python", "jupyter", "shell", "gitignore"]

- repo: https://github.com/omnilib/ufmt
rev: v2.7.3
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.13
hooks:
- id: ufmt
additional_dependencies:
- black == 24.10.0
- usort == 1.0.8.post1
# Run the linter
- id: ruff-check
types_or: [python, pyi]
# TODO: Enable when black and ruff format converge
# Run the formatter
# - id: ruff-format
# types_or: [python, pyi]

- repo: https://github.com/pycqa/flake8
rev: 7.1.1
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: flake8
args: ["--config", "setup.cfg"]
- id: black
24 changes: 10 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,33 @@ conda activate pytorch-ignite-dev

### Installation

1) Make a fork of the repository on the GitHub (see [here](https://github.com/firstcontributions/first-contributions#fork-this-repository) for details).
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
1. Make a fork of the repository on the GitHub (see [here](https://github.com/firstcontributions/first-contributions#fork-this-repository) for details).
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

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

```bash
git clone https://github.com/happy-ignite-developer/ignite.git
cd ignite
git remote add upstream https://github.com/pytorch/ignite.git
git remote -v
```

You might see the following output:

```
origin https://github.com/happy-ignite-developer/ignite.git (fetch)
origin https://github.com/happy-ignite-developer/ignite.git (push)
upstream https://github.com/pytorch/ignite (fetch)
upstream https://github.com/pytorch/ignite (push)
```
3) Sync and install all necessary dependencies:

3. Sync and install all necessary dependencies:

```bash
git pull upstream master
pip install -e .
pip install -r requirements-dev.txt
bash ./tests/run_code_style.sh install
```

### Code development
Expand Down Expand Up @@ -149,15 +151,11 @@ black manually to format files and commit them.

To install `flake8`, `ufmt` and `mypy`, please run

```bash
bash ./tests/run_code_style.sh install
```

To format files and commit changes:

```bash
# This should autoformat the files
bash ./tests/run_code_style.sh fmt
pre-commit -a
# If everything is OK, then commit
git add .
git commit -m "Added awesome feature"
Expand Down Expand Up @@ -226,7 +224,7 @@ CUDA_VISIBLE_DEVICES="" pytest --dist=each --tx $WORLD_SIZE*popen//python=python
To run mypy to check the optional static type:

```bash
bash ./tests/run_code_style.sh mypy
mypy
```

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

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)


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)

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

Expand Down
117 changes: 95 additions & 22 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license-files = ["LICENSE"]
classifiers = [
"Programming Language :: Python :: 3",
]
requires-python = ">=3.9,<3.13"
dependencies = [
"torch>=1.3,<3",
"packaging"
Expand All @@ -34,6 +35,94 @@ artifacts = [
"*.typed",
]

[tool.ruff]
src = ["ignite", "examples", "tests"]

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
"assets",
]

# Same as Black.
line-length = 120
indent-width = 4

# Assume Python 3.9
target-version = "py39"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = ["E402", "E713", "E721", "E722", "E203", "E231", "F403", "F841"] # "W503",

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.isort]
known-third-party = ["clearml", "dill", "matplotlib", "numpy", "pkg_resources", "pytest", "requests", "setuptools", "skimage", "sklearn", "torch", "torchvision"]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", ]

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

[tool.black]
line-length = 120
target-version = ['py39', 'py311']
Expand All @@ -59,26 +148,10 @@ exclude = '''
)
'''

[tool.usort.known]
first_party = [
"ignite",
]
third_party = [
"clearml",
"dill",
"matplotlib",
"numpy",
"pkg_resources",
"pytest",
"requests",
"setuptools",
"skimage",
"sklearn",
"torch",
"torchvision",
]

[tool.ufmt]
excludes = [
"assets/",
[tool.pytest.ini_options]
markers = [
"distributed: mark a test with distributed option",
"multinode_distributed: mark a test with multi-node distributed option",
"tpu: mark a test as requiring XLA",
]
addopts = "--color=yes"
3 changes: 3 additions & 0 deletions requirements-check.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Local development
mypy
pre-commit
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
numpy
pytest
pytest-cov
pytest-xdist
pytest-order
pytest-timeout
pytest-xdist
dill
filelock
setuptools
Expand Down
28 changes: 0 additions & 28 deletions setup.cfg

This file was deleted.

Loading
Loading