Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ repos:
args: [--autofix]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.9.1
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
- id: ruff-format

# commented out until PEP 639 is supported\
# https://github.com/abravalheri/validate-pyproject/issues/70
# - repo: https://github.com/abravalheri/validate-pyproject
# rev: v0.10.1
# hooks:
# - id: validate-pyproject
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23
hooks:
- id: validate-pyproject

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
rev: v1.14.1
hooks:
- id: mypy
files: "^src/"
Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ name = "cmap"
description = "Scientific colormaps for python, without dependencies"
readme = "README.md"
requires-python = ">=3.8"
license = { text = "BSD 3-Clause License" }
license = "BSD-3-Clause"
license-files = ["LICENSE/*"]
authors = [{ email = "[email protected]", name = "Talley Lambert" }]
classifiers = [
"Development Status :: 4 - Beta",
Expand All @@ -25,9 +26,6 @@ classifiers = [
dynamic = ["version"]
dependencies = ["numpy"]

[project.license-files]
globs = ["LICENSE/*"]

# extras
# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
[project.optional-dependencies]
Expand All @@ -52,9 +50,9 @@ test_thirdparty = [
"colour",
"matplotlib",
"napari>=0.4.19; python_version<'3.13'",
"numba; python_version<'3.13'",
"numba; python_version<'3.13' and platform_machine != 'arm64'",
"plotly",
"pydantic-extra-types>=2",
"pydantic-extra-types>=2,!=2.10.1",
"pydantic",
"pygfx",
"pyqtgraph",
Expand All @@ -73,6 +71,7 @@ dev = [
"pytest",
"rich",
"ruff",
"pyqt6",
]

[project.urls]
Expand Down
10 changes: 5 additions & 5 deletions src/cmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def resolve(self, name: str) -> str:
from ._catalog import Catalog, CatalogItem

__all__ = [
"Catalog",
"CatalogItem",
"Color",
"Colormap",
"ColorStops",
"HSLA",
"HSVA",
"RGBA",
"RGBA8",
"Catalog",
"CatalogItem",
"Color",
"ColorStops",
"Colormap",
]
2 changes: 1 addition & 1 deletion src/cmap/_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _build_catalog(records: Iterable[FileDescriptorOrPath]) -> CatalogDict:
# here we add any global keys to the colormap that are not already there.
for k in ("license", "namespace", "source", "authors", "category"):
if k in data:
v.setdefault(k, data[k]) # type: ignore [misc,literal-required]
v.setdefault(k, data[k]) # type: ignore [misc]

# add the fully namespaced colormap to the catalog
ctlg[namespaced] = v
Expand Down
4 changes: 2 additions & 2 deletions src/cmap/_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def to_float(self) -> RGBA:
def to_hex(self) -> str:
"""Convert to hex color."""
out = f"#{self.r:02X}{self.g:02X}{self.b:02X}"
return f"{out}{round(self.a*255):02X}" if self.a != 1 else out
return f"{out}{round(self.a * 255):02X}" if self.a != 1 else out

def to_hsv(self) -> HSVA:
"""Convert to Hue, Saturation, Value."""
Expand Down Expand Up @@ -466,7 +466,7 @@ class Color:
The color to represent. Can be any "ColorLike".
"""

__slots__ = ("_rgba", "_name", "__weakref__")
__slots__ = ("__weakref__", "_name", "_rgba")
_rgba: RGBA
_name: str | None

Expand Down
14 changes: 7 additions & 7 deletions src/cmap/_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
"""

__slots__ = (
"__weakref__",
"_initialized",
"_lut_cache",
"bad_color",
"category",
"color_stops",
Expand All @@ -130,9 +133,6 @@
"name",
"over_color",
"under_color",
"_initialized",
"_lut_cache",
"__weakref__",
)

color_stops: ColorStops
Expand Down Expand Up @@ -920,7 +920,7 @@
return cls(np.concatenate([stops[:, None], ary], axis=1))

@property
def stops(self) -> tuple[float, ...]:
def stops(self) -> tuple[np.floating, ...]:
"""Return tuple of color stop positions."""
return tuple(self._stops[:, 0])

Expand Down Expand Up @@ -1061,14 +1061,14 @@
midpoints = np.linspace(0, 1, len(colors) + 1)[1:-1]
_midstops = []
for m, (c1, c2) in zip(midpoints, zip(colors[:-1], colors[1:])):
s1 = f"{c1.hex if as_hex else c1.rgba_string} {m*100:g}%"
s2 = f"{c2.hex if as_hex else c2.rgba_string} {m*100:g}%"
s1 = f"{c1.hex if as_hex else c1.rgba_string} {m * 100:g}%"
s2 = f"{c2.hex if as_hex else c2.rgba_string} {m * 100:g}%"

Check warning on line 1065 in src/cmap/_colormap.py

View check run for this annotation

Codecov / codecov/patch

src/cmap/_colormap.py#L1064-L1065

Added lines #L1064 - L1065 were not covered by tests
_midstops.extend([s1, s2])
_stops = ", ".join(_midstops)
else:
_stops = ", ".join(
[
f"{c.hex if as_hex else c.rgba_string} {s*100:g}%"
f"{c.hex if as_hex else c.rgba_string} {s * 100:g}%"
for c, s in zip(colors, stops)
]
)
Expand Down
8 changes: 6 additions & 2 deletions src/cmap/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def plot_color_gradients(
nrows = len(cmap_list) * (2 if compare else 1)
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh))
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, left=0.2, right=0.99)
bottom = 0.15 / figh
top = 1 - 0.35 / figh
if bottom >= top: # pragma: no cover
bottom, top = top, bottom
fig.subplots_adjust(top=top, bottom=bottom, left=0.2, right=0.99)

for i, (ax, name) in enumerate(zip(axs[:: 2 if compare else 1], cmap_list)):
cm = _ensure_cmap(name).to_mpl()
Expand Down Expand Up @@ -137,7 +141,7 @@ def plot_lightness(
x = np.linspace(0.0, 1.0, 101) if x is None else np.asarray(x)
cmap = _ensure_cmap(cmap)
lab = calc_lightness(cmap, x, colorspace)
lslice = np.s_[::-1] if reverse else np.s_[:]
lslice = np.s_[::-1] if reverse else slice(None)
y_ = lab[lslice]
c_ = x[lslice]

Expand Down
Loading
Loading