From 1f1baec91db82a1c5143d7d6e7e84d5cb373e3e6 Mon Sep 17 00:00:00 2001 From: jp-dark Date: Fri, 13 Mar 2026 11:09:11 -0400 Subject: [PATCH] Switch from black to ruff and update line-length --- .pre-commit-config.yaml | 8 ++------ pyproject.toml | 2 ++ python-spec/requirements-py3.12-lint.txt | 1 - python-spec/src/somacore/__init__.py | 1 - python-spec/src/somacore/collection.py | 4 +--- python-spec/src/somacore/data.py | 4 +--- python-spec/src/somacore/options.py | 8 ++------ python-spec/src/somacore/query/axis.py | 7 ++----- python-spec/src/somacore/spatial.py | 8 ++------ 9 files changed, 12 insertions(+), 31 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ec79ae65..584ceae7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,8 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.11.10 hooks: - - id: ruff + - id: ruff-check + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy # This mypy step is not perfect; in the interest of not reproducing @@ -28,11 +29,6 @@ repos: - id: mypy additional_dependencies: [attrs] - - repo: https://github.com/psf/black - rev: "25.1.0" - hooks: - - id: black - - repo: https://github.com/hukkin/mdformat rev: 0.7.22 # Use the ref you want to point at hooks: diff --git a/pyproject.toml b/pyproject.toml index 7e07880e..be6b1082 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,8 @@ tag_regex = '^python-(?P[vV]?\d+(?:\.\d+){0,2}[^\+]*)(?:\+.*)?$' lint.extend-select = ["I"] target-version = "py39" fix = true +preview = true # enables "beta" rules: https://docs.astral.sh/ruff/preview/ +line-length = 120 [tool.ruff.lint.isort] force-single-line = true diff --git a/python-spec/requirements-py3.12-lint.txt b/python-spec/requirements-py3.12-lint.txt index 9ade3d92..8ffeb02e 100644 --- a/python-spec/requirements-py3.12-lint.txt +++ b/python-spec/requirements-py3.12-lint.txt @@ -1,7 +1,6 @@ anndata==0.11.3 array_api_compat==1.11.1 attrs==25.1.0 -black==25.1.0 cfgv==3.4.0 click==8.1.8 distlib==0.3.9 diff --git a/python-spec/src/somacore/__init__.py b/python-spec/src/somacore/__init__.py index 51876cf4..f0685940 100644 --- a/python-spec/src/somacore/__init__.py +++ b/python-spec/src/somacore/__init__.py @@ -67,7 +67,6 @@ "GeometryDataFrame", "PointCloudDataFrame", "BatchSize", - "IOfN", "ResultOrder", "AxisColumnNames", "AxisQuery", diff --git a/python-spec/src/somacore/collection.py b/python-spec/src/somacore/collection.py index 11f006d0..cc0209b6 100644 --- a/python-spec/src/somacore/collection.py +++ b/python-spec/src/somacore/collection.py @@ -219,9 +219,7 @@ def __setitem__(self, key: str, value: _Elem) -> None: """Sets an entry into this collection. See :meth:`set` for details.""" self.set(key, value) - def set( - self, key: str, value: _Elem, *, use_relative_uri: bool | None = None - ) -> Self: + def set(self, key: str, value: _Elem, *, use_relative_uri: bool | None = None) -> Self: """Sets an entry of this collection. Important note: Because parent objects may need to share diff --git a/python-spec/src/somacore/data.py b/python-spec/src/somacore/data.py index c5b09a52..7e6a7dd2 100644 --- a/python-spec/src/somacore/data.py +++ b/python-spec/src/somacore/data.py @@ -290,9 +290,7 @@ def create( """ ... - def resize( - self, newshape: Sequence[int | None], check_only: bool = False - ) -> StatusAndReason: + def resize(self, newshape: Sequence[int | None], check_only: bool = False) -> StatusAndReason: """Increases the shape of the array as specified. Lifecycle: maturing diff --git a/python-spec/src/somacore/options.py b/python-spec/src/somacore/options.py index 6e0b2a24..c42a12c8 100644 --- a/python-spec/src/somacore/options.py +++ b/python-spec/src/somacore/options.py @@ -60,9 +60,7 @@ class IOfN(ReadPartitions): def _validate(self, _, __): del _, __ # Unused. if not 0 <= self.i < self.n: - raise ValueError( - f"Partition index {self.i} must be in the range [0, {self.n})" - ) + raise ValueError(f"Partition index {self.i} must be in the range [0, {self.n})") @attrs.define(frozen=True) @@ -187,7 +185,5 @@ class ResultOrder(enum.Enum): SparseNDCoords = Sequence[SparseNDCoord] """A sequence of coordinate ranges for reading sparse ndarrays.""" -SpatialRegion = Union[ - Sequence[int], Sequence[float], shapely.geometry.base.BaseGeometry -] +SpatialRegion = Union[Sequence[int], Sequence[float], shapely.geometry.base.BaseGeometry] """A spatial region used for reading spatial dataframes and multiscale images.""" diff --git a/python-spec/src/somacore/query/axis.py b/python-spec/src/somacore/query/axis.py index c108b6a8..b7f7f0b3 100644 --- a/python-spec/src/somacore/query/axis.py +++ b/python-spec/src/somacore/query/axis.py @@ -22,12 +22,9 @@ def _canonicalize_coords( return tuple(_canonicalize_coord(c) for c in in_coords) if isinstance(in_coords, (str, bytes)): raise TypeError( - "Query coordinates must be a normal sequence, not `str` or `bytes`." - f" Did you mean {(in_coords,)}?" + f"Query coordinates must be a normal sequence, not `str` or `bytes`. Did you mean {(in_coords,)}?" ) - raise TypeError( - f"Query coordinates must be a sequence, not a single {type(in_coords)}" - ) + raise TypeError(f"Query coordinates must be a sequence, not a single {type(in_coords)}") def _canonicalize_coord(coord: options.SparseDFCoord) -> options.SparseDFCoord: diff --git a/python-spec/src/somacore/spatial.py b/python-spec/src/somacore/spatial.py index 1e4a6c59..de3f8955 100644 --- a/python-spec/src/somacore/spatial.py +++ b/python-spec/src/somacore/spatial.py @@ -663,18 +663,14 @@ def data_axis_order(self) -> tuple[str, ...]: """ ... - def get_transform_from_level( - self, level: int | str - ) -> coordinates.CoordinateTransform: + def get_transform_from_level(self, level: int | str) -> coordinates.CoordinateTransform: """Returns the transformation from user requested level to image reference level. Lifecycle: experimental """ ... - def get_transform_to_level( - self, level: int | str - ) -> coordinates.CoordinateTransform: + def get_transform_to_level(self, level: int | str) -> coordinates.CoordinateTransform: """Returns the transformation from the image reference level to the user requested level.