diff --git a/.github/workflows/code-style-checks.yml b/.github/workflows/code-style-checks.yml new file mode 100644 index 000000000000..95c79d94d831 --- /dev/null +++ b/.github/workflows/code-style-checks.yml @@ -0,0 +1,65 @@ +name: Code Style Checks + +on: + push: + branches: + - master + - "*.*.*" + paths: + - "**.py" + - "setup.cfg" + - "requirements-dev.txt" + - "pyproject.toml" + - ".pre-commit-config.yaml" + - ".github/workflows/code-style-checks.yml" + - "!assets/**" + - "!docker/**" + - "!docs/**" + - "!conda.recipe" + pull_request: + paths: + - "**.py" + - "setup.cfg" + - "requirements-dev.txt" + - "pyproject.toml" + - ".pre-commit-config.yaml" + - ".github/workflows/code-style-checks.yml" + - "!assets/**" + - "!docker/**" + - "!docs/**" + - "!conda.recipe" + workflow_dispatch: + +concurrency: + # -- + group: code-style-${{ github.ref_name }}-${{ !(github.ref_protected) || github.sha }} + cancel-in-progress: true + +jobs: + code-style: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.13"] + + steps: + - uses: actions/checkout@v4 + + - uses: astral-sh/setup-uv@v6 + with: + version: "latest" + python-version: ${{ matrix.python-version }} + activate-environment: true + enable-cache: true + cache-dependency-glob: | + **/requirements-dev.txt + **/pyproject.toml + + - name: Install dependencies + run: | + uv pip install pre-commit + uv pip install -r requirements-dev.txt + uv pip install -e . + + - name: Run pre-commit checks + run: pre-commit run --all-files --show-diff-on-failure diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml deleted file mode 100644 index d8ebbcc4d269..000000000000 --- a/.github/workflows/code-style.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Format python code - -on: - push: - paths: - - "**.py" - - "setup.cfg" - - "requirements-dev.txt" - - "pyproject.toml" - - ".github/workflows/code-style.yml" - - "!assets/**" - - "!docker/**" - - "!docs/**" - - "!conda.recipe" - -jobs: - code-style: - runs-on: ubuntu-latest - steps: - - if: github.event_name == 'push' - uses: actions/checkout@v4 - - uses: astral-sh/setup-uv@v6 - with: - version: "latest" - python-version: "3.11" - activate-environment: true - enable-cache: true - cache-dependency-glob: | - **/requirements-dev.txt - **/pyproject.toml - - run: | - pip install -r requirements-dev.txt - pre-commit run -a - - - name: Commit and push changes - uses: stefanzweifel/git-auto-commit-action@v6 - with: - commit_message: "autopep8 fix" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/typing-checks.yml b/.github/workflows/typing-checks.yml new file mode 100644 index 000000000000..2dc8d6f8d933 --- /dev/null +++ b/.github/workflows/typing-checks.yml @@ -0,0 +1,69 @@ +name: Type Checking + +on: + push: + branches: + - master + - "*.*.*" + paths: + - "ignite/**" + - "examples/**.py" + - "tests/ignite/**" + - "requirements-dev.txt" + - "pyproject.toml" + - "mypy.ini" + - ".github/workflows/typing-checks.yml" + pull_request: + paths: + - "ignite/**" + - "examples/**.py" + - "tests/ignite/**" + - "requirements-dev.txt" + - "pyproject.toml" + - "mypy.ini" + - ".github/workflows/typing-checks.yml" + workflow_dispatch: + +concurrency: + # -- + group: typing-${{ github.ref_name }}-${{ !(github.ref_protected) || github.sha }} + cancel-in-progress: true + +jobs: + mypy: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.13"] + pytorch-channel: [pytorch] + + steps: + - uses: actions/checkout@v4 + + - name: Get year & week number + id: get-date + run: | + echo "date=$(/bin/date "+%Y-%U")" >> $GITHUB_OUTPUT + + - uses: astral-sh/setup-uv@v6 + with: + version: "latest" + python-version: ${{ matrix.python-version }} + activate-environment: true + enable-cache: true + cache-suffix: "${{ steps.get-date.outputs.date }}-typing-${{ runner.os }}-${{ matrix.python-version }}" + cache-dependency-glob: | + **/requirements-dev.txt + **/pyproject.toml + + - name: Install PyTorch + run: uv pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu + + - name: Install dependencies + run: | + uv pip install -r requirements-dev.txt + uv pip install . + uv pip install mypy + + - name: Run MyPy type checking + run: mypy diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index aff8f4716be3..9437ca8d90e0 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -93,17 +93,6 @@ jobs: uv pip install . uv pip list - - name: Check code formatting - run: | - pre-commit run -a - - - name: Run Mypy - # https://github.com/pytorch/ignite/pull/2780 - # - if: ${{ matrix.os == 'ubuntu-latest' }} - run: | - mypy - # Download MNIST: https://github.com/pytorch/ignite/issues/1737 # to "/tmp" for unit tests - name: Download MNIST diff --git a/.gitignore b/.gitignore index 995f3ac0e864..ce03e6ffec93 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ conda_build/ .neptune/ pytest.ini + +.vscode/* diff --git a/ignite/handlers/clearml_logger.py b/ignite/handlers/clearml_logger.py index 7ceba167dd73..00af4531aa10 100644 --- a/ignite/handlers/clearml_logger.py +++ b/ignite/handlers/clearml_logger.py @@ -118,6 +118,8 @@ class ClearMLLogger(BaseLogger): """ + _task: Any + def __init__(self, **kwargs: Any): try: from clearml import Task @@ -823,6 +825,8 @@ class ClearMLSaver(DiskSaver): """ + _task: Any + def __init__( self, logger: Optional[ClearMLLogger] = None, @@ -858,7 +862,7 @@ def _setup_check_clearml(self, logger: ClearMLLogger, output_uri: str) -> None: except ImportError: try: # Backwards-compatibility for legacy Trains SDK - from trains import Task + from trains import Task # type: ignore[no-redef] except ImportError: raise ModuleNotFoundError( "This contrib module requires clearml to be installed. " @@ -933,7 +937,7 @@ def __call__(self, checkpoint: Mapping, filename: str, metadata: Optional[Mappin except ImportError: try: # Backwards-compatibility for legacy Trains SDK - from trains.binding.frameworks import WeightsFileHandler + from trains.binding.frameworks import WeightsFileHandler # type: ignore[no-redef] except ImportError: raise ModuleNotFoundError( "This contrib module requires clearml to be installed. " @@ -957,8 +961,8 @@ def __call__(self, checkpoint: Mapping, filename: str, metadata: Optional[Mappin metadata=metadata, ) - pre_cb_id = WeightsFileHandler.add_pre_callback(cb_context.pre_callback) - post_cb_id = WeightsFileHandler.add_post_callback(cb_context.post_callback) + pre_cb_id = WeightsFileHandler.add_pre_callback(cb_context.pre_callback) # type: ignore[arg-type] + post_cb_id = WeightsFileHandler.add_post_callback(cb_context.post_callback) # type: ignore[arg-type] try: super(ClearMLSaver, self).__call__(checkpoint, filename, metadata)