Skip to content

Commit

Permalink
more ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslamb committed Aug 22, 2024
1 parent 39d034b commit ed5cb9e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/python/gds_whole_slide/lz4_nvcomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
21 changes: 12 additions & 9 deletions python/cucim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
Expand Down
14 changes: 8 additions & 6 deletions python/cucim/src/cucim/skimage/_shared/version_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions python/cucim/src/cucim/skimage/_vendored/pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions python/cucim/src/cucim/skimage/_vendored/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion python/cucim/src/cucim/skimage/transform/_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 1 addition & 3 deletions python/cucim/src/localtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit ed5cb9e

Please sign in to comment.