retostauffer / python-colorspace

Python colorspace implementation. Documentation available on https://retostauffer.github.io/python-colorspace/. The latest release is available via the Python Package Index (PyPI) via https://pypi.org/project/colorspace/
Other
67 stars 15 forks source link

[0.4.5] Soft dependencies #17

Closed retostauffer closed 4 months ago

retostauffer commented 4 months ago

Testing the package on a 'naked' installation (Unix and Windows) and noticed that the one soft-dependency (suggested; matplotlib) is required for color vision deficiency simulation. To be precise:

Minimal

from colorspace import diverging_hcl, deutan
colors = diverging_hcl("Green-Orange").colors(10)
print(deutan(colors))

... where deutan() calls CVD.check_hex_colors() which imports matplotlib.colors.to_hex to allow for conversion for e.g., "red", 1.

Possible solution

I think this can be removed easily by only importing matplotlib if we do only get strings with valid hex colors by re-using the regex from colorlib.hex_to_sRGB/def: validhex() and only (try except) import matplotlib when needed.

zeileis commented 4 months ago

Sounds like a good idea!

But if we have to depend on matplotlib, it would be tolerable, I guess.

retostauffer commented 4 months ago

Fixed, make that dependent on the input and only import matplotlib when needed.

Adjusted tests and the GitHub Action workflow, now does the following:

@zeileis FYI