|
@@ -16,6 +16,9 @@ _console = Console()
|
|
|
# The current log level.
|
|
|
_LOG_LEVEL = LogLevel.INFO
|
|
|
|
|
|
+# Deprecated features who's warning has been printed.
|
|
|
+_EMITTED_DEPRECATION_WARNINGS = set()
|
|
|
+
|
|
|
|
|
|
def set_log_level(log_level: LogLevel):
|
|
|
"""Set the log level.
|
|
@@ -111,6 +114,7 @@ def deprecate(
|
|
|
reason: str,
|
|
|
deprecation_version: str,
|
|
|
removal_version: str,
|
|
|
+ dedupe: bool = True,
|
|
|
**kwargs,
|
|
|
):
|
|
|
"""Print a deprecation warning.
|
|
@@ -119,15 +123,19 @@ def deprecate(
|
|
|
feature_name: The feature to deprecate.
|
|
|
reason: The reason for deprecation.
|
|
|
deprecation_version: The version the feature was deprecated
|
|
|
- removal_version: The version the deprecated feature will be removed.
|
|
|
+ removal_version: The version the deprecated feature will be removed
|
|
|
+ dedupe: If True, suppress multiple console logs of deprecation message.
|
|
|
kwargs: Keyword arguments to pass to the print function.
|
|
|
"""
|
|
|
- msg = (
|
|
|
- f"{feature_name} has been deprecated in version {deprecation_version} {reason.rstrip('.')}. It will be completely "
|
|
|
- f"removed in {removal_version}"
|
|
|
- )
|
|
|
- if _LOG_LEVEL <= LogLevel.WARNING:
|
|
|
- print(f"[yellow]DeprecationWarning: {msg}[/yellow]", **kwargs)
|
|
|
+ if feature_name not in _EMITTED_DEPRECATION_WARNINGS:
|
|
|
+ msg = (
|
|
|
+ f"{feature_name} has been deprecated in version {deprecation_version} {reason.rstrip('.')}. It will be completely "
|
|
|
+ f"removed in {removal_version}"
|
|
|
+ )
|
|
|
+ if _LOG_LEVEL <= LogLevel.WARNING:
|
|
|
+ print(f"[yellow]DeprecationWarning: {msg}[/yellow]", **kwargs)
|
|
|
+ if dedupe:
|
|
|
+ _EMITTED_DEPRECATION_WARNINGS.add(feature_name)
|
|
|
|
|
|
|
|
|
def error(msg: str, **kwargs):
|