-
Notifications
You must be signed in to change notification settings - Fork 844
🔧 chore(ci): upgrade python 3.13 #3112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
🔧 chore(ci): upgrade python 3.13 #3112
Conversation
87bbf95 to
aee7d36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR upgrades the project's minimum Python version from 3.10 to 3.13, ensuring compatibility with the latest Python release. The changes include CI/CD updates, dependency constraint adjustments, code modernization to use Python 3.13 features, and compatibility fixes for ONNX export and tests.
- Migrates string-based enums from
class Name(str, Enum)toclass Name(StrEnum)pattern - Simplifies Generator type hints from
Generator[T, None, None]toGenerator[T] - Adds
dynamo=Falseto ONNX export to use legacy JIT exporter due to Dynamo compatibility issues
Reviewed changes
Copilot reviewed 44 out of 45 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/pre_merge.yml |
Updated CI to test Python 3.13 alongside 3.10 |
pyproject.toml |
Added Python 3.13 classifier, updated PyTorch dependency constraints, reorganized ruff configuration |
docs/source/snippets/install/source.txt |
Updated installation instructions to support Python >=3.10 |
docs/source/markdown/guides/developer/contributing.md |
Updated development environment setup to support Python >=3.10 |
src/anomalib/models/components/base/export_mixin.py |
Added dynamo=False to torch.onnx.export for legacy JIT exporter |
src/anomalib/data/utils/download.py |
Removed Python version check for tar.extract filter parameter |
src/anomalib/data/dataclasses/torch/base.py |
Moved TypeVar declaration after InferenceBatch class |
src/anomalib/data/dataclasses/numpy/depth.py |
Added missing dataclass decorator and type annotations |
| Multiple enum files | Migrated from (str, Enum) pattern to StrEnum |
| Multiple generator files | Simplified Generator type hints by removing None type parameters |
tests/unit/deploy/test_inferencer.py |
Relaxed tolerance from 1e-3 to 3e-3 for floating-point comparison |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pyproject.toml
Outdated
| cu118 = [ | ||
| "torch>=2.4.0,<=2.8.0", | ||
| "torchvision>=0.19.0", | ||
| "torch>=2.4.0,<=2.5.1 ; python_version < '3.13'", |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upper bound constraint <=2.5.1 for cu118 seems overly restrictive and inconsistent with the other CUDA extras. If PyTorch 2.5.1 is the last version supporting CUDA 11.8 on Python 3.12, this is correct. However, if newer versions exist that also support CUDA 11.8 on Python < 3.13, consider using an open upper bound like torch>=2.4.0 ; python_version < '3.13' to avoid unnecessary version locks.
| "torch>=2.4.0,<=2.5.1 ; python_version < '3.13'", | |
| "torch>=2.4.0 ; python_version < '3.13'", |
pyproject.toml
Outdated
| cu121 = [ | ||
| "torch>=2.4.0,<=2.8.0", | ||
| "torchvision>=0.19.0", | ||
| "torch>=2.4.0 ; python_version < '3.13'", |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cu121 extra has no upper bound for torch, which differs from cu118 that has <=2.5.1. This inconsistency may be intentional if CUDA 12.1 wheels continue to be built for Python < 3.13, but consider documenting why these constraints differ or making them consistent if both CUDA versions have the same support lifecycle.
| "torch>=2.4.0 ; python_version < '3.13'", | |
| "torch>=2.4.0,<=2.5.1 ; python_version < '3.13'", |
| # PyTorch dependency groups | ||
| cpu = [ | ||
| "torch>=2.4.0,<=2.8.0", | ||
| "torch>=2.4.0", |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of the upper bound <=2.8.0 for the cpu extra creates potential compatibility risks. If PyTorch 3.0+ introduces breaking changes, users could encounter issues. Consider retaining an upper bound (e.g., <3.0) or adding a comment explaining why the constraint was relaxed.
| "torch>=2.4.0", | |
| "torch>=2.4.0,<3.0", |
| >>> item.depth.shape | ||
| (224, 224) | ||
| """ | ||
|
|
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The new imports on lines 29 and 31 are only used for the item_class type annotation on line 93. Consider adding these imports closer to where they're used, or add a comment explaining they're specifically for the ClassVar annotation added for Python 3.13 compatibility.
| # The following imports are only used for the `item_class` type annotation in NumpyDepthBatch | |
| # and are required for Python 3.13 compatibility with ClassVar. |
| pred_mask: torch.Tensor | None = None | ||
|
|
||
|
|
||
| NumpyT = TypeVar("NumpyT") |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Moving NumpyT after InferenceBatch appears to be for ordering purposes, but it creates a gap between related type definitions. Consider adding a comment explaining why this TypeVar is defined here rather than at the top with other type-related imports, especially since it's used by the ToNumpyMixin class below.
pyproject.toml
Outdated
|
|
||
| ignore = [ | ||
| # pydocstyle | ||
| "COM812", |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new COM812 ignore rule (missing trailing commas) is added without explanation. Consider adding a comment explaining why this specific rule is being ignored, especially since it appears in the middle of other documented rule ignores. This helps maintainers understand the rationale.
| "COM812", | |
| "COM812", # Missing trailing comma (ignored due to project style preference) |
| # Use of virtual environment is highy recommended | ||
| # Using conda | ||
| yes | conda create -n anomalib_env python=3.10 | ||
| yes | conda create -n anomalib_env python>=3.10 |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conda create command syntax python>=3.10 is incorrect. Conda expects python=3.10 or python=3.13 but does not support constraint operators like >= in the package specification. This should be changed to a specific version like python=3.13 or python=3.10.
| yes | conda create -n anomalib_env python>=3.10 | |
| yes | conda create -n anomalib_env python=3.10 |
|
|
||
| ```bash | ||
| conda create -n anomalib_dev python=3.10 | ||
| conda create -n anomalib_dev python>=3.10 |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conda create command syntax python>=3.10 is incorrect. Conda does not support constraint operators like >= in package specifications. Use a specific version like python=3.13 or python=3.10 instead.
| conda create -n anomalib_dev python>=3.10 | |
| conda create -n anomalib_dev python=3.10 |
0ac0b74 to
7985e04
Compare
- Update pyproject.toml to require python >= 3.13 - Update tox.ini to test py313 - Remove legacy CUDA dependencies (11.8, 12.1) incompatible with PyTorch 2.5+ - Fix numpy array formatting issue in inferencer tests for Py3.13 compatibility Signed-off-by: Rickypanta0 <rickypanta.dev@gmail.com>
7985e04 to
204426f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 82 out of 83 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,6 +1,6 @@ | |||
| # Use of virtual environment is highy recommended | |||
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "highy" should be "highly".
| # Use of virtual environment is highy recommended | |
| # Use of virtual environment is highly recommended |
samet-akcay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your contribution @Rickypanta0. I've added some comments.
| # | ||
| # Required Inputs: | ||
| # - python-version: Python version for building (default: "3.10") | ||
| # - python-version: Python version for building (default: "3.11") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
| # uses: ./.github/workflows/_reusable-artifact-builder.yaml | ||
| # with: | ||
| # python-version: "3.10" | ||
| # python-version: "3.11" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| description: "Python version for building" | ||
| type: string | ||
| default: "3.10" | ||
| default: "3.11" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here?
| # with: | ||
| # version: "v1.2.3" | ||
| # python-version: "3.10" | ||
| # python-version: "3.11" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| # with: | ||
| # version: "v1.2.3-rc1" | ||
| # python-version: "3.10" | ||
| # python-version: "3.11" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here. It would be great to have consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, would you prefer these examples/defaults to reflect the minimum supported version (reverting to 3.10, as it was) or the latest target version ?
| """ | ||
|
|
||
| item_class = NumpyDepthItem | ||
| item_class: ClassVar[Callable] = NumpyDepthItem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these changes related to python version as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, is indirectly related. Upgrading to 3.13, the pre-commit hooks fails with mypy with incompatibility error. I adopted for the fix instaed of suppressing it with # type: ignore[misc]. Here is the error log raised from the upgrade:
`mypy.....................................................................Failed
hook id: mypy
exit code: 1
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_DepthInputFields" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_ImageInputFields" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "NumpyBatch" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_GenericBatch" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "UpdateMixin" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_OutputFields" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_InputFields" [misc]
Found 7 errors in 1 file (checked 396 source files)`
|
|
||
| @dataclass | ||
| class ToNumpyMixin(Generic[NumpyT]): | ||
| class ToNumpyMixin(Generic[NumpyT]): # noqa: UP046 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above? Do we need to change all this when we change the python version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is triggered by the upgrade. Since the target is now compatible with py 3.12+. However i found that the new syntax for the bounded generics are less readable in my opinion, compared with the current implementation. I decided to suppress the errors with # noqa: UP046 to mantain readability.
| readme = "README.md" | ||
| description = "anomalib - Anomaly Detection Library" | ||
| requires-python = ">=3.10" | ||
| requires-python = ">=3.13" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undestood, i will revert the compatibility to >=3.10 to keep backward compatibility while ensuring the CI/CD pipeline test against 3.13.

📝 Description
This PR addresses issue #2959 by upgrading the project's minimum Python version from Python 3.10 to Python 3.13. It addresses dependency constraints, updates CI configurations, and applies necessary fixes to code and tests to ensure compatibility with the updated environment.
Key Changes & Rationale:
pre_merge.yml) and documentation to use Python 3.13.pyproject.tomlanduv.lockto support Python 3.13.cu118andcu121extras topython_version < '3.13', as PyTorch does not provide wheels for these CUDA versions on Python 3.13 (which defaults to CUDA 12.4).torch.onnx.exportto use the legacy JIT exporter (dynamo=False) inexport_mixin.py.GuardOnDataDependentSymNodedue to data-dependent control flow inpost_processor.py(specificallyisnan()checks). The legacy exporter handles this correctly.test_inference_similarity(from1e-3to5-e3).✨ Changes
Select what type of change your PR is:
✅ Checklist
Before you submit your pull request, please make sure you have completed the following steps: