Skip to content

Commit f41b1e3

Browse files
authored
Add typing and style checks as separate workflows (#3442)
1 parent ddbd188 commit f41b1e3

File tree

6 files changed

+144
-55
lines changed

6 files changed

+144
-55
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Code Style Checks
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- "*.*.*"
8+
paths:
9+
- "**.py"
10+
- "setup.cfg"
11+
- "requirements-dev.txt"
12+
- "pyproject.toml"
13+
- ".pre-commit-config.yaml"
14+
- ".github/workflows/code-style-checks.yml"
15+
- "!assets/**"
16+
- "!docker/**"
17+
- "!docs/**"
18+
- "!conda.recipe"
19+
pull_request:
20+
paths:
21+
- "**.py"
22+
- "setup.cfg"
23+
- "requirements-dev.txt"
24+
- "pyproject.toml"
25+
- ".pre-commit-config.yaml"
26+
- ".github/workflows/code-style-checks.yml"
27+
- "!assets/**"
28+
- "!docker/**"
29+
- "!docs/**"
30+
- "!conda.recipe"
31+
workflow_dispatch:
32+
33+
concurrency:
34+
# <workflow_name>-<branch_name>-<true || commit_sha (if branch is protected)>
35+
group: code-style-${{ github.ref_name }}-${{ !(github.ref_protected) || github.sha }}
36+
cancel-in-progress: true
37+
38+
jobs:
39+
code-style:
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
python-version: ["3.9", "3.13"]
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: astral-sh/setup-uv@v6
49+
with:
50+
version: "latest"
51+
python-version: ${{ matrix.python-version }}
52+
activate-environment: true
53+
enable-cache: true
54+
cache-dependency-glob: |
55+
**/requirements-dev.txt
56+
**/pyproject.toml
57+
58+
- name: Install dependencies
59+
run: |
60+
uv pip install pre-commit
61+
uv pip install -r requirements-dev.txt
62+
uv pip install -e .
63+
64+
- name: Run pre-commit checks
65+
run: pre-commit run --all-files --show-diff-on-failure

.github/workflows/code-style.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Type Checking
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- "*.*.*"
8+
paths:
9+
- "ignite/**"
10+
- "examples/**.py"
11+
- "tests/ignite/**"
12+
- "requirements-dev.txt"
13+
- "pyproject.toml"
14+
- "mypy.ini"
15+
- ".github/workflows/typing-checks.yml"
16+
pull_request:
17+
paths:
18+
- "ignite/**"
19+
- "examples/**.py"
20+
- "tests/ignite/**"
21+
- "requirements-dev.txt"
22+
- "pyproject.toml"
23+
- "mypy.ini"
24+
- ".github/workflows/typing-checks.yml"
25+
workflow_dispatch:
26+
27+
concurrency:
28+
# <workflow_name>-<branch_name>-<true || commit_sha (if branch is protected)>
29+
group: typing-${{ github.ref_name }}-${{ !(github.ref_protected) || github.sha }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
mypy:
34+
runs-on: ubuntu-latest
35+
strategy:
36+
matrix:
37+
python-version: ["3.9", "3.13"]
38+
pytorch-channel: [pytorch]
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Get year & week number
44+
id: get-date
45+
run: |
46+
echo "date=$(/bin/date "+%Y-%U")" >> $GITHUB_OUTPUT
47+
48+
- uses: astral-sh/setup-uv@v6
49+
with:
50+
version: "latest"
51+
python-version: ${{ matrix.python-version }}
52+
activate-environment: true
53+
enable-cache: true
54+
cache-suffix: "${{ steps.get-date.outputs.date }}-typing-${{ runner.os }}-${{ matrix.python-version }}"
55+
cache-dependency-glob: |
56+
**/requirements-dev.txt
57+
**/pyproject.toml
58+
59+
- name: Install PyTorch
60+
run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
61+
62+
- name: Install dependencies
63+
run: |
64+
uv pip install -r requirements-dev.txt
65+
uv pip install .
66+
uv pip install mypy
67+
68+
- name: Run MyPy type checking
69+
run: mypy

.github/workflows/unit-tests.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,6 @@ jobs:
9393
uv pip install .
9494
uv pip list
9595
96-
- name: Check code formatting
97-
run: |
98-
pre-commit run -a
99-
100-
- name: Run Mypy
101-
# https://github.com/pytorch/ignite/pull/2780
102-
#
103-
if: ${{ matrix.os == 'ubuntu-latest' }}
104-
run: |
105-
mypy
106-
10796
# Download MNIST: https://github.com/pytorch/ignite/issues/1737
10897
# to "/tmp" for unit tests
10998
- name: Download MNIST

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ conda_build/
4848

4949
.neptune/
5050
pytest.ini
51+
52+
.vscode/*

ignite/handlers/clearml_logger.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class ClearMLLogger(BaseLogger):
118118
119119
"""
120120

121+
_task: Any
122+
121123
def __init__(self, **kwargs: Any):
122124
try:
123125
from clearml import Task
@@ -823,6 +825,8 @@ class ClearMLSaver(DiskSaver):
823825
824826
"""
825827

828+
_task: Any
829+
826830
def __init__(
827831
self,
828832
logger: Optional[ClearMLLogger] = None,
@@ -858,7 +862,7 @@ def _setup_check_clearml(self, logger: ClearMLLogger, output_uri: str) -> None:
858862
except ImportError:
859863
try:
860864
# Backwards-compatibility for legacy Trains SDK
861-
from trains import Task
865+
from trains import Task # type: ignore[no-redef]
862866
except ImportError:
863867
raise ModuleNotFoundError(
864868
"This contrib module requires clearml to be installed. "
@@ -933,7 +937,7 @@ def __call__(self, checkpoint: Mapping, filename: str, metadata: Optional[Mappin
933937
except ImportError:
934938
try:
935939
# Backwards-compatibility for legacy Trains SDK
936-
from trains.binding.frameworks import WeightsFileHandler
940+
from trains.binding.frameworks import WeightsFileHandler # type: ignore[no-redef]
937941
except ImportError:
938942
raise ModuleNotFoundError(
939943
"This contrib module requires clearml to be installed. "
@@ -957,8 +961,8 @@ def __call__(self, checkpoint: Mapping, filename: str, metadata: Optional[Mappin
957961
metadata=metadata,
958962
)
959963

960-
pre_cb_id = WeightsFileHandler.add_pre_callback(cb_context.pre_callback)
961-
post_cb_id = WeightsFileHandler.add_post_callback(cb_context.post_callback)
964+
pre_cb_id = WeightsFileHandler.add_pre_callback(cb_context.pre_callback) # type: ignore[arg-type]
965+
post_cb_id = WeightsFileHandler.add_post_callback(cb_context.post_callback) # type: ignore[arg-type]
962966

963967
try:
964968
super(ClearMLSaver, self).__call__(checkpoint, filename, metadata)

0 commit comments

Comments
 (0)