Back to index

salome-kernel  6.5.0
Functions | Variables
KERNEL_PY.kernel.deprecation Namespace Reference

Functions

def __deprecated_with_msg
def deprecated
def deprecated_module
def is_called_by_sphinx
def __show_colored_warning

Variables

string msg_seedoc = "See documentation for possible replacements."

Function Documentation

def KERNEL_PY.kernel.deprecation.__deprecated_with_msg (   func,
  msg 
) [private]

Definition at line 45 of file deprecation.py.

00045 
00046 def __deprecated_with_msg(func, msg):
00047 
00048     def new_func(*args, **kwargs):
00049         if len(inspect.stack()) > 1:
00050             callingfunc = inspect.stack()[1][3]
00051         else:
00052             callingfunc = "CORBA middleware"
00053         warnings.warn(
00054             ("Call to deprecated function %(funcname)s of module " +
00055              "%(modname)s (called from %(callingfunc)s).\n  %(msg)s") % {
00056                 'funcname': func.__name__,
00057                 'modname': func.__module__,
00058                 'callingfunc': callingfunc,
00059                 'msg': msg,
00060             },
00061             category = DeprecationWarning,
00062             stacklevel = 2
00063         )
00064         return func(*args, **kwargs)
00065     return new_func

Here is the caller graph for this function:

def KERNEL_PY.kernel.deprecation.__show_colored_warning (   message,
  category,
  filename,
  lineno,
  file = sys.stderr,
  line = None 
) [private]

Definition at line 118 of file deprecation.py.

00118 
00119                            lineno, file = sys.stderr, line = None):
00120     str = warnings.formatwarning(message, category, filename, lineno, line)
00121     if category == DeprecationWarning and termcolor.canDisplayColor(file):
00122         file.write(termcolor.makeColoredMessage(str, termcolor.BLUE))
00123     else:
00124         file.write(str)
00125 
00126 # Enable warnings for deprecated functions and modules (in Python 2.7, they
00127 # are disabled by default)
00128 warnings.filterwarnings("always", "Call to *", DeprecationWarning)
00129 warnings.filterwarnings("always", "Importation of *", DeprecationWarning)
00130 warnings.showwarning = __show_colored_warning

Here is the caller graph for this function:

def KERNEL_PY.kernel.deprecation.deprecated (   msg = msg_seedoc)
This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used. The message in parameter will
be displayed and should indicate how this function can be
replaced. If the terminal can display colors, the warning
messages will appear in blue.

Definition at line 66 of file deprecation.py.

00066 
00067 def deprecated(msg = msg_seedoc):
00068     """
00069     This is a decorator which can be used to mark functions
00070     as deprecated. It will result in a warning being emitted
00071     when the function is used. The message in parameter will
00072     be displayed and should indicate how this function can be
00073     replaced. If the terminal can display colors, the warning
00074     messages will appear in blue.
00075     """
00076     def make_dep(f):
00077         if is_called_by_sphinx():
00078             return f
00079         else:
00080             g = __deprecated_with_msg(f, msg)
00081             g.__name__ = f.__name__
00082             g.__doc__ = f.__doc__
00083             g.__dict__.update(f.__dict__)
00084             return g
00085     return make_dep

Here is the call graph for this function:

Here is the caller graph for this function:

This function can be used to mark a module as deprecated.
It must be called explicitly at the beginning of the deprecated
module. It will result in a warning being emitted. The message
in parameter will be displayed and should indicate how this
module can be replaced. If the terminal can display colors,
the warning messages will appear in blue.

Definition at line 86 of file deprecation.py.

00086 
00087 def deprecated_module(msg = msg_seedoc):
00088     """
00089     This function can be used to mark a module as deprecated.
00090     It must be called explicitly at the beginning of the deprecated
00091     module. It will result in a warning being emitted. The message
00092     in parameter will be displayed and should indicate how this
00093     module can be replaced. If the terminal can display colors,
00094     the warning messages will appear in blue.
00095     """
00096     if not is_called_by_sphinx():
00097         warnings.warn(
00098             "Importation of deprecated module %(modname)s.\n  %(msg)s" % {
00099                 'modname': inspect.getmodulename(inspect.stack()[1][1]),
00100                 'msg': msg,
00101             },
00102             category = DeprecationWarning,
00103             stacklevel = 5
00104         )

Here is the call graph for this function:

Determine if the calling code is ultimately called by sphinx to generate
documentation. The result can be used to conditionally inhibit the
decorators or some Salome-related imports that fail when called outside
Salome.

Definition at line 105 of file deprecation.py.

00105 
00106 def is_called_by_sphinx():
00107     """
00108     Determine if the calling code is ultimately called by sphinx to generate
00109     documentation. The result can be used to conditionally inhibit the
00110     decorators or some Salome-related imports that fail when called outside
00111     Salome.
00112     """
00113     calling_file = inspect.stack()[len(inspect.stack())-1][1]
00114     basename = os.path.basename(calling_file)
00115     return (basename == "sphinx-build")
00116 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string KERNEL_PY.kernel.deprecation.msg_seedoc = "See documentation for possible replacements."

Definition at line 43 of file deprecation.py.