Skip to content

Commit

Permalink
style: update codebase with fixes for new ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed Aug 17, 2023
1 parent 5cb4832 commit f2a0520
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 300 deletions.
1 change: 0 additions & 1 deletion caput/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import weakref

import numpy as np

from cachetools import LRUCache


Expand Down
41 changes: 15 additions & 26 deletions caput/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"""
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -59,7 +60,6 @@

from yaml.loader import SafeLoader


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -138,7 +138,7 @@ def _from_config(self, obj, config):
val = self.proptype(config[self.key])
except TypeError as e:
raise CaputConfigError(
"Can't read value of '%s' as %s: %s" % (self.key, self.proptype, e),
f"Can't read value of '{self.key}' as {self.proptype}: {e}",
location=config,
) from e
obj.__dict__[self.propname] = val
Expand Down Expand Up @@ -259,9 +259,7 @@ def _prop(val):

return ensure_unix(val)

prop = Property(proptype=_prop, default=default)

return prop
return Property(proptype=_prop, default=default)


def float_in_range(start, end, default=None):
Expand Down Expand Up @@ -292,13 +290,11 @@ def _prop(val):
val = float(val)

if val < start or val > end:
raise CaputConfigError("Input %f not in range [%f, %f]" % (val, start, end))
raise CaputConfigError(f"Input {val:f} not in range [{start:f}, {end:f}]")

return val

prop = Property(proptype=_prop, default=default)

return prop
return Property(proptype=_prop, default=default)


def enum(options, default=None):
Expand Down Expand Up @@ -339,9 +335,7 @@ def _prop(val):
if default is not None and default not in options:
raise ValueError(f"Default value {default} must be in {options} (or None)")

prop = Property(proptype=_prop, default=default)

return prop
return Property(proptype=_prop, default=default)


def list_type(type_=None, length=None, maxlength=None, default=None):
Expand Down Expand Up @@ -411,13 +405,10 @@ def _prop(val):
_prop(default)
except CaputConfigError as e:
raise ValueError(
"Default value %s does not satisfy property requirements: %s"
% (default, repr(e))
f"Default value {default} does not satisfy property requirements: {e!r}"
) from e

prop = Property(proptype=_prop, default=default)

return prop
return Property(proptype=_prop, default=default)


def logging_config(default=None):
Expand Down Expand Up @@ -476,9 +467,7 @@ def _prop(config):
checked_config[key] = level
return checked_config

prop = Property(proptype=_prop, default=default)

return prop
return Property(proptype=_prop, default=default)


def file_format(default: str | fileformats.FileFormat | None = None) -> Property:
Expand Down Expand Up @@ -522,7 +511,7 @@ def _prop(val):

if not isinstance(val, str):
raise CaputConfigError(
f"Input {repr(val)} is of type {type(val).__name__} (expected str or None)."
f"Input {val!r} is of type {type(val).__name__} (expected str or None)."
)

val = val.lower()
Expand All @@ -532,12 +521,12 @@ def _prop(val):
if val == "zarr":
return fileformats.Zarr

raise CaputConfigError(f"Input {repr(val)} needs to be one of {options})")
raise CaputConfigError(f"Input {val!r} needs to be one of {options})")

if default is not None and (
(not isinstance(default, str)) or (default.lower() not in options)
):
raise CaputConfigError(f"Default value {repr(default)} must be in {options}")
raise CaputConfigError(f"Default value {default!r} must be in {options}")

return Property(proptype=_prop, default=default)

Expand Down Expand Up @@ -591,10 +580,10 @@ def __init__(self, message, file_=None, location=None):
def __str__(self):
location = ""
if self.line is not None:
location = "\nError in block starting at L{}".format(self.line)
location = f"\nError in block starting at L{self.line}"
if self.file is not None:
location = "{} ({})".format(location, self.file)
return "{}{}".format(self.message, location)
location = f"{location} ({self.file})"
return f"{self.message}{location}"


if __name__ == "__main__":
Expand Down
11 changes: 4 additions & 7 deletions caput/fileformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
zarr_available = True

try:
from bitshuffle.h5 import H5FILTER, H5_COMPRESS_LZ4
import numcodecs
from bitshuffle.h5 import H5_COMPRESS_LZ4, H5FILTER
except ModuleNotFoundError as e:
logger.debug(
f"Install with 'compression' extra_require to use bitshuffle/numcodecs compression filters.: {e}"
Expand Down Expand Up @@ -154,12 +154,9 @@ def compression_kwargs(compression=None, compression_opts=None, compressor=None)
blocksize=int(blocksize) if blocksize is not None else None,
)
}
else:
raise ValueError(
f"Compression filter not supported in zarr: {compression}"
)
else:
return {"compressor": compressor}
raise ValueError(f"Compression filter not supported in zarr: {compression}")

return {"compressor": compressor}


class ZarrProcessSynchronizer:
Expand Down
Loading

0 comments on commit f2a0520

Please sign in to comment.