From 7d65a9445aa04d82334c6fe2828278e528eda1cb Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 29 Feb 2024 18:52:38 +0300 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=F0=9F=90=9E=20Custom=20warning=20ty?= =?UTF-8?q?pe=20'SupervisionWarning'=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/utils/internal.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/supervision/utils/internal.py b/supervision/utils/internal.py index f5ab14ba..bec3e9aa 100644 --- a/supervision/utils/internal.py +++ b/supervision/utils/internal.py @@ -1,8 +1,23 @@ import functools +import os import warnings from typing import Callable -warnings.simplefilter("always", DeprecationWarning) + +class SupervisionWarnings(Warning): + """Supervision warning category. + Set the deprecation warnings visibility for Supervision library. + You can set the environment variable SUPERVISON_DEPRECATION_WARNING to '0' to + disable the deprecation warnings. + """ + + pass + + +if os.getenv("SUPERVISON_DEPRECATION_WARNING") == "0": + warnings.simplefilter("ignore", SupervisionWarnings) +else: + warnings.simplefilter("always", SupervisionWarnings) def deprecated_parameter( @@ -63,7 +78,7 @@ def deprecated_parameter( new_parameter=new_parameter, **message_kwargs, ), - category=DeprecationWarning, + category=SupervisionWarnings, stacklevel=2, ) @@ -82,7 +97,7 @@ def deprecated(reason: str): def wrapper(*args, **kwargs): warnings.warn( f"{func.__name__} is deprecated: {reason}", - category=DeprecationWarning, + category=SupervisionWarnings, stacklevel=2, ) return func(*args, **kwargs) From 18085340e2c7c156c3c07813659a3deb374d494a Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Thu, 29 Feb 2024 19:18:06 +0300 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E2=9A=A0=EF=B8=8F=20cleaner=20warn?= =?UTF-8?q?ing=20format=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- supervision/utils/internal.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/supervision/utils/internal.py b/supervision/utils/internal.py index bec3e9aa..978a1448 100644 --- a/supervision/utils/internal.py +++ b/supervision/utils/internal.py @@ -14,6 +14,16 @@ class SupervisionWarnings(Warning): pass +def format_warning(msg, category, filename, lineno, line=None): + """ + Format a warning the same way as the default formatter, but also include the + category name in the output. + """ + return f"{category.__name__}: {msg}\n" + + +warnings.formatwarning = format_warning + if os.getenv("SUPERVISON_DEPRECATION_WARNING") == "0": warnings.simplefilter("ignore", SupervisionWarnings) else: