Skip to content

Commit 16a632f

Browse files
authored
Merge branch 'dev-define-engines-abc' into dev-define-semantic-segmentor
2 parents c84099b + 8571e14 commit 16a632f

28 files changed

+39
-41
lines changed

.github/workflows/mypy-type-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
mypy --install-types --non-interactive --follow-imports=skip \
4141
tiatoolbox/__init__.py \
4242
tiatoolbox/__main__.py \
43-
tiatoolbox/typing.py \
43+
tiatoolbox/type_hints.py \
4444
tiatoolbox/tiatoolbox.py \
4545
tiatoolbox/utils \
4646
tiatoolbox/tools \

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
sudo apt update
3131
sudo apt-get install -y libopenslide-dev openslide-tools libopenjp2-7 libopenjp2-tools
3232
python -m pip install --upgrade pip
33-
python -m pip install ruff==0.8.2 pytest pytest-cov pytest-runner
33+
python -m pip install ruff==0.9.4 pytest pytest-cov pytest-runner
3434
pip install -r requirements/requirements.txt
3535
- name: Cache tiatoolbox static assets
3636
uses: actions/cache@v3

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
- mdformat-black
2424
- mdformat-myst
2525
- repo: https://github.com/executablebooks/mdformat
26-
rev: 0.7.21
26+
rev: 0.7.22
2727
hooks:
2828
- id: mdformat
2929
# Optionally add plugins
@@ -60,7 +60,7 @@ repos:
6060
- id: rst-inline-touching-normal # Detect mistake of inline code touching normal text in rst.
6161
- repo: https://github.com/astral-sh/ruff-pre-commit
6262
# Ruff version.
63-
rev: v0.8.6
63+
rev: v0.9.4
6464
hooks:
6565
- id: ruff
6666
args: [--fix, --exit-non-zero-on-fix]

