Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
sudo apt update
sudo apt-get install -y libopenjp2-7 libopenjp2-tools
python -m pip install --upgrade pip
python -m pip install ruff==0.11.13 pytest pytest-cov pytest-runner
python -m pip install ruff==0.12.2 pytest pytest-cov pytest-runner
pip install -r requirements/requirements.txt
- name: Cache tiatoolbox static assets
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ repos:
- id: rst-inline-touching-normal # Detect mistake of inline code touching normal text in rst.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.13
rev: v0.12.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/annotation_store_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def __exit__(self: memray, *args: object) -> None:

import numpy as np
import psutil
from shapely import affinity
from shapely.geometry import Polygon
from tqdm import tqdm

Expand Down Expand Up @@ -188,8 +189,6 @@ def cell_polygon(
round_coords (bool): Round coordinates to integers. Defaults to False.

"""
from shapely import affinity

rand_state = np.random.default_rng().__getstate__()
rng = np.random.default_rng(seed)
if repeat_first:
Expand Down
4 changes: 2 additions & 2 deletions pre-commit/notebook_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def git_branch_name() -> str:
"""Get the current branch name."""
return (
subprocess.check_output( # noqa: S603
subprocess.check_output(
["/usr/bin/git", "rev-parse", "--abbrev-ref", "HEAD"],
)
.decode()
Expand Down Expand Up @@ -45,7 +45,7 @@ def git_previous_commit_modified_paths() -> set[Path]:
"""Get a set of file paths modified in the previous commit."""
return {
Path(p)
for p in subprocess.check_output( # noqa: S603
for p in subprocess.check_output(
["/usr/bin/git", "diff", "--name-only", "HEAD~"],
)
.decode()
Expand Down
2 changes: 1 addition & 1 deletion pre-commit/requirements_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def parse_setup_py(file_path: Path) -> dict[str, Requirement]:
pkg_resources.Requirement.
"""
mock_setup = {}
import setuptools
import setuptools # noqa: PLC0415

setuptools.setup = lambda **kw: mock_setup.update(kw)
spec = importlib.util.spec_from_file_location("setup", str(file_path))
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pytest>=7.2.0
pytest-cov>=4.0.0
pytest-runner>=6.0
pytest-xdist[psutil]
ruff==0.11.13 # This will be updated by pre-commit bot to latest version
ruff==0.12.2 # This will be updated by pre-commit bot to latest version
toml>=0.10.2
twine>=4.0.1
wheel>=0.37.1
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,9 @@ def chdir() -> Callable:

"""
try:
from contextlib import chdir
from contextlib import chdir # noqa: PLC0415
except ImportError:
from contextlib import AbstractContextManager
from contextlib import AbstractContextManager # noqa: PLC0415

class chdir(AbstractContextManager): # noqa: N801
"""Non thread-safe context manager to change the current working directory.
Expand Down
10 changes: 5 additions & 5 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_set_root_dir(tmp_path: Path) -> None:
"""Test for setting new root dir."""
# skipcq
importlib.reload(tiatoolbox)
from tiatoolbox import rcParam
from tiatoolbox import rcParam # noqa: PLC0415

old_root_dir = rcParam["TIATOOLBOX_HOME"]
test_dir_path = tmp_path / "tmp_check"
Expand All @@ -27,7 +27,7 @@ def test_set_root_dir(tmp_path: Path) -> None:
# reimport to see if it overwrites
# silence Deep Source because this is an intentional check
# skipcq
from tiatoolbox import rcParam
from tiatoolbox import rcParam # noqa: PLC0415

rcParam["TIATOOLBOX_HOME"].mkdir(parents=True)
if not Path.exists(test_dir_path):
Expand Down Expand Up @@ -135,9 +135,9 @@ def test_duplicate_filter(caplog: pytest.LogCaptureFixture) -> None:

def test_lazy_import() -> None:
"""Test lazy import for tiatoolbox."""
import sys
import sys # noqa: PLC0415

from tiatoolbox import _lazy_import
from tiatoolbox import _lazy_import # noqa: PLC0415

assert "exceptions" not in sys.modules

Expand All @@ -151,7 +151,7 @@ def test_lazy_import() -> None:

def test_lazy_import_module_not_found() -> None:
"""'Test lazy import for ModuleNotFoundError."""
from tiatoolbox import _lazy_import
from tiatoolbox import _lazy_import # noqa: PLC0415

with pytest.raises(ModuleNotFoundError):
_lazy_import(
Expand Down
10 changes: 5 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import hashlib
import json
import shutil
from pathlib import Path
from typing import TYPE_CHECKING, NoReturn
Expand All @@ -27,7 +28,10 @@
from tiatoolbox.annotation.storage import DictionaryStore, SQLiteStore
from tiatoolbox.enums import GeometryType
from tiatoolbox.models.architecture import fetch_pretrained_weights
from tiatoolbox.models.architecture.utils import compile_model
from tiatoolbox.models.architecture.utils import (
compile_model,
is_torch_compile_compatible,
)
from tiatoolbox.utils import misc
from tiatoolbox.utils.exceptions import FileNotSupportedError
from tiatoolbox.utils.transforms import locsize2bounds
Expand Down Expand Up @@ -1348,8 +1352,6 @@ def test_select_device() -> None:
def test_save_as_json(tmp_path: Path) -> None:
"""Test save data to json."""
# This should be broken up into separate tests!
import json

# dict with nested dict, list, and np.array
key_dict = {
"a1": {"name": "John", "age": 23, "sex": "male"},
Expand Down Expand Up @@ -1860,8 +1862,6 @@ def test_torch_compile_disable() -> None:

def test_torch_compile_compatibility(caplog: pytest.LogCaptureFixture) -> None:
"""Test if torch-compile compatibility is checked correctly."""
from tiatoolbox.models.architecture.utils import is_torch_compile_compatible

is_torch_compile_compatible()
assert "torch.compile" in caplog.text

Expand Down
6 changes: 3 additions & 3 deletions tiatoolbox/annotation/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class SQLTriplet(SQLExpression):

def __init__(
self: SQLExpression,
lhs: SQLTriplet | str | SQLExpression | Number | bool | object,
lhs: SQLTriplet | str | SQLExpression | Number | bool | object, # noqa: FBT001
op: Callable | str | None = None,
rhs: SQLTriplet | str | SQLExpression | Number | SQLNone | object | None = None,
) -> None:
Expand Down Expand Up @@ -373,7 +373,7 @@ def json_contains(json_str: str, x: object) -> bool:
return x in json.loads(json_str)


def sql_is_none(x: SQLExpression | Number | str | bool) -> SQLTriplet:
def sql_is_none(x: SQLExpression | Number | str | bool) -> SQLTriplet: # noqa: FBT001
"""Check if x is None.

Returns:
Expand All @@ -384,7 +384,7 @@ def sql_is_none(x: SQLExpression | Number | str | bool) -> SQLTriplet:
return SQLTriplet(x, "is_none")


def sql_is_not_none(x: SQLExpression | Number | str | bool) -> SQLTriplet:
def sql_is_not_none(x: SQLExpression | Number | str | bool) -> SQLTriplet: # noqa: FBT001
"""Check if x is not None.

Returns:
Expand Down
1 change: 0 additions & 1 deletion tiatoolbox/annotation/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4047,7 +4047,6 @@ def __len__(self: DictionaryStore) -> int:
"""Return the length of the instance attributes."""
return len(self._rows)

# flake8: noqa: A003
@classmethod
def open(cls: type[AnnotationStore], fp: Path | str | IO) -> AnnotationStore:
"""Opens :class:`DictionaryStore` from file pointer or path."""
Expand Down
Loading
Loading