From ed5cb9e93778bd4c5cd23a8e4b82169a69bcffcb Mon Sep 17 00:00:00 2001 From: James Lamb Date: Thu, 22 Aug 2024 13:11:24 -0500 Subject: [PATCH] more ruff fixes --- .pre-commit-config.yaml | 2 +- examples/python/gds_whole_slide/lz4_nvcomp.py | 2 +- python/cucim/pyproject.toml | 21 +++++++++++-------- .../skimage/_shared/version_requirements.py | 14 +++++++------ .../cucim/src/cucim/skimage/_vendored/pad.py | 4 +--- .../cucim/src/cucim/skimage/_vendored/time.py | 4 +--- .../skimage/metrics/_structural_similarity.py | 2 +- .../src/cucim/skimage/transform/_geometric.py | 2 +- python/cucim/src/localtest.py | 4 +--- 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cdc6fcba8..37a56402d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: black args: ["--config", "python/cucim/pyproject.toml"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.3 + rev: v0.6.1 hooks: - id: ruff types_or: [python, pyi] diff --git a/examples/python/gds_whole_slide/lz4_nvcomp.py b/examples/python/gds_whole_slide/lz4_nvcomp.py index c4b519909..a02d6c962 100644 --- a/examples/python/gds_whole_slide/lz4_nvcomp.py +++ b/examples/python/gds_whole_slide/lz4_nvcomp.py @@ -146,7 +146,7 @@ def decode(self, buf, out=None): return ndarray_copy(decompressed, out) def __repr__(self): - r = "%s" % type(self).__name__ + r = f"{type(self).__name__}" return r diff --git a/python/cucim/pyproject.toml b/python/cucim/pyproject.toml index 705ec6e8e..afd1e05d7 100644 --- a/python/cucim/pyproject.toml +++ b/python/cucim/pyproject.toml @@ -147,13 +147,6 @@ filterwarnings = [ ] [tool.ruff] -# see: https://docs.astral.sh/ruff/rules/ -select = ["E", "F", "W", "I", "UP"] -ignore = [ - # (pyupgrade) Use `X | Y` in `isinstance` call instead of `(X, Y)` - "UP038", -] -fixable = ["ALL"] exclude = [ # TODO: Remove this in a follow-up where we fix __all__. ".tox", @@ -166,14 +159,24 @@ exclude = [ "docs/source/conf.py", "docs/source/ext", "__init__.py", + "python/cucim/src/cucim/skimage/_vendored", ] line-length = 80 fix = true -[tool.ruff.per-file-ignores] +[tool.ruff.lint] +# see: https://docs.astral.sh/ruff/rules/ +select = ["E", "F", "W", "I", "UP"] +ignore = [ + # (pyupgrade) Use `X | Y` in `isinstance` call instead of `(X, Y)` + "UP038", +] +fixable = ["ALL"] + +[tool.ruff.lint.per-file-ignores] # "src/cucim/skimage/util/tests/test_shape.py" = ["E201", "E202"] -[tool.ruff.isort] +[tool.ruff.lint.isort] combine-as-imports = true force-single-line = false known-first-party = ["cucim"] diff --git a/python/cucim/src/cucim/skimage/_shared/version_requirements.py b/python/cucim/src/cucim/skimage/_shared/version_requirements.py index 17c7afcc5..e5bf41e36 100644 --- a/python/cucim/src/cucim/skimage/_shared/version_requirements.py +++ b/python/cucim/src/cucim/skimage/_shared/version_requirements.py @@ -79,9 +79,12 @@ def is_installed(name, version=None): symb = version[: match.start()] if not symb: symb = "=" - assert symb in (">=", ">", "=", "<"), ( - "Invalid version condition '%s'" % symb - ) + assert symb in ( + ">=", + ">", + "=", + "<", + ), f"Invalid version condition '{symb}'" version = version[match.start() :] return _check_version(actver, version, symb) @@ -115,10 +118,9 @@ def func_wrapped(*args, **kwargs): if is_installed(name, version): return obj(*args, **kwargs) else: - msg = '"%s" in "%s" requires "%s' - msg = msg % (obj, obj.__module__, name) + msg = f'"{obj}" in "{obj.__module__}" requires "{name}"' if version is not None: - msg += " %s" % version + msg += f" {version}" raise ImportError(msg + '"') return func_wrapped diff --git a/python/cucim/src/cucim/skimage/_vendored/pad.py b/python/cucim/src/cucim/skimage/_vendored/pad.py index 249a2c1ed..a3d22a7a0 100644 --- a/python/cucim/src/cucim/skimage/_vendored/pad.py +++ b/python/cucim/src/cucim/skimage/_vendored/pad.py @@ -666,9 +666,7 @@ def pad(array, pad_width, mode="constant", **kwargs): raise ValueError(f"mode '{mode}' is not supported") if unsupported_kwargs: raise ValueError( - "unsupported keyword arguments for mode '{}': {}".format( - mode, unsupported_kwargs - ) + f"unsupported keyword arguments for mode '{mode}': {unsupported_kwargs}" ) if _use_elementwise_kernel(array, mode, kwargs): diff --git a/python/cucim/src/cucim/skimage/_vendored/time.py b/python/cucim/src/cucim/skimage/_vendored/time.py index 5ec1156ce..e55027212 100644 --- a/python/cucim/src/cucim/skimage/_vendored/time.py +++ b/python/cucim/src/cucim/skimage/_vendored/time.py @@ -36,9 +36,7 @@ def _to_str_per_item(device_name, t): s = f" {device_name}:{t_us.mean():9.03f} us" if t.size > 1: - s += " +/-{:6.03f} (min:{:9.03f} / max:{:9.03f}) us".format( - t_us.std(), t_us.min(), t_us.max() - ) + s += f" +/-{t_us.std():6.03f} (min:{t_us.min():9.03f} / max:{t_us.max():9.03f}) us" return s def to_str(self, show_gpu=False): diff --git a/python/cucim/src/cucim/skimage/metrics/_structural_similarity.py b/python/cucim/src/cucim/skimage/metrics/_structural_similarity.py index 04ad88ab2..d89e28c70 100644 --- a/python/cucim/src/cucim/skimage/metrics/_structural_similarity.py +++ b/python/cucim/src/cucim/skimage/metrics/_structural_similarity.py @@ -269,7 +269,7 @@ def structural_similarity( if cp.issubdtype(im1.dtype, cp.integer) and (im1.dtype != cp.uint8): warn( "Setting data_range based on im1.dtype. " - + ("data_range = %.0f. " % data_range) + + f"data_range = {data_range:.0f}. " + "Please specify data_range explicitly to avoid mistakes.", stacklevel=2, ) diff --git a/python/cucim/src/cucim/skimage/transform/_geometric.py b/python/cucim/src/cucim/skimage/transform/_geometric.py index 25347db26..47cc133b8 100644 --- a/python/cucim/src/cucim/skimage/transform/_geometric.py +++ b/python/cucim/src/cucim/skimage/transform/_geometric.py @@ -1936,7 +1936,7 @@ def estimate_transform(ttype, src, dst, *args, **kwargs): ttype = ttype.lower() if ttype not in TRANSFORMS: raise ValueError( - "the transformation type '%s' is not" "implemented" % ttype + f"the transformation type '{ttype}' is not" "implemented" ) tform = TRANSFORMS[ttype](dimensionality=src.shape[1]) diff --git a/python/cucim/src/localtest.py b/python/cucim/src/localtest.py index f5794dd43..c80949f7b 100644 --- a/python/cucim/src/localtest.py +++ b/python/cucim/src/localtest.py @@ -148,7 +148,5 @@ def load_tile_cucim(slide, start_loc, tile_size): print("Total time (OpenSlide):", openslide_tot_time) print("Total time (cuCIM):", cucim_tot_time) print( - "Average performance gain (OpenSlide/cuCIM): {}".format( - openslide_tot_time / cucim_tot_time - ) + f"Average performance gain (OpenSlide/cuCIM): {openslide_tot_time / cucim_tot_time}" # noqa: E501 )