def load_rules(root='fmn.rules'):
    """ Load the big list of allowed callable rules. """

    module = __import__(root, fromlist=[root.split('.')[0]])

    hinting_helpers = fmn.lib.hinting.__dict__.values()

    rules = {}
    for name in dir(module):
        obj = getattr(module, name)

        # Ignore non-callables.
        if not callable(obj):
            continue

        # Ignore our decorator and its friends
        if obj in hinting_helpers:
            continue

        doc = inspect.getdoc(obj)

        # It's crazy, but inspect (stdlib!) doesn't return unicode objs on py2.
        if doc and hasattr(doc, 'decode'):
            doc = doc.decode('utf-8')

        if doc:
            # If we have a docstring, then mark it up beautifully for display
            # in the web app.
            # FWIW, this should probably be moved into fmn.web since nowhere
            # else are we going to want HTML... we'll still want raw .rst.
            title, doc_as_rst = doc.split('\n', 1)
            doc = docutils.examples.html_parts(doc_as_rst)['body']
            soup = bs4.BeautifulSoup(doc, 'html5lib')
            doc_no_links = ''.join(map(six.text_type, strip_anchor_tags(soup)))
            doc = markupsafe.Markup(doc)
            doc_no_links = markupsafe.Markup(doc_no_links)
        else:
            title = "UNDOCUMENTED"
            doc = "No docs for %s:%s %r" % (root, name, obj)
            doc_no_links = doc

        rules[name] = {
            'func': obj,
            'submodule': obj.__module__.split('.')[-1],
            'title': title.strip(),
            'doc': doc.strip(),
            'doc-no-links': doc_no_links.strip(),
            'args': inspect.getargspec(obj)[0],
            'datanommer-hints': getattr(obj, 'hints', {}),
            'hints-invertible': getattr(obj, 'hinting_invertible', True),
            'hints-callable': getattr(obj, 'hinting_callable', None),
        }

    rules = OrderedDict(
        sorted(rules.items(), key=lambda x: x[1]['title'])
    )

    return {root: rules}
def load_rules ( root = 'fmn.rules' ) : module = __import__ ( root , fromlist = [ root . split ( '.' ) [ 0 ] ] ) hinting_helpers = fmn . lib . hinting . __dict__ . values ( ) rules = { } for name in dir ( module ) : obj = getattr ( module , name ) if not callable ( obj ) : continue if obj in hinting_helpers : continue doc = inspect . getdoc ( obj ) if doc and hasattr ( doc , 'decode' ) : doc = doc . decode ( 'utf-8' ) if doc : title , doc_as_rst = doc . split ( '\n' , 1 ) doc = docutils . examples . html_parts ( doc_as_rst ) [ 'body' ] soup = bs4 . BeautifulSoup ( doc , 'html5lib' ) doc_no_links = '' . join ( map ( six . text_type , strip_anchor_tags ( soup ) ) ) doc = markupsafe . Markup ( doc ) doc_no_links = markupsafe . Markup ( doc_no_links ) else : title = "UNDOCUMENTED" doc = "No docs for %s:%s %r" % ( root , name , obj ) doc_no_links = doc rules [ name ] = { 'func' : obj , 'submodule' : obj . __module__ . split ( '.' ) [ - 1 ] , 'title' : title . strip ( ) , 'doc' : doc . strip ( ) , 'doc-no-links' : doc_no_links . strip ( ) , 'args' : inspect . getargspec ( obj ) [ 0 ] , 'datanommer-hints' : getattr ( obj , 'hints' , { } ) , 'hints-invertible' : getattr ( obj , 'hinting_invertible' , True ) , 'hints-callable' : getattr ( obj , 'hinting_callable' , None ) , } rules = OrderedDict ( sorted ( rules . items ( ) , key = lambda x : x [ 1 ] [ 'title' ] ) ) return { root : rules }
Load the big list of allowed callable rules.