Skip to content
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

🧑‍💻 pre-commit autoupdate #910

Merged
merged 6 commits into from
Feb 5, 2025
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/mypy-type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
mypy --install-types --non-interactive --follow-imports=skip \
tiatoolbox/__init__.py \
tiatoolbox/__main__.py \
tiatoolbox/typing.py \
tiatoolbox/type_hints.py \
tiatoolbox/tiatoolbox.py \
tiatoolbox/utils \
tiatoolbox/tools \
Expand Down
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 libopenslide-dev openslide-tools libopenjp2-7 libopenjp2-tools
python -m pip install --upgrade pip
python -m pip install ruff==0.8.2 pytest pytest-cov pytest-runner
python -m pip install ruff==0.9.4 pytest pytest-cov pytest-runner
pip install -r requirements/requirements.txt
- name: Cache tiatoolbox static assets
uses: actions/cache@v3
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
- mdformat-black
- mdformat-myst
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.21
rev: 0.7.22
hooks:
- id: mdformat
# Optionally add plugins
Expand Down 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.8.6
rev: v0.9.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
4 changes: 3 additions & 1 deletion pre-commit/notebook_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def check_notebook(
for line_num, line in enumerate(cell["source"]):
new_line = replace_line(line, to_ref, replacements)
if new_line != line:
print(f"{path.name}: Changed (cell {cell_num+1}, line {line_num+1})")
print(
f"{path.name}: Changed (cell {cell_num + 1}, line {line_num + 1})"
)
changed = True
cell["source"][line_num] = new_line
return changed, notebook
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.8.2 # This will be updated by pre-commit bot to latest version
ruff==0.9.4 # This will be updated by pre-commit bot to latest version
toml>=0.10.2
twine>=4.0.1
wheel>=0.37.1
6 changes: 3 additions & 3 deletions tests/models/test_multi_task_segmentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ def test_functionality_hovernetplus(remote_sample: Callable, tmp_path: Path) ->

assert len(inst_dict) > 0, "Must have some nuclei."
assert layer_map is not None, "Must have some layers."
assert (
layer_map.shape == required_dims
), "Output layer map dimensions must be same as the expected output shape"
assert layer_map.shape == required_dims, (
"Output layer map dimensions must be same as the expected output shape"
)


def test_functionality_hovernet(remote_sample: Callable, tmp_path: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_annotation_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
if TYPE_CHECKING: # pragma: no cover
from numbers import Number

from tiatoolbox.typing import Geometry
from tiatoolbox.type_hints import Geometry


sqlite3.enable_callback_tracebacks(True) # noqa: FBT003
Expand Down
2 changes: 1 addition & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def raise_source_exception(
for n, line in enumerate(source.splitlines())
]
if source_offset:
source_lines.insert(source_lineno, f"{' '*(source_offset+3)}^ {message}")
source_lines.insert(source_lineno, f"{' ' * (source_offset + 3)}^ {message}")
annotated_source = "\n".join(source_lines)
exception = type(exception) if exception else SyntaxError
msg = f"{rel_path}:{file_lineno}: {message}\n{annotated_source}"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_patch_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)

if TYPE_CHECKING:
from tiatoolbox.typing import IntPair, Resolution, Units
from tiatoolbox.type_hints import IntPair, Resolution, Units


def read_points_patches(
Expand Down
6 changes: 3 additions & 3 deletions tests/test_tileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test_change_overlay( # noqa: PLR0915
assert response.status_code == 200
assert response.content_type == "text/html; charset=utf-8"
# check that the overlay has been correctly added
lname = f"layer{len(empty_app.pyramids[session_id])-1}"
lname = f"layer{len(empty_app.pyramids[session_id]) - 1}"
layer = empty_app.pyramids[session_id][lname]
assert layer.wsi.info.file_path == overlay_path

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from tiatoolbox.utils.transforms import locsize2bounds

if TYPE_CHECKING:
from tiatoolbox.typing import IntBounds
from tiatoolbox.type_hints import IntBounds

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

Expand Down
2 changes: 1 addition & 1 deletion tests/test_wsireader.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import requests
from openslide import OpenSlide

from tiatoolbox.typing import IntBounds, IntPair
from tiatoolbox.type_hints import IntBounds, IntPair
from tiatoolbox.wsicore.wsimeta import WSIMeta

# -------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tiatoolbox/annotation/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
py_regexp,
)
from tiatoolbox.enums import GeometryType
from tiatoolbox.typing import CallablePredicate, CallableSelect, Geometry
from tiatoolbox.type_hints import CallablePredicate, CallableSelect, Geometry

if TYPE_CHECKING: # pragma: no cover
from tiatoolbox.typing import (
from tiatoolbox.type_hints import (
Predicate,
Properties,
QueryGeometry,
Expand Down
3 changes: 1 addition & 2 deletions tiatoolbox/models/architecture/hovernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ def __init__(

if mode not in ["original", "fast"]:
msg = (
f"Invalid mode {mode} for HoVerNet. "
f"Only support `original` or `fast`."
f"Invalid mode {mode} for HoVerNet. Only support `original` or `fast`."
)
raise ValueError(
msg,
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/models/architecture/nuclick.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tiatoolbox.models.models_abc import ModelABC

if TYPE_CHECKING: # pragma: no cover
from tiatoolbox.typing import IntPair
from tiatoolbox.type_hints import IntPair

bn_axis = 1

Expand Down
8 changes: 0 additions & 8 deletions tiatoolbox/models/architecture/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ def compile_model(
logger.warning(msg=msg)
return model

# This check will be removed when torch.compile is supported in Python 3.12+
if sys.version_info > (3, 12): # pragma: no cover
msg = "torch-compile is currently not supported in Python 3.12+."
logger.warning(
msg=msg,
)
return model

if isinstance( # pragma: no cover
model,
torch._dynamo.eval_frame.OptimizedModule, # skipcq: PYL-W0212 # noqa: SLF001
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/models/dataset/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import torch
from PIL.Image import Image

from tiatoolbox.typing import IntPair, Resolution, Units
from tiatoolbox.type_hints import IntPair, Resolution, Units


class _TorchPreprocCaller:
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/models/engine/multi_task_segmentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
if TYPE_CHECKING: # pragma: no cover
import torch

from tiatoolbox.typing import IntBounds
from tiatoolbox.type_hints import IntBounds


# Python is yet to be able to natively pickle Object method/static method.
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/models/engine/patch_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from tiatoolbox.wsicore.wsireader import VirtualWSIReader, WSIReader

if TYPE_CHECKING: # pragma: no cover
from tiatoolbox.typing import IntPair, Resolution, Units
from tiatoolbox.type_hints import IntPair, Resolution, Units


class IOPatchPredictorConfig(IOSegmentorConfig):
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/models/engine/semantic_segmentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
if TYPE_CHECKING: # pragma: no cover
from multiprocessing.managers import Namespace

from tiatoolbox.typing import IntPair, Resolution, Units
from tiatoolbox.type_hints import IntPair, Resolution, Units


def _estimate_canvas_parameters(
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/tools/patchextraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from pandas import DataFrame

from tiatoolbox.annotation.storage import AnnotationStore
from tiatoolbox.typing import Resolution, Units
from tiatoolbox.type_hints import Resolution, Units


def validate_shape(shape: np.ndarray) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/tools/registration/wsi_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tiatoolbox.wsicore.wsireader import VirtualWSIReader, WSIReader

if TYPE_CHECKING: # pragma: no cover
from tiatoolbox.typing import IntBounds, Resolution, Units
from tiatoolbox.type_hints import IntBounds, Resolution, Units

RGB_IMAGE_DIM = 3
BIN_MASK_DIM = 2
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tiatoolbox/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)

if TYPE_CHECKING: # pragma: no cover
from tiatoolbox.typing import IntBounds, NumpyPadLiteral
from tiatoolbox.type_hints import IntBounds, NumpyPadLiteral

PADDING_TO_BOUNDS = np.array([-1, -1, 1, 1])
"""
Expand Down
3 changes: 1 addition & 2 deletions tiatoolbox/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ def load_stain_matrix(stain_matrix_input: np.ndarray | PathLike) -> np.ndarray:
_, __, suffixes = split_path_name_ext(stain_matrix_input)
if suffixes[-1] not in [".csv", ".npy"]:
msg = (
"If supplying a path to a stain matrix, "
"use either a npy or a csv file"
"If supplying a path to a stain matrix, use either a npy or a csv file"
)
raise FileNotSupportedError(
msg,
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/visualization/bokeh_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ def segment_on_box() -> None:
# Make a mask defining the box
thumb = UI["vstate"].wsi.slide_thumbnail()
conv_mpp = UI["vstate"].dims[0] / thumb.shape[1]
msg = f'box tl: {UI["box_source"].data["x"][0]}, {UI["box_source"].data["y"][0]}'
msg = f"box tl: {UI['box_source'].data['x'][0]}, {UI['box_source'].data['y'][0]}"
logger.info(msg)
x = round(
(UI["box_source"].data["x"][0] - 0.5 * UI["box_source"].data["width"][0])
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/visualization/tileserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__( # noqa: PLR0915
if isinstance(layers, list):
layers_dict = {"slide": layers[0]}
for i, p in enumerate(layers[1:]):
layers_dict[f"layer-{i+1}"] = p
layers_dict[f"layer-{i + 1}"] = p
layers = layers_dict
# Set up the layer dict.
meta = None
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/wsicore/wsimeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
if TYPE_CHECKING: # pragma: no cover
from collections.abc import Mapping, Sequence

from tiatoolbox.typing import Resolution, Units
from tiatoolbox.type_hints import Resolution, Units


class WSIMeta:
Expand Down
9 changes: 8 additions & 1 deletion tiatoolbox/wsicore/wsireader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@

import glymur

from tiatoolbox.typing import Bounds, IntBounds, IntPair, NumPair, Resolution, Units
from tiatoolbox.type_hints import (
Bounds,
IntBounds,
IntPair,
NumPair,
Resolution,
Units,
)
from tiatoolbox.wsicore.metadata.ngff import Multiscales

pixman_warning()
Expand Down