arte/utils/help.py
def add_help(cls=None, *, help_function='help', classmethod=False):
    '''
    Decorator to add interactive help to a class

    Parameters
    ----------
    help_function: str, optional
        Name of the method that will be added to the class. Defaults to "help"
    classmethod: bool, optional
        If True, the help method will be added as a classmethod. Default False

    Returns
    -------
    class
        The decorated class type
    '''
    # Trick to allow a decorator without parenthesis
    if cls is not None:
        return add_help()(cls)

    def help(self, search='', prefix=''):
        '''
        Interactive help

        Prints on stdout a list of methods that match the *search* substring
        or all of them if *search* is left to the default value of an empty
        string, together with a one-line help taken from the first line
        of their docstring, if any.

        The *prefix* argument is prepended to the method name and is used
        for recursive help of every class member.
        '''
        methods = {k: getattr(self, k) for k in dir(self) if callable(getattr(self, k))}
        members = {k: getattr(self, k) for k in dir(self) if not callable(getattr(self, k))}

        properties = ({k: getattr(self.__class__, k)
                      for k in dir(self.__class__)
                      if isinstance(getattr(self.__class__, k), property)})

        methods.update(properties)

        methods = {k: v for k, v in methods.items() if _is_public_method(k) \
                                                      and not _is_hidden(v)}
        members = {k: v for k, v in members.items() if _is_hlp_class(v)}

        if prefix == '':
            prefix = self.__class__.__name__

        hlp = {prefix: _format_docstring(self)}

        for name, method in methods.items():
            name = _format_name(method, default=name)
            pars = _format_pars(method)
            helpstr = _format_docstring(method)

            hlp[prefix + '.' + name + pars] = helpstr

        maxlen = max(map(len, hlp.keys()))
        fmt = '%%-%ds%%s' % (maxlen + 3)

        lines = []
        for k in sorted(hlp.keys()):
            line = fmt % (k, hlp[k])
            if search in line:
                lines.append(line)

        if len(lines) > 0:
            print('---------')
            for line in lines:
                print(line)

        for name, obj in sorted(members.items()):
            obj.help(search=search, prefix='%s.%s' % (prefix, name))

    def decorate(cls):
        setattr(cls, HIDDEN_HELP, False)  # Set attr but do not define a string
        if classmethod:
            func = partial(help, self=cls())
            func.__name__ = help.__name__
            setattr(cls, help_function, hide_from_help(func))
        else:
            setattr(cls, help_function, hide_from_help(help))
        return cls
    return decorate

    Decorator to add interactive help to a class

    Parameters
    ----------
    help_function: str, optional
        Name of the method that will be added to the class. Defaults to "help"
    classmethod: bool, optional
        If True, the help method will be added as a classmethod. Default False

    Returns
    -------
    class
        The decorated class type
    
Decorator to add interactive help to a class
Parameters

str, optional
Name of the method that will be added to the class. Defaults to "help"
classmethod: bool, optional
If True, the help method will be added as a classmethod. Default False

Returns

class
The decorated class type
Decorator to add interactive help to a class Parameters str optional Name of the method that will be added to the class . Defaults to " help " classmethod : bool optional If True the help method will be added as a classmethod . Default False Returns class The decorated class type
def add_help(cls=None, *, help_function='help', classmethod=False):
    if cls is not None:
        return add_help()(cls)
    def help(self, search='', prefix=''):
        methods = {k: getattr(self, k) for k in dir(self) if callable(getattr(self, k))}
        members = {k: getattr(self, k) for k in dir(self) if not callable(getattr(self, k))}
        properties = ({k: getattr(self.__class__, k)
                      for k in dir(self.__class__)
                      if isinstance(getattr(self.__class__, k), property)})
        methods.update(properties)
        methods = {k: v for k, v in methods.items() if _is_public_method(k) \
                                                      and not _is_hidden(v)}
        members = {k: v for k, v in members.items() if _is_hlp_class(v)}
        if prefix == '':
            prefix = self.__class__.__name__
        hlp = {prefix: _format_docstring(self)}
        for name, method in methods.items():
            name = _format_name(method, default=name)
            pars = _format_pars(method)
            helpstr = _format_docstring(method)
            hlp[prefix + '.' + name + pars] = helpstr
        maxlen = max(map(len, hlp.keys()))
        fmt = '%%-%ds%%s' % (maxlen + 3)
        lines = []
        for k in sorted(hlp.keys()):
            line = fmt % (k, hlp[k])
            if search in line:
                lines.append(line)
        if len(lines) > 0:
            print('---------')
            for line in lines:
                print(line)
        for name, obj in sorted(members.items()):
            obj.help(search=search, prefix='%s.%s' % (prefix, name))
    def decorate(cls):
        setattr(cls, HIDDEN_HELP, False)  
        if classmethod:
            func = partial(help, self=cls())
            func.__name__ = help.__name__
            setattr(cls, help_function, hide_from_help(func))
        else:
            setattr(cls, help_function, hide_from_help(help))
        return cls
    return decorate
