Skip to content

Conversation

@clbarnes
Copy link

See #105

Copy link
Member

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! 👍

Untitled.mov

left some minor comments below

# All of the things that we can pass to the constructor of Colormap
ColormapLike: TypeAlias = Union[
str, # colormap name, w/ optional "_r" suffix
ColormapName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ColormapName,
ColormapName,
str,

I know it feels like a cop-out, having added such lovely completion here. But from past experiences, I have a feeling this will result in people using # type: ignore all over the place rather than doing the research to import ColormapName to make their type checker happy. By adding str, we don't lose the lovely autocompletion and discovery.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what would you think about making this file .pyi? We don't ever want the compiler to have to make byte-code for it. It would require/demand import inside of a TYPE_CHECKING clause. (You could also export it in cmap/__init__.py, inside of TYPE_CHECKING, for those who want to use it externally)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(would also fix the failing 3.9 tests)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"""Produce the expected script."""
names = []

for rel_path in sorted(data_dir.glob("*/record.json")):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since ultimately, strings passed to Colormap are compared against the catalog:

cmap/src/cmap/_colormap.py

Lines 232 to 234 in fb69861

if isinstance(value, str):
rev = value.endswith("_r")
info = self.catalog()[value[:-2] if rev else value]

you could also use the catalog directly here, rather than parsing record.json again. This would avoid any divergence in logic for how the catalog is constructed from records.

import cmap

list(Colormap.catalog())  # all the colormap names, without the `_r`

not sure if you were trying to refrain from importing cmap? I don't see any issues with that...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now using the Catalog, although I am using the normalised names for consistency with the docs. I added some logic to avoid ambiguous alias warnings.

scripts_dir = Path(__file__).resolve().parent
module_dir = scripts_dir.parent.joinpath("src", "cmap")
data_dir = module_dir.joinpath("data")
out_file = module_dir.joinpath("_colormapname.py")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.pyi... depending on how you felt about that suggestion in my other comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now set this up as a pyi, which passes mypy although I still get a yellow squiggly in my editor (VSCode).

@clbarnes
Copy link
Author

Ah, depending on cmap means you can only run it when you have cmap installed, which isn't ideal e.g. on CI. What do you think?

@tlambert03
Copy link
Member

uv run will install the project in editable mode anyway by default. So it should already just work on ci with your current command

@tlambert03
Copy link
Member

see #108 (comment)
unfortunately, this causes performance issues for typing. please reopen with any new strategies

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

Successfully merging this pull request may close these issues.

3 participants