Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding stub file #29

Open
beskep opened this issue Jul 11, 2023 · 0 comments
Open

Adding stub file #29

beskep opened this issue Jul 11, 2023 · 0 comments

Comments

@beskep
Copy link

beskep commented Jul 11, 2023

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant