colour-science / colour

Colour Science for Python
https://www.colour-science.org
BSD 3-Clause "New" or "Revised" License
2.14k stars 263 forks source link

PR: Implement support for injecting `vaab/colour` objects into our namespace. #1222

Closed KelSolaar closed 1 year ago

KelSolaar commented 1 year ago

Summary

This PR injects vaab/colour objects into our namespace to address #1221, #958 and https://github.com/vaab/colour/issues/62.

This is really gross but it will help users so...

from colour import Color, web2rgb

print(Color, web2rgb)
/Users/kelsolaar/Library/Caches/pypoetry/virtualenvs/colour-science-49B8_mty-py3.11/bin/python /Users/kelsolaar/Applications/PyCharm Professional Edition.app/Contents/plugins/python/helpers/pydev/pydevconsole.py --mode=client --host=127.0.0.1 --port=56376 
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['/Users/kelsolaar/Documents/Development/colour-science/colour'])
Python 3.11.6 (main, Oct  2 2023, 20:46:14) [Clang 14.0.3 (clang-1403.0.22.14.1)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.16.1 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 8.16.1
Python 3.11.6 (main, Oct  2 2023, 20:46:14) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
runfile('/Users/kelsolaar/Library/Application Support/JetBrains/PyCharm2023.2/scratches/scratch_127.py', wdir='/Users/kelsolaar/Library/Application Support/JetBrains/PyCharm2023.2/scratches')
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "COLOR_NAME_TO_RGB" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "C_HEX" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "C_HSL" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "C_RGB" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "Color" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "HEX" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "HSL" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "HSL_equivalence" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "LONG_HEX_COLOR" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "RGB" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "RGB_TO_COLOR_NAMES" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "RGB_color_picker" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "RGB_equivalence" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "SHORT_HEX_COLOR" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "color_scale" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hash_or_str" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hex2hsl" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hex2rgb" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hex2web" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hsl2hex" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hsl2rgb" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "hsl2web" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "make_color_factory" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "rgb2hex" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "rgb2hsl" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "rgb2web" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "web2hex" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "web2hsl" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
/Users/kelsolaar/Documents/Development/colour-science/colour/colour/utilities/verbose.py:265: ColourWarning: Injecting "vaab/colour" "web2rgb" object into "Colour"'s namespace!
  warn(*args, **kwargs)  # noqa: B028
<class '__vaab_colour__.Color'> <function <lambda> at 0x16f085da0>

Preflight

Code Style and Quality

Documentation

coveralls commented 1 year ago

Coverage Status

coverage: 99.733% (-0.03%) from 99.763% when pulling 6e828f651a702961cada2bff683c68eda3f8a551 on feature/vaab_colour into c1dd25a048c7e0ed3a1140dcfff01298db69e77c on develop.

KelSolaar commented 1 year ago

After discussion with @tjdcs, we are going for an opt-in behaviour, default is to warn if vaab/colour is detected, proposing to set the COLOUR_SCIENCE__COLOUR__IMPORT_VAAB_COLOUR variable to import its objects into our namespace.