cmcrameri
cmcrameri copied to clipboard
Adding stub file
Adding stub file of cm.py would be very helpful for type checking and auto completing colormaps.
from matplotlib.colors import ListedColormap
from pathlib import Path
paths: list[Path]
cmaps: dict[str, ListedColormap]
def show_cmaps(*, ncols: int = ..., figwidth: int = ...) -> None: ...
acton: ListedColormap
acton_r: ListedColormap
actonS: ListedColormap
bam: ListedColormap
bam_r: ListedColormap
bamako: ListedColormap
bamako_r: ListedColormap
bamakoS: ListedColormap
⋮
I generated cm.pyi stub file with this script (mypy needed).
import subprocess
from pathlib import Path
from cmcrameri.cm import cmaps
if __name__ == "__main__":
subprocess.check_output(["stubgen", "-o", ".", "cmcrameri/cm.py"])
path = Path(__file__).parent / "cm.pyi"
assert path.exists()
with path.open("a", encoding="utf-8") as f:
for cmap in cmaps:
f.write(f"\n{cmap}: ListedColormap")
These lines were added for typing paths and cmaps.
paths: list[Path]
cmaps: dict[str, ListedColormap]
paths, cmaps = _load_cmaps()