From 2baa1a941cb03b9de3207cd5482e3cc619e2aae2 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Fri, 26 Jan 2024 20:54:17 +1300 Subject: [PATCH] Add new `COLOUR_SCIENCE__FILTER_RUNTIME_WARNINGS`, `COLOUR_SCIENCE__FILTER_USAGE_WARNINGS`, `COLOUR_SCIENCE__FILTER_COLOUR_WARNINGS` and `COLOUR_SCIENCE__FILTER_PYTHON_WARNINGS` environment variables. --- colour/utilities/verbose.py | 35 +++++++++++++++++++++++++++++++++-- docs/advanced.rst | 10 ++++++++-- docs/basics.rst | 4 ++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/colour/utilities/verbose.py b/colour/utilities/verbose.py index d7962dcbd..58aafd849 100644 --- a/colour/utilities/verbose.py +++ b/colour/utilities/verbose.py @@ -32,7 +32,7 @@ Type, cast, ) -from colour.utilities import is_string, optional +from colour.utilities import as_bool, is_string, optional __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -392,7 +392,38 @@ def filter_warnings( # Defaulting to filter *Colour* runtime warnings. -filter_warnings(colour_runtime_warnings=True) +filter_warnings( + colour_runtime_warnings=as_bool( + os.environ.get("COLOUR_SCIENCE__FILTER_RUNTIME_WARNINGS", "True") + ) +) + +if ( + os.environ.get("COLOUR_SCIENCE__FILTER_USAGE_WARNINGS") is not None +): # pragma: no cover + filter_warnings( + colour_usage_warnings=as_bool( + os.environ["COLOUR_SCIENCE__FILTER_USAGE_WARNINGS"] + ) + ) + +if ( + os.environ.get("COLOUR_SCIENCE__FILTER_COLOUR_WARNINGS") is not None +): # pragma: no cover + filter_warnings( + colour_usage_warnings=as_bool( + os.environ["COLOUR_SCIENCE__FILTER_WARNINGS"], + ) + ) + +if ( + os.environ.get("COLOUR_SCIENCE__FILTER_PYTHON_WARNINGS") is not None +): # pragma: no cover + filter_warnings( + colour_usage_warnings=as_bool( + os.environ["COLOUR_SCIENCE__FILTER_PYTHON_WARNINGS"] + ) + ) @contextmanager diff --git a/docs/advanced.rst b/docs/advanced.rst index d05a31e75..d4f3e59f0 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -1,5 +1,5 @@ -Advanced Concepts -================= +Advanced Usage +============== This page describes some advanced usage scenarios of **Colour**. @@ -29,6 +29,12 @@ runtime: :func:`warnings.showwarning` definition to be replaced with the :func:`colour.utilities.show_warning` definition and thus providing complete traceback from the point where the warning occurred. +- ``COLOUR_SCIENCE__FILTER_RUNTIME_WARNINGS``: Filter *Colour* runtime + warnings. +- ``COLOUR_SCIENCE__FILTER_USAGE_WARNINGS``: Filter *Colour* usage warnings. +- ``COLOUR_SCIENCE__FILTER_COLOUR_WARNINGS``: Filter *Colour* warnings, this + also filters *Colour* usage and runtime warnings. +- ``COLOUR_SCIENCE__FILTER_PYTHON_WARNINGS``: Filter *Python* warnings. JEnv File --------- diff --git a/docs/basics.rst b/docs/basics.rst index 99d936f4b..6b30c9cd6 100644 --- a/docs/basics.rst +++ b/docs/basics.rst @@ -1,5 +1,5 @@ -Basic Concepts -============== +Basic Usage +=========== This page puts an emphasis on basic concepts of **Colour**, those are important to understand.