Skip to content

Commit

Permalink
Implement support for JEnv file.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Jan 25, 2024
1 parent 4a7844e commit db37830
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,30 @@
"""

import contextlib
import json
import os
import sys

import numpy as np

# Loading the "colour-science" JEnv file.
_JENV_FILE_PATH = os.path.join(
os.path.expanduser("~"),
".colour-science",
"colour-science.jenv",
)

if os.path.exists(_JENV_FILE_PATH):
with open(_JENV_FILE_PATH) as _JENV_FILE:
for _KEY, _VALUE in json.loads(_JENV_FILE.read()).items():
os.environ[_KEY] = str(_VALUE)

del _JENV_FILE, _KEY, _VALUE

del _JENV_FILE_PATH

# ruff: noqa: E402

from colour import plotting # noqa: F401

from .adaptation import (
Expand Down
13 changes: 13 additions & 0 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ runtime:
:func:`colour.utilities.show_warning` definition and thus providing
complete traceback from the point where the warning occurred.

JEnv File
---------

**Colour** will also read the ``~/.colour-science/colour-science.jenv`` JSON
file if it exists. The syntax is that of a mapping of environment variable and
values as follows:

.. code-block:: json
{
"COLOUR_SCIENCE__COLOUR__SHOW_WARNINGS_WITH_TRACEBACK": "True"
}
Caching
-------

Expand Down

0 comments on commit db37830

Please sign in to comment.