pre-commit/notebook_urls.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ def check_notebook(
197197
for line_num, line in enumerate(cell["source"]):
198198
new_line = replace_line(line, to_ref, replacements)
199199
if new_line != line:
200-
print(f"{path.name}: Changed (cell {cell_num+1}, line {line_num+1})")
200+
print(
201+
f"{path.name}: Changed (cell {cell_num + 1}, line {line_num + 1})"
202+
)
201203
changed = True
202204
cell["source"][line_num] = new_line
203205
return changed, notebook

requirements/requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pytest>=7.2.0
1010
pytest-cov>=4.0.0
1111
pytest-runner>=6.0
1212
pytest-xdist[psutil]
13-
ruff==0.8.2 # This will be updated by pre-commit bot to latest version
13+
ruff==0.9.4 # This will be updated by pre-commit bot to latest version
1414
toml>=0.10.2
1515
twine>=4.0.1
1616
wheel>=0.37.1

tests/engines/test_engine_abc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def test_engine_run() -> NoReturn:
355355

356356
def test_engine_run_with_verbose() -> NoReturn:
357357
"""Test engine run with verbose."""
358-
"""Run pytest with `-rP` option to view progress bar on the captured stderr call"""
358+
# Run pytest with `-rP` option to view progress bar on the captured stderr call.
359359

360360
eng = TestEngineABC(model="alexnet-kather100k", verbose=True)
361361
out = eng.run(
@@ -401,7 +401,7 @@ def test_patch_pred_zarr_store(tmp_path: pytest.TempPathFactory) -> NoReturn:
401401
)
402402
assert Path.exists(out), "Zarr output file does not exist"
403403

404-
""" test custom zarr output file name"""
404+
# Test custom zarr output file name
405405
eng = TestEngineABC(model="alexnet-kather100k")
406406
out = eng.run(
407407
images=np.zeros((10, 224, 224, 3), dtype=np.uint8),

tests/models/test_models_abc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def forward(self: Proto) -> None:
7070
# skipcq
7171
def infer_batch() -> None:
7272
"""Define infer batch."""
73-
pass # base class definition pass # noqa: PIE790
7473

7574

7675
@pytest.mark.skipif(

tests/test_annotation_stores.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
if TYPE_CHECKING: # pragma: no cover
4141
from numbers import Number
4242

43-
from tiatoolbox.typing import Geometry
43+
from tiatoolbox.type_hints import Geometry
4444

4545

4646
sqlite3.enable_callback_tracebacks(True) # noqa: FBT003

tests/test_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def raise_source_exception(
141141
for n, line in enumerate(source.splitlines())
142142
]
143143
if source_offset:
144-
source_lines.insert(source_lineno, f"{' '*(source_offset+3)}^ {message}")
144+
source_lines.insert(source_lineno, f"{' ' * (source_offset + 3)}^ {message}")
145145
annotated_source = "\n".join(source_lines)
146146
exception = type(exception) if exception else SyntaxError
147147
msg = f"{rel_path}:{file_lineno}: {message}\n{annotated_source}"

tests/test_patch_extraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323
if TYPE_CHECKING:
24-
from tiatoolbox.typing import IntPair, Resolution, Units
24+
from tiatoolbox.type_hints import IntPair, Resolution, Units
2525

2626

2727
def read_points_patches(

tests/test_tileserver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def test_change_overlay( # noqa: PLR0915
461461
assert response.status_code == 200
462462
assert response.content_type == "text/html; charset=utf-8"
463463
# check that the overlay has been correctly added
464-
lname = f"layer{len(empty_app.pyramids[session_id])-1}"
464+
lname = f"layer{len(empty_app.pyramids[session_id]) - 1}"
465465
layer = empty_app.pyramids[session_id][lname]
466466
assert layer.wsi.info.file_path == overlay_path
467467

@@ -493,7 +493,7 @@ def test_change_overlay( # noqa: PLR0915
493493
data={"overlay_path": safe_str(jpg_path)},
494494
)
495495
# check that the overlay has been correctly added
496-
lname = f"layer{len(empty_app.pyramids[session_id])-1}"
496+
lname = f"layer{len(empty_app.pyramids[session_id]) - 1}"
497497
layer = empty_app.pyramids[session_id][lname]
498498
assert np.all(layer.wsi.img == imread(jpg_path))
499499

@@ -517,7 +517,7 @@ def test_change_overlay( # noqa: PLR0915
517517
data={"overlay_path": safe_str(tiff_path)},
518518
)
519519
# check that the overlay has been correctly added
520-
lname = f"layer{len(empty_app.pyramids[session_id])-1}"
520+
lname = f"layer{len(empty_app.pyramids[session_id]) - 1}"
521521
layer = empty_app.pyramids[session_id][lname]
522522
assert layer.wsi.info.file_path == tiff_path
523523

tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from tiatoolbox.utils.transforms import locsize2bounds
2929

3030
if TYPE_CHECKING:
31-
from tiatoolbox.typing import IntBounds
31+
from tiatoolbox.type_hints import IntBounds
3232

3333
RNG = np.random.default_rng() # Numpy Random Generator
3434

tests/test_wsireader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
import requests
5353
from openslide import OpenSlide
5454

55-
from tiatoolbox.typing import IntBounds, IntPair
55+
from tiatoolbox.type_hints import IntBounds, IntPair
5656
from tiatoolbox.wsicore.wsimeta import WSIMeta
5757

5858
# -------------------------------------------------------------------------------------

tiatoolbox/annotation/storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@
8383
py_regexp,
8484
)
8585
from tiatoolbox.enums import GeometryType
86-
from tiatoolbox.typing import CallablePredicate, CallableSelect, Geometry
86+
from tiatoolbox.type_hints import CallablePredicate, CallableSelect, Geometry
8787

8888
if TYPE_CHECKING: # pragma: no cover
89-
from tiatoolbox.typing import (
89+
from tiatoolbox.type_hints import (
9090
Predicate,
9191
Properties,
9292
QueryGeometry,

tiatoolbox/models/architecture/hovernet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ def __init__(
338338

339339
if mode not in ["original", "fast"]:
340340
msg = (
341-
f"Invalid mode {mode} for HoVerNet. "
342-
f"Only support `original` or `fast`."
341+
f"Invalid mode {mode} for HoVerNet. Only support `original` or `fast`."
343342
)
344343
raise ValueError(
345344
msg,

tiatoolbox/models/architecture/nuclick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from tiatoolbox.models.models_abc import ModelABC
2525

2626
if TYPE_CHECKING: # pragma: no cover
27-
from tiatoolbox.typing import IntPair
27+
from tiatoolbox.type_hints import IntPair
2828

2929
bn_axis = 1
3030

tiatoolbox/models/architecture/utils.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ def compile_model(
8888
logger.warning(msg=msg)
8989
return model
9090

91-
# This check will be removed when torch.compile is supported in Python 3.12+
92-
if sys.version_info > (3, 12): # pragma: no cover
93-
msg = "torch-compile is currently not supported in Python 3.12+."
94-
logger.warning(
95-
msg=msg,
96-
)
97-
return model
98-
9991
if isinstance( # pragma: no cover
10092
model,
10193
torch._dynamo.eval_frame.OptimizedModule, # skipcq: PYL-W0212 # noqa: SLF001

tiatoolbox/models/engine/multi_task_segmentor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
if TYPE_CHECKING: # pragma: no cover
4141
import torch
4242

43-
from tiatoolbox.typing import IntBounds
43+
from tiatoolbox.type_hints import IntBounds
4444

4545
from .io_config import IOInstanceSegmentorConfig, IOSegmentorConfig
4646

tiatoolbox/models/engine/semantic_segmentor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .io_config import IOSegmentorConfig
3030

3131
if TYPE_CHECKING: # pragma: no cover
32-
from tiatoolbox.typing import IntPair, Resolution, Units
32+
from tiatoolbox.type_hints import IntPair, Resolution, Units
3333

3434

3535
def _estimate_canvas_parameters(

tiatoolbox/tools/patchextraction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pandas import DataFrame
2121

2222
from tiatoolbox.annotation.storage import AnnotationStore
23-
from tiatoolbox.typing import Resolution, Units
23+
from tiatoolbox.type_hints import Resolution, Units
2424

2525

2626
def validate_shape(shape: np.ndarray) -> bool:

tiatoolbox/tools/registration/wsi_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from tiatoolbox.wsicore.wsireader import VirtualWSIReader, WSIReader
2525

2626
if TYPE_CHECKING: # pragma: no cover
27-
from tiatoolbox.typing import IntBounds, Resolution, Units
27+
from tiatoolbox.type_hints import IntBounds, Resolution, Units
2828

2929
RGB_IMAGE_DIM = 3
3030
BIN_MASK_DIM = 2
File renamed without changes.

tiatoolbox/utils/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
)
1919

2020
if TYPE_CHECKING: # pragma: no cover
21-
from tiatoolbox.typing import IntBounds, NumpyPadLiteral
21+
from tiatoolbox.type_hints import IntBounds, NumpyPadLiteral
2222

2323
PADDING_TO_BOUNDS = np.array([-1, -1, 1, 1])
2424
"""

tiatoolbox/utils/misc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ def load_stain_matrix(stain_matrix_input: np.ndarray | PathLike) -> np.ndarray:
220220
_, __, suffixes = split_path_name_ext(stain_matrix_input)
221221
if suffixes[-1] not in [".csv", ".npy"]:
222222
msg = (
223-
"If supplying a path to a stain matrix, "
224-
"use either a npy or a csv file"
223+
"If supplying a path to a stain matrix, use either a npy or a csv file"
225224
)
226225
raise FileNotSupportedError(
227226
msg,

tiatoolbox/visualization/bokeh_app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ def segment_on_box() -> None:
12041204
# Make a mask defining the box
12051205
thumb = UI["vstate"].wsi.slide_thumbnail()
12061206
conv_mpp = UI["vstate"].dims[0] / thumb.shape[1]
1207-
msg = f'box tl: {UI["box_source"].data["x"][0]}, {UI["box_source"].data["y"][0]}'
1207+
msg = f"box tl: {UI['box_source'].data['x'][0]}, {UI['box_source'].data['y'][0]}"
12081208
logger.info(msg)
12091209
x = round(
12101210
(UI["box_source"].data["x"][0] - 0.5 * UI["box_source"].data["width"][0])

tiatoolbox/visualization/tileserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def __init__( # noqa: PLR0915
102102
if isinstance(layers, list):
103103
layers_dict = {"slide": layers[0]}
104104
for i, p in enumerate(layers[1:]):
105-
layers_dict[f"layer-{i+1}"] = p
105+
layers_dict[f"layer-{i + 1}"] = p
106106
layers = layers_dict
107107
# Set up the layer dict.
108108
meta = None

tiatoolbox/wsicore/wsimeta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if TYPE_CHECKING: # pragma: no cover
2121
from collections.abc import Mapping, Sequence
2222

23-
from tiatoolbox.typing import Resolution, Units
23+
from tiatoolbox.type_hints import Resolution, Units
2424

2525

2626
class WSIMeta:

tiatoolbox/wsicore/wsireader.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434

3535
import glymur
3636

37-
from tiatoolbox.typing import Bounds, IntBounds, IntPair, NumPair, Resolution, Units
37+
from tiatoolbox.type_hints import (
38+
Bounds,
39+
IntBounds,
40+
IntPair,
41+
NumPair,
42+
Resolution,
43+
Units,
44+
)
3845
from tiatoolbox.wsicore.metadata.ngff import Multiscales
3946

4047
pixman_warning()

0 commit comments

Comments
 (0)