[REF-2229]Dedupe deprecation warnings (#2871)
* Dedupe deprecation warnings * Update reflex/utils/console.py Co-authored-by: Masen Furer <m_github@0x26.net> * address PR comments --------- Co-authored-by: Masen Furer <m_github@0x26.net>
This commit is contained in:
parent
15dc7f4552
commit
61c6728006
@ -621,6 +621,7 @@ class Component(BaseComponent, ABC):
|
|||||||
reason=f"for consistency. Use `{prop}` instead.",
|
reason=f"for consistency. Use `{prop}` instead.",
|
||||||
deprecation_version="0.4.0",
|
deprecation_version="0.4.0",
|
||||||
removal_version="0.5.0",
|
removal_version="0.5.0",
|
||||||
|
dedupe=False,
|
||||||
)
|
)
|
||||||
props[prop] = props.pop(under_prop)
|
props[prop] = props.pop(under_prop)
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ _console = Console()
|
|||||||
# The current log level.
|
# The current log level.
|
||||||
_LOG_LEVEL = LogLevel.INFO
|
_LOG_LEVEL = LogLevel.INFO
|
||||||
|
|
||||||
|
# Deprecated features who's warning has been printed.
|
||||||
|
_EMITTED_DEPRECATION_WARNINGS = set()
|
||||||
|
|
||||||
|
|
||||||
def set_log_level(log_level: LogLevel):
|
def set_log_level(log_level: LogLevel):
|
||||||
"""Set the log level.
|
"""Set the log level.
|
||||||
@ -111,6 +114,7 @@ def deprecate(
|
|||||||
reason: str,
|
reason: str,
|
||||||
deprecation_version: str,
|
deprecation_version: str,
|
||||||
removal_version: str,
|
removal_version: str,
|
||||||
|
dedupe: bool = True,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""Print a deprecation warning.
|
"""Print a deprecation warning.
|
||||||
@ -119,15 +123,19 @@ def deprecate(
|
|||||||
feature_name: The feature to deprecate.
|
feature_name: The feature to deprecate.
|
||||||
reason: The reason for deprecation.
|
reason: The reason for deprecation.
|
||||||
deprecation_version: The version the feature was deprecated
|
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.
|
kwargs: Keyword arguments to pass to the print function.
|
||||||
"""
|
"""
|
||||||
msg = (
|
if feature_name not in _EMITTED_DEPRECATION_WARNINGS:
|
||||||
f"{feature_name} has been deprecated in version {deprecation_version} {reason.rstrip('.')}. It will be completely "
|
msg = (
|
||||||
f"removed in {removal_version}"
|
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 _LOG_LEVEL <= LogLevel.WARNING:
|
||||||
|
print(f"[yellow]DeprecationWarning: {msg}[/yellow]", **kwargs)
|
||||||
|
if dedupe:
|
||||||
|
_EMITTED_DEPRECATION_WARNINGS.add(feature_name)
|
||||||
|
|
||||||
|
|
||||||
def error(msg: str, **kwargs):
|
def error(msg: str, **kwargs):
|
||||||
|
Loading…
Reference in New Issue
Block a user