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

add parse_color function #361

Merged
merged 3 commits into from
Mar 8, 2021
Merged

add parse_color function #361

merged 3 commits into from
Mar 8, 2021

Conversation

vincentsarago
Copy link
Member

ref developmentseed/titiler#262

This PR adds a function to parse colormap value from HEX for list.

rio_tiler/colormap.py Outdated Show resolved Hide resolved

"""
if isinstance(value, str):
if re.match("^#[a-fA-F0-9]{3,4}$", value):
Copy link
Member

Choose a reason for hiding this comment

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

IMO a regex is overkill here. You can just assert that the string starts with # (if you want) and then if the string has <=4 more characters, you treat it as the first type, otherwise the second. And if an error is created that gets propagated to the user. But not a strong preference.

Copy link
Member Author

Choose a reason for hiding this comment

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

if len(rgba) == 3:
rgba += (255,)

return rgba # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't keep mypy happy here because it lost the track on the number of items in rgba 🤷‍♂️

@vincentsarago vincentsarago merged commit 76b7648 into master Mar 8, 2021
@vincentsarago vincentsarago deleted the parseColor branch March 8, 2021 18:17
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