Skip to content

Commit c739906

Browse files
committed
chore(ci): add python 3.13 compatibility
Signed-off-by: Rickypanta0 <[email protected]>
1 parent f2736d0 commit c739906

File tree

37 files changed

+227
-10541
lines changed

37 files changed

+227
-10541
lines changed

.github/workflows/pr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ jobs:
9999
with:
100100
test-type: "integration"
101101
runner: "self-hosted"
102-
timeout: 60
103102
enable-cache: "false"
104103
secrets:
105104
codecov-token: ${{ secrets.CODECOV_TOKEN }}

pyproject.toml

Lines changed: 44 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ classifiers = [
2222
"Programming Language :: Python :: 3.10",
2323
"Programming Language :: Python :: 3.11",
2424
"Programming Language :: Python :: 3.12",
25+
"Programming Language :: Python :: 3.13",
2526
"Topic :: Software Development :: Libraries",
2627
"Topic :: Scientific/Engineering :: Artificial Intelligence",
2728
]
@@ -100,19 +101,11 @@ test = [
100101
]
101102
# PyTorch dependency groups
102103
cpu = [
103-
"torch>=2.4.0,<=2.8.0",
104-
"torchvision>=0.19.0",
105-
]
106-
cu118 = [
107-
"torch>=2.4.0,<=2.8.0",
108-
"torchvision>=0.19.0",
109-
]
110-
cu121 = [
111-
"torch>=2.4.0,<=2.8.0",
104+
"torch>=2.4.0",
112105
"torchvision>=0.19.0",
113106
]
114107
cu124 = [
115-
"torch>=2.4.0,<=2.8.0",
108+
"torch>=2.4.0",
116109
"torchvision>=0.19.0",
117110
]
118111
cu130 = [
@@ -159,8 +152,6 @@ managed = true
159152
conflicts = [
160153
[
161154
{ extra = "cpu" },
162-
{ extra = "cu118" },
163-
{ extra = "cu121" },
164155
{ extra = "cu124" },
165156
{ extra = "cu130" },
166157
{ extra = "rocm" },
@@ -174,16 +165,6 @@ name = "pytorch-cpu"
174165
url = "https://download.pytorch.org/whl/cpu"
175166
explicit = true
176167

177-
[[tool.uv.index]]
178-
name = "pytorch-cu118"
179-
url = "https://download.pytorch.org/whl/cu118"
180-
explicit = true
181-
182-
[[tool.uv.index]]
183-
name = "pytorch-cu121"
184-
url = "https://download.pytorch.org/whl/cu121"
185-
explicit = true
186-
187168
[[tool.uv.index]]
188169
name = "pytorch-cu124"
189170
url = "https://download.pytorch.org/whl/cu124"
@@ -208,17 +189,13 @@ explicit = true
208189
[tool.uv.sources]
209190
torch = [
210191
{ index = "pytorch-cpu", extra = "cpu" },
211-
{ index = "pytorch-cu118", extra = "cu118" },
212-
{ index = "pytorch-cu121", extra = "cu121" },
213192
{ index = "pytorch-cu124", extra = "cu124" },
214193
{ index = "pytorch-cu130", extra = "cu130" },
215194
{ index = "pytorch-rocm61", extra = "rocm" },
216195
{ index = "pytorch-xpu", extra = "xpu" },
217196
]
218197
torchvision = [
219198
{ index = "pytorch-cpu", extra = "cpu" },
220-
{ index = "pytorch-cu118", extra = "cu118" },
221-
{ index = "pytorch-cu121", extra = "cu121" },
222199
{ index = "pytorch-cu124", extra = "cu124" },
223200
{ index = "pytorch-cu130", extra = "cu130" },
224201
{ index = "pytorch-rocm61", extra = "rocm" },
@@ -235,9 +212,46 @@ pytorch-triton-xpu = [
235212
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
236213
# RUFF CONFIGURATION #
237214
[tool.ruff]
215+
# Exclude a variety of commonly ignored directories.
216+
exclude = [
217+
".bzr",
218+
".direnv",
219+
".eggs",
220+
".git",
221+
".hg",
222+
".mypy_cache",
223+
".nox",
224+
".pants.d",
225+
".pytype",
226+
".ruff_cache",
227+
".svn",
228+
".tox",
229+
".venv",
230+
"__pypackages__",
231+
"_build",
232+
"buck-out",
233+
"build",
234+
"dist",
235+
"node_modules",
236+
"venv",
237+
]
238+
239+
# Same as Black.
240+
line-length = 120
241+
242+
# Assume Python 3.10.
243+
target-version = "py310"
244+
245+
# Allow imports relative to the "src" and "tests" directories.
246+
src = ["src", "tests"]
247+
248+
[tool.ruff.lint]
238249
# Enable preview features
239250
preview = true
240251

252+
# Allow unused variables when underscore-prefixed.
253+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
254+
241255
# Enable rules
242256
select = [
243257
"F", # Pyflakes (`F`)
@@ -286,8 +300,6 @@ select = [
286300
"NPY", # NumPy-specific rules (`NPY`)
287301
"PERF", # Perflint (`PERF`)
288302
"RUF", # Ruff-specific rules (`RUF`)
289-
# "FURB", # refurb (`FURB`) - ERROR: Unknown rule selector: `FURB`
290-
# "LOG", # flake8-logging (`LOG`) - ERROR: Unknown rule selector: `LOG`
291303
]
292304

293305
ignore = [
@@ -346,57 +358,21 @@ ignore = [
346358
fixable = ["ALL"]
347359
unfixable = []
348360

349-
# Exclude a variety of commonly ignored directories.
350-
exclude = [
351-
".bzr",
352-
".direnv",
353-
".eggs",
354-
".git",
355-
".hg",
356-
".mypy_cache",
357-
".nox",
358-
".pants.d",
359-
".pytype",
360-
".ruff_cache",
361-
".svn",
362-
".tox",
363-
".venv",
364-
"__pypackages__",
365-
"_build",
366-
"buck-out",
367-
"build",
368-
"dist",
369-
"node_modules",
370-
"venv",
371-
]
372-
373-
# Same as Black.
374-
line-length = 120
375-
376-
# Allow unused variables when underscore-prefixed.
377-
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
378-
379-
# Assume Python 3.10.
380-
target-version = "py310"
381-
382-
# Allow imports relative to the "src" and "tests" directories.
383-
src = ["src", "tests"]
384-
385-
[tool.ruff.mccabe]
361+
[tool.ruff.lint.mccabe]
386362
# Unlike Flake8, default to a complexity level of 10.
387363
max-complexity = 15
388364

389365

390-
[tool.ruff.pydocstyle]
366+
[tool.ruff.lint.pydocstyle]
391367
convention = "google"
392368

393-
[tool.ruff.flake8-copyright]
369+
[tool.ruff.lint.flake8-copyright]
394370
notice-rgx = """
395371
# Copyright \\(C\\) (\\d{4}(-\\d{4})?) Intel Corporation
396372
# SPDX-License-Identifier: Apache-2\\.0
397373
"""
398374

399-
[tool.ruff.per-file-ignores]
375+
[tool.ruff.lint.per-file-ignores]
400376
"examples/notebooks/**/*" = ["CPY001"]
401377

402378
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

src/anomalib/data/dataclasses/torch/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
from anomalib.data.dataclasses.generic import ImageT, _GenericBatch, _GenericItem
2222

23-
NumpyT = TypeVar("NumpyT")
24-
2523

2624
class InferenceBatch(NamedTuple):
2725
"""Batch for use in torch and inference models.
@@ -43,6 +41,9 @@ class InferenceBatch(NamedTuple):
4341
pred_mask: torch.Tensor | None = None
4442

4543

44+
NumpyT = TypeVar("NumpyT")
45+
46+
4647
@dataclass
4748
class ToNumpyMixin(Generic[NumpyT]):
4849
"""Mixin for converting torch-based dataclasses to numpy.

src/anomalib/data/datasets/image/datumaro.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ def make_datumaro_dataset(
8080
image_path = Path(root) / "images" / "default" / item["image"]["path"]
8181
label_index = item["annotations"][0]["label_id"]
8282
label = categories[label_index]
83-
samples.append({
84-
"image_path": str(image_path),
85-
"label": label,
86-
"label_index": label_index,
87-
"split": None,
88-
"mask_path": "", # mask is provided in annotation file
89-
})
83+
samples.append(
84+
{
85+
"image_path": str(image_path),
86+
"label": label,
87+
"label_index": label_index,
88+
"split": None,
89+
"mask_path": "", # mask is provided in annotation file
90+
},
91+
)
9092
samples_df = pd.DataFrame(
9193
samples,
9294
columns=["image_path", "label", "label_index", "split", "mask_path"],

src/anomalib/engine/engine.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ def fit(
365365
val_dataloaders: EVAL_DATALOADERS | None = None,
366366
datamodule: AnomalibDataModule | None = None,
367367
ckpt_path: str | Path | None = None,
368+
**kwargs, # noqa: ARG002
368369
) -> None:
369370
"""Fit the model using the trainer.
370371
@@ -379,6 +380,7 @@ def fit(
379380
Defaults to None.
380381
ckpt_path (str | None, optional): Checkpoint path. If provided, the model will be loaded from this path.
381382
Defaults to None.
383+
**kwargs: Additional arguments passed to PyTorch Lightning Trainer's fit method.
382384
383385
CLI Usage:
384386
1. you can pick a model, and you can run through the MVTec dataset.
@@ -415,7 +417,14 @@ def fit(
415417
weights_only=False,
416418
)
417419
else:
418-
self.trainer.fit(model, train_dataloaders, val_dataloaders, datamodule, ckpt_path, weights_only=False)
420+
self.trainer.fit(
421+
model,
422+
train_dataloaders,
423+
val_dataloaders,
424+
datamodule,
425+
ckpt_path,
426+
weights_only=False,
427+
)
419428

420429
def validate(
421430
self,
@@ -424,6 +433,7 @@ def validate(
424433
ckpt_path: str | Path | None = None,
425434
verbose: bool = True,
426435
datamodule: AnomalibDataModule | None = None,
436+
**kwargs, # noqa: ARG002
427437
) -> _EVALUATE_OUTPUT | None:
428438
"""Validate the model using the trainer.
429439
@@ -441,6 +451,7 @@ def validate(
441451
AnomalibDataModule` that defines the
442452
:class:`~lightning.pytorch.core.hooks.DataHooks.val_dataloader` hook.
443453
Defaults to None.
454+
**kwargs: Additional arguments passed to PyTorch Lightning Trainer's validate method.
444455
445456
Returns:
446457
_EVALUATE_OUTPUT | None: Validation results.
@@ -472,6 +483,7 @@ def test(
472483
ckpt_path: str | Path | None = None,
473484
verbose: bool = True,
474485
datamodule: AnomalibDataModule | None = None,
486+
**kwargs, # noqa: ARG002
475487
) -> _EVALUATE_OUTPUT:
476488
"""Test the model using the trainer.
477489
@@ -497,6 +509,7 @@ def test(
497509
A :class:`~lightning.pytorch.core.datamodule.AnomalibDataModule` that defines
498510
the :class:`~lightning.pytorch.core.hooks.DataHooks.test_dataloader` hook.
499511
Defaults to None.
512+
**kwargs: Additional arguments passed to PyTorch Lightning Trainer's test method.
500513
501514
Returns:
502515
_EVALUATE_OUTPUT: A List of dictionaries containing the test results. 1 dict per dataloader.
@@ -556,7 +569,7 @@ def test(
556569

557570
if self._should_run_validation(model or self.model, ckpt_path):
558571
logger.info("Running validation before testing to collect normalization metrics and/or thresholds.")
559-
self.trainer.validate(model, dataloaders, None, verbose=False, datamodule=datamodule)
572+
self.trainer.validate(model, dataloaders, None, verbose=False, datamodule=datamodule, weights_only=False)
560573
return self.trainer.test(model, dataloaders, ckpt_path, verbose, datamodule, weights_only=False)
561574

562575
def predict(
@@ -568,6 +581,7 @@ def predict(
568581
return_predictions: bool | None = None,
569582
ckpt_path: str | Path | None = None,
570583
data_path: str | Path | None = None,
584+
**kwargs, # noqa: ARG002
571585
) -> _PREDICT_OUTPUT | None:
572586
"""Predict using the model using the trainer.
573587
@@ -601,6 +615,7 @@ def predict(
601615
data_path (str | Path | None):
602616
Path to the image or folder containing images to generate predictions for.
603617
Defaults to None.
618+
**kwargs: Additional arguments passed to PyTorch Lightning Trainer's predict method.
604619
605620
Returns:
606621
_PREDICT_OUTPUT | None: Predictions.
@@ -747,6 +762,7 @@ def export(
747762
ov_kwargs: dict[str, Any] | None = None,
748763
onnx_kwargs: dict[str, Any] | None = None,
749764
ckpt_path: str | Path | None = None,
765+
**kwargs, # noqa: ARG002
750766
) -> Path | None:
751767
r"""Export the model in PyTorch, ONNX or OpenVINO format.
752768
@@ -785,6 +801,7 @@ def export(
785801
See https://pytorch.org/docs/stable/onnx.html#torch.onnx.export for details.
786802
Defaults to ``None``.
787803
ckpt_path (str | Path | None): Checkpoint path. If provided, the model will be loaded from this path.
804+
**kwargs: Additional arguments.
788805
789806
Returns:
790807
Path: Path to the exported model.

src/anomalib/metrics/threshold/f1_adaptive_threshold.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949

5050
@contextmanager
51-
def handle_mac(metric: "_F1AdaptiveThreshold") -> Generator[None, None, None]:
51+
def handle_mac(metric: "_F1AdaptiveThreshold") -> Generator[None]:
5252
"""Temporarily move tensors to CPU on macOS/MPS and restore after.
5353
5454
This context manager checks whether the provided metric instance has

src/anomalib/models/components/base/anomalib_module.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,12 @@ def configure_pre_processor(image_size: tuple[int, int] | None = None) -> PrePro
328328
"""
329329
image_size = image_size or (256, 256)
330330
return PreProcessor(
331-
transform=Compose([
332-
Resize(image_size, antialias=True),
333-
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
334-
]),
331+
transform=Compose(
332+
[
333+
Resize(image_size, antialias=True),
334+
Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
335+
],
336+
),
335337
)
336338

337339
def configure_post_processor(self) -> PostProcessor | None:

0 commit comments

Comments
 (0)