Skip to content

Commit

Permalink
Merge branch 'develop' into dev-define-engines-abc
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneahmed authored Mar 19, 2024
2 parents 7d3b530 + dc897e2 commit 2e522be
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 231 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/mypy-type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ jobs:
tiatoolbox/tools/stainextract.py \
tiatoolbox/tools/pyramid.py \
tiatoolbox/tools/tissuemask.py \
tiatoolbox/tools/graph.py
tiatoolbox/tools/graph.py \
tiatoolbox/tools/stainnorm.py \
tiatoolbox/tools/stainaugment.py \
tiatoolbox/tools/patchextraction.py
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.3.2 pytest pytest-cov pytest-runner
python -m pip install ruff==0.3.3 pytest pytest-cov pytest-runner
pip install -r requirements/requirements.txt
- name: Cache tiatoolbox static assets
uses: actions/cache@v3
Expand Down
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,13 @@ repos:
- id: rst-backticks # Detect common mistake of using single backticks when writing rst.
- id: rst-directive-colons # Detect mistake of rst directive not ending with double colon.
- id: rst-inline-touching-normal # Detect mistake of inline code touching normal text in rst.
- repo: https://github.com/psf/black
rev: 24.2.0 # Replace with any tag/version: https://github.com/psf/black/tags
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.+
additional_dependencies: ['click==8.0.4'] # Currently >8.0.4 breaks black
- id: black-jupyter
language: python
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.2
rev: v0.3.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [python, pyi, jupyter]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@
<a href="https://codecov.io/gh/TissueImageAnalytics/tiatoolbox">
<img src="https://codecov.io/gh/TissueImageAnalytics/tiatoolbox/branch/master/graph/badge.svg?token=7UZEMacQHm" alt="Code Coverage"/>
</a>
<br>
<br>
<a href="https://github.com/psf/black">
<img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code Style black"/>
</a>
<a href="https://github.com/astral-sh/ruff">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Code Style black"/>
</a>
Expand Down
11 changes: 7 additions & 4 deletions benchmarks/annotation_store_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,13 @@ def main(
if tracker_filepath.is_file():
tracker_filepath.unlink()

with NamedTemporaryFile(mode="w+") as temp_file, memray.Tracker(
tracker_filepath,
native_traces=True,
follow_fork=True,
with (
NamedTemporaryFile(mode="w+") as temp_file,
memray.Tracker(
tracker_filepath,
native_traces=True,
follow_fork=True,
),
):
io = ":memory:" if in_memory else temp_file # Backing (memory/disk)
print(f"Storing {size[0] * size[1]} cells")
Expand Down
89 changes: 47 additions & 42 deletions examples/06-semantic-segmentation.ipynb

Large diffs are not rendered by default.

139 changes: 82 additions & 57 deletions examples/07-advanced-modeling.ipynb

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
[tool.pytest.ini_options]
collect_ignore = ["setup.py", "benchmark/"]

[tool.black]
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.venv
| _build
| buck-out
| build
| dist
| docs
| data
| setup.py
)/
'''
include = '\.pyi?$'
line-length = 88
target-version = ['py37', 'py38', 'py39', 'py310']


[tool.coverage.run]
branch = true
source = ['tiatoolbox']
Expand Down Expand Up @@ -126,7 +104,8 @@ lint.select = [
"SLOT", # flake8-slots
"ASYNC", # flake8-async
]
lint.ignore = []
# Ignore rules which conflict with ruff formatter.
lint.ignore = ["COM812", "ISC001",]
# Allow Ruff to discover `*.ipynb` files.
include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"]

Expand Down Expand Up @@ -172,6 +151,27 @@ convention = "google"
[tool.ruff.lint.pylint]
max-args = 10

[tool.ruff.format]
exclude = [
".eggs",
".git",
".ruff_cache",
".svn",
".venv",
"__pypackages__",
"_build",
"build",
"dist",
"venv",
".hg",
".mypy_cache",
"buck-out",
"docs",
"data",
"setup.py",
]
skip-magic-trailing-comma = false

[tool.mypy]
ignore_missing_imports = true
python_version = 3.9
3 changes: 1 addition & 2 deletions requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-r requirements.txt
-r ../docs/requirements.txt
black>=23.3.0
coverage>=7.0.0
docutils>=0.18.1
jinja2>=3.0.3, <3.1.0
Expand All @@ -12,7 +11,7 @@ pytest>=7.2.0
pytest-cov>=4.0.0
pytest-runner>=6.0
pytest-xdist[psutil]
ruff==0.3.2 # This will be updated by pre-commit bot to latest version
ruff==0.3.3 # This will be updated by pre-commit bot to latest version
toml>=0.10.2
twine>=4.0.1
wheel>=0.37.1
3 changes: 1 addition & 2 deletions tests/test_annotation_stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,7 @@ def test_query_predicate_callable(
store.patch(keys[0], properties={"class": 123})
results = store.query(
# (0, 0, 1024, 1024), # noqa: ERA001
where=lambda props: props.get("class")
== 123,
where=lambda props: props.get("class") == 123,
)
assert len(results) == 1

Expand Down
1 change: 1 addition & 0 deletions tests/test_tiatoolbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Pytests for `tiatoolbox` package."""

from __future__ import annotations

from click.testing import CliRunner
Expand Down
7 changes: 3 additions & 4 deletions tiatoolbox/annotation/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2177,8 +2177,7 @@ def __init__(
# Check if the path is a non-empty file
exists = (
# Use 'and' to short-circuit
self.path.is_file()
and self.path.stat().st_size > 0
self.path.is_file() and self.path.stat().st_size > 0
)
self.cons = {}
self.con.execute("BEGIN")
Expand Down Expand Up @@ -2478,7 +2477,7 @@ def compile_options() -> list[str]:
with sqlite3.connect(":memory:") as conn:
conn.enable_load_extension(True) # noqa: FBT003
options = conn.execute("pragma compile_options").fetchall()
return [opt for opt, in options]
return [opt for (opt,) in options]

def close(self: SQLiteStore) -> None:
"""Closes :class:`SQLiteStore` from file pointer or path."""
Expand Down Expand Up @@ -2861,7 +2860,7 @@ def iquery(
for key, properties in cur.fetchall()
if where(json.loads(properties))
]
return [key for key, in cur.fetchall()]
return [key for (key,) in cur.fetchall()]

def query(
self: SQLiteStore,
Expand Down
1 change: 1 addition & 0 deletions tiatoolbox/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# skipcq: PTC-W6004 # noqa: ERA001
"""Package to define datasets available to download via TIAToolbox."""

from __future__ import annotations

import importlib.resources as importlib_resources
Expand Down
4 changes: 3 additions & 1 deletion tiatoolbox/models/engine/multi_task_segmentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# ***** END GPL LICENSE BLOCK *****

"""This module enables multi-task segmentors."""

from __future__ import annotations

import shutil
Expand Down Expand Up @@ -156,7 +157,8 @@ def _process_tile_predictions(
sem_maps = [out for out in out_dicts if isinstance(out, np.ndarray)]
# Some output maps may not be aggregated into a single map - combine these
sem_maps = [
np.argmax(s, axis=-1) if s.ndim == 3 else s for s in sem_maps # noqa: PLR2004
np.argmax(s, axis=-1) if s.ndim == 3 else s # noqa: PLR2004
for s in sem_maps
]

new_inst_dicts, remove_insts_in_origs = [], []
Expand Down
Loading

0 comments on commit 2e522be

Please sign in to comment.