def add_help ( cls = None , * , help_function = 'help' , classmethod = False ) : if cls is not None : return add_help ( ) ( cls ) def help ( self , search = '' , prefix = '' ) : '''
        Interactive help

        Prints on stdout a list of methods that match the *search* substring
        or all of them if *search* is left to the default value of an empty
        string, together with a one-line help taken from the first line
        of their docstring, if any.

        The *prefix* argument is prepended to the method name and is used
        for recursive help of every class member.
        ''' methods = { k : getattr ( self , k ) for k in dir ( self ) if callable ( getattr ( self , k ) ) } members = { k : getattr ( self , k ) for k in dir ( self ) if not callable ( getattr ( self , k ) ) } properties = ( { k : getattr ( self . __class__ , k ) for k in dir ( self . __class__ ) if isinstance ( getattr ( self . __class__ , k ) , property ) } ) methods . update ( properties ) methods = { k : v for k , v in methods . items ( ) if _is_public_method ( k ) and not _is_hidden ( v ) } members = { k : v for k , v in members . items ( ) if _is_hlp_class ( v ) } if prefix == '' : prefix = self . __class__ . __name__ hlp = { prefix : _format_docstring ( self ) } for name , method in methods . items ( ) : name = _format_name ( method , default = name ) pars = _format_pars ( method ) helpstr = _format_docstring ( method ) hlp [ prefix + '.' + name + pars ] = helpstr maxlen = max ( map ( len , hlp . keys ( ) ) ) fmt = '%%-%ds%%s' % ( maxlen + 3 ) lines = [ ] for k in sorted ( hlp . keys ( ) ) : line = fmt % ( k , hlp [ k ] ) if search in line : lines . append ( line ) if len ( lines ) > 0 : print ( '---------' ) for line in lines : print ( line ) for name , obj in sorted ( members . items ( ) ) : obj . help ( search = search , prefix = '%s.%s' % ( prefix , name ) ) def decorate ( cls ) : setattr ( cls , HIDDEN_HELP , False ) if classmethod : func = partial ( help , self = cls ( ) ) func . __name__ = help . __name__ setattr ( cls , help_function , hide_from_help ( func ) ) else : setattr ( cls , help_function , hide_from_help ( help ) ) return cls return decorate
Decorator to add interactive help to a class
Parameters
Decorator to add interactive help to a class Parameters
'''
    Decorator to add interactive help to a class

    Parameters
    ----------
    help_function: str, optional
        Name of the method that will be added to the class. Defaults to "help"
    classmethod: bool, optional
        If True, the help method will be added as a classmethod. Default False

    Returns
    -------
    class
        The decorated class type
    ''' # Trick to allow a decorator without parenthesis '''
        Interactive help

        Prints on stdout a list of methods that match the *search* substring
        or all of them if *search* is left to the default value of an empty
        string, together with a one-line help taken from the first line
        of their docstring, if any.

        The *prefix* argument is prepended to the method name and is used
        for recursive help of every class member.
        ''' # Set attr but do not define a string
cls
help_function
classmethod