DeprecateMessage
- class omni.graph.tools.DeprecateMessage
Bases:
object
Manager for deprecation messages, to make it efficient to prevent multiple logging of the same deprecation messages.
The default settings for output is usually enough to help you find where deprecated code is referenced. If more information is desired these per-class variables can be set to reduce the filtering being done. The message should contains an action item for the user to upgrade from the deprecated functionality:
DeprecateMessage.deprecated("Install the latest version instead") # Although it's not usually necessary the class can be tuned using these class variable SILENCE_LOG = False # When set the output does not go to the console log; useful to disable for testing SHOW_STACK = True # Report stack trace in the deprecation message - can be turned off if it is too verbose MAX_STACK_LEVELS = 3 # Maximum number of stack levels to report, after filtering
You can use some Python features to handle simple deprecation cases directly such as:
# Rename constant from A to B A = (DeprecateMessage("A has been renamed to B") and False) or B # Constant A will be removed A = (DeprecateMessage("A will be removed, use B instead) and False) or B
Methods
Clear the logged messages so that they can be logged again
deprecated
(message[, deprecation_level])Log the deprecation message if it has not yet been logged, otherwise do nothing
Returns True if deprecations are currently being treated as errors
Returns the set of messages that have been logged so far
set_deprecations_are_errors
(make_errors)Enable or disable treating deprecations as errors instead of warnings
Attributes
Maximum number of stack levels to report, after filtering
Report stack trace in the deprecation message - can be turned off if it is too verbose
When set the output does not go to the console log; useful to disable for testing
- __init__()
- class NoLogging(*args, **kwargs)
Bases:
object
Context manager class to let you import a bunch of known deprecated functions without logging warnings. Typical use would be in providing backward compatibility in a module where submodules have moved.
- with DeprecateMessage.NoLogging():
import .v1_0.my_old_function as my_old_function
- classmethod clear_messages()
Clear the logged messages so that they can be logged again
- classmethod deprecated(message: str, deprecation_level: Optional[DeprecationLevel] = None)
Log the deprecation message if it has not yet been logged, otherwise do nothing
- Parameters
message – Message to display; only displays once even if this is called many times
deprecation_level – If specified, override the default level coming from deprecations_are_errors()
Adds stack trace information if the class member SHOW_STACK is True. Skips the Carbonite logging if the class member SILENCE_LOG is True (mostly useful for testing when a warning is the expected result).
- classmethod deprecations_are_errors() bool
Returns True if deprecations are currently being treated as errors
- classmethod messages_logged() Set[str]
Returns the set of messages that have been logged so far
- classmethod set_deprecations_are_errors(make_errors: bool)
Enable or disable treating deprecations as errors instead of warnings
- MAX_STACK_LEVELS = 3
Maximum number of stack levels to report, after filtering
- SHOW_STACK = True
Report stack trace in the deprecation message - can be turned off if it is too verbose
- SILENCE_LOG = False
When set the output does not go to the console log; useful to disable for testing