diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 5235ebe28..7250d6d6b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -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.7.4 pytest pytest-cov pytest-runner + python -m pip install ruff==0.8.1 pytest pytest-cov pytest-runner pip install -r requirements/requirements.txt - name: Cache tiatoolbox static assets uses: actions/cache@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 437d91c96..bc49a4459 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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.7.4 + rev: v0.8.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/benchmarks/annotation_store.ipynb b/benchmarks/annotation_store.ipynb index b6008e781..25ff75f87 100644 --- a/benchmarks/annotation_store.ipynb +++ b/benchmarks/annotation_store.ipynb @@ -195,7 +195,7 @@ "from typing import TYPE_CHECKING, Any\n", "\n", "import numpy as np\n", - "from IPython.display import display\n", + "from IPython.display import display_svg\n", "from matplotlib import patheffects\n", "from matplotlib import pyplot as plt\n", "from shapely import affinity\n", @@ -444,7 +444,7 @@ ], "source": [ "for n in range(4):\n", - " display(cell_polygon(xy=(0, 0), n_points=20, repeat_first=False, seed=n))" + " display_svg(cell_polygon(xy=(0, 0), n_points=20, repeat_first=False, seed=n))" ] }, { diff --git a/requirements/requirements_dev.txt b/requirements/requirements_dev.txt index a1543d522..ff66ca0fa 100644 --- a/requirements/requirements_dev.txt +++ b/requirements/requirements_dev.txt @@ -10,7 +10,7 @@ pytest>=7.2.0 pytest-cov>=4.0.0 pytest-runner>=6.0 pytest-xdist[psutil] -ruff==0.7.4 # This will be updated by pre-commit bot to latest version +ruff==0.8.1 # This will be updated by pre-commit bot to latest version toml>=0.10.2 twine>=4.0.1 wheel>=0.37.1 diff --git a/tiatoolbox/annotation/__init__.py b/tiatoolbox/annotation/__init__.py index f99cf4628..99dfa07ec 100644 --- a/tiatoolbox/annotation/__init__.py +++ b/tiatoolbox/annotation/__init__.py @@ -8,4 +8,4 @@ SQLiteStore, ) -__all__ = ["AnnotationStore", "SQLiteStore", "DictionaryStore", "Annotation"] +__all__ = ["Annotation", "AnnotationStore", "DictionaryStore", "SQLiteStore"] diff --git a/tiatoolbox/annotation/storage.py b/tiatoolbox/annotation/storage.py index 420e94085..058b65b71 100644 --- a/tiatoolbox/annotation/storage.py +++ b/tiatoolbox/annotation/storage.py @@ -1371,11 +1371,13 @@ def bquery( for key, annotation in self.items() if ( query_geometry is None - or isinstance(query_geometry, (Polygon, Point, LineString)) - and Polygon.from_bounds(*annotation.geometry.bounds).intersects( - Polygon.from_bounds(*query_geometry.bounds), + or ( + isinstance(query_geometry, (Polygon, Point, LineString)) + and Polygon.from_bounds(*annotation.geometry.bounds).intersects( + Polygon.from_bounds(*query_geometry.bounds), + ) + and self._eval_where(where, annotation.properties) ) - and self._eval_where(where, annotation.properties) ) } diff --git a/tiatoolbox/models/__init__.py b/tiatoolbox/models/__init__.py index ab37165ff..39d1441ce 100644 --- a/tiatoolbox/models/__init__.py +++ b/tiatoolbox/models/__init__.py @@ -25,14 +25,14 @@ ) __all__ = [ + "SCCNN", "HoVerNet", "HoVerNetPlus", "IDaRS", "MapDe", "MicroNet", - "NuClick", - "SCCNN", "MultiTaskSegmentor", + "NuClick", "NucleusInstanceSegmentor", "PatchPredictor", "SemanticSegmentor", diff --git a/tiatoolbox/models/architecture/__init__.py b/tiatoolbox/models/architecture/__init__.py index 6fac9b08b..a2c33dc4f 100644 --- a/tiatoolbox/models/architecture/__init__.py +++ b/tiatoolbox/models/architecture/__init__.py @@ -18,7 +18,7 @@ from tiatoolbox.models.models_abc import IOConfigABC -__all__ = ["get_pretrained_model", "fetch_pretrained_weights"] +__all__ = ["fetch_pretrained_weights", "get_pretrained_model"] PRETRAINED_INFO = rcParam["pretrained_model_info"] diff --git a/tiatoolbox/utils/__init__.py b/tiatoolbox/utils/__init__.py index e29f28c12..da32b92ea 100644 --- a/tiatoolbox/utils/__init__.py +++ b/tiatoolbox/utils/__init__.py @@ -20,10 +20,10 @@ ) __all__ = [ + "download_data", "imread", "imwrite", - "save_yaml", "save_as_json", - "download_data", + "save_yaml", "unzip_data", ] diff --git a/tiatoolbox/utils/visualization.py b/tiatoolbox/utils/visualization.py index 817485711..4aa0746b8 100644 --- a/tiatoolbox/utils/visualization.py +++ b/tiatoolbox/utils/visualization.py @@ -914,26 +914,27 @@ def _set_mapper( def __setattr__( self: AnnotationRenderer, - __name: str, - __value: str | list | dict | None, + name: str, + value: str | list | dict | None, + /, ) -> None: """Set attribute each time an attribute is set.""" - if __name == "mapper": + if name == "mapper": # save a more readable version of the mapper too - _ = self._set_mapper(__value) + _ = self._set_mapper(value) return - if __name == "blur_radius" and isinstance(__value, int): + if name == "blur_radius" and isinstance(value, int): # need to change additional settings - if __value > 0: - self.__dict__["blur"] = ImageFilter.GaussianBlur(__value) + if value > 0: + self.__dict__["blur"] = ImageFilter.GaussianBlur(value) self.__dict__["edge_thickness"] = 0 else: self.__dict__["blur"] = None self.__dict__["edge_thickness"] = self.__dict__["edge_thickness_old"] - elif __name == "edge_thickness": - self.__dict__["edge_thickness_old"] = __value + elif name == "edge_thickness": + self.__dict__["edge_thickness_old"] = value - self.__dict__[__name] = __value + self.__dict__[name] = value def render_annotations( self: AnnotationRenderer, diff --git a/tiatoolbox/visualization/bokeh_app/main.py b/tiatoolbox/visualization/bokeh_app/main.py index 4e4195558..b80f19138 100644 --- a/tiatoolbox/visualization/bokeh_app/main.py +++ b/tiatoolbox/visualization/bokeh_app/main.py @@ -308,10 +308,8 @@ def get_mapper_for_prop(prop: str, mapper_type: str = "auto") -> str | dict[str, prop_vals = json.loads(resp.text) # If auto, guess what cmap should be if ( - (len(prop_vals) > MAX_CAT or len(prop_vals) == 0) - and mapper_type == "auto" - or mapper_type == "continuous" - ): + (len(prop_vals) > MAX_CAT or len(prop_vals) == 0) and mapper_type == "auto" + ) or mapper_type == "continuous": cmap = ( "viridis" if UI["cmap_select"].value == "dict" else UI["cmap_select"].value ) @@ -647,24 +645,25 @@ def __init__(self: ViewerState, slide_path: str | Path) -> None: def __setattr__( self: ViewerState, - __name: str, - __value: Any, # noqa: ANN401 + name: str, + value: Any, # noqa: ANN401 + /, ) -> None: """Set an attribute of the viewer state.""" - if __name == "types": - self.__dict__["mapper"] = make_color_dict(__value) + if name == "types": + self.__dict__["mapper"] = make_color_dict(value) self.__dict__["colors"] = list(self.mapper.values()) if self.cprop == "type": update_mapper() # We will standardise the types to strings, keep dict of originals - self.__dict__["orig_types"] = {str(x): x for x in __value} - __value = [str(x) for x in __value] + self.__dict__["orig_types"] = {str(x): x for x in value} + value = [str(x) for x in value] - if __name == "wsi": - z = ZoomifyGenerator(__value, tile_size=256) + if name == "wsi": + z = ZoomifyGenerator(value, tile_size=256) self.__dict__["num_zoom_levels"] = z.level_count - self.__dict__[__name] = __value + self.__dict__[name] = value # endregion diff --git a/tiatoolbox/wsicore/__init__.py b/tiatoolbox/wsicore/__init__.py index 2d3bdfa75..f93108a97 100644 --- a/tiatoolbox/wsicore/__init__.py +++ b/tiatoolbox/wsicore/__init__.py @@ -7,6 +7,6 @@ # Top level imports __all__ = [ - "WSIReader", "WSIMeta", + "WSIReader", ]