Esempio n. 1
0
def entry_for_one_class(nom, klas):
    """  Generate a BUILD dictionary entry for a class.
  nom: name like 'python_binary'
  klas: class like twitter.pants.python_binary"""
    try:
        args, varargs, varkw, defaults = inspect.getargspec(klas.__init__)
        argspec = inspect.formatargspec(args[1:], varargs, varkw, defaults)
        funcdoc = klas.__init__.__doc__

        methods = []
        for attrname in dir(klas):
            attr = getattr(klas, attrname)
            attr_bdi = get_builddict_info(attr)
            if not attr_bdi: continue
            if inspect.ismethod(attr):
                methods.append(entry_for_one_method(attrname, attr))
                continue
            raise TaskError(
                '@manual.builddict on non-method %s within class %s '
                'but I only know what to do with methods' % (attrname, nom))

    except TypeError:  # __init__ might not be a Python function
        argspec = None
        funcdoc = None
        methods = None

    return entry(nom,
                 classdoc=klas.__doc__,
                 argspec=argspec,
                 funcdoc=funcdoc,
                 methods=methods)
def entry_for_one_class(nom, klas):
    """  Generate a BUILD dictionary entry for a class.
  nom: name like 'python_binary'
  klas: class like twitter.pants.python_binary"""
    try:
        args, varargs, varkw, defaults = inspect.getargspec(klas.__init__)
        argspec = inspect.formatargspec(args[1:], varargs, varkw, defaults)
        funcdoc = klas.__init__.__doc__

        methods = []
        for attrname in dir(klas):
            attr = getattr(klas, attrname)
            attr_bdi = get_builddict_info(attr)
            if not attr_bdi:
                continue
            if inspect.ismethod(attr):
                methods.append(entry_for_one_method(attrname, attr))
                continue
            raise TaskError(
                "@manual.builddict on non-method %s within class %s "
                "but I only know what to do with methods" % (attrname, nom)
            )

    except TypeError:  # __init__ might not be a Python function
        argspec = None
        funcdoc = None
        methods = None

    return entry(nom, classdoc=klas.__doc__, argspec=argspec, funcdoc=funcdoc, methods=methods)
Esempio n. 3
0
def assemble(predefs=PREDEFS, symbol_hash=None):
    """Assemble big hash of entries suitable for smushing into a template.

  predefs: Hash of "hard-wired" predefined entries.
  symbol_hash: Python syms from which to generate more entries. Default: get from BUILD context"""
    d = {}
    for k in PREDEFS:
        v = PREDEFS[k]
        if "suppress" in v and v["suppress"]: continue
        d[k] = v
    if symbol_hash is None:
        symbol_hash = get_syms()
    for k in symbol_hash:
        bdi = get_builddict_info(symbol_hash[k])
        if bdi is None: continue
        d[k] = bdi.copy()
        if not "defn" in d[k]:
            d[k]["defn"] = entry_for_one(k, symbol_hash[k])
    return d
def assemble(predefs=PREDEFS, symbol_hash=None):
    """Assemble big hash of entries suitable for smushing into a template.

  predefs: Hash of "hard-wired" predefined entries.
  symbol_hash: Python syms from which to generate more entries. Default: get from BUILD context"""
    d = {}
    for k in PREDEFS:
        v = PREDEFS[k]
        if "suppress" in v and v["suppress"]:
            continue
        d[k] = v
    if symbol_hash is None:
        symbol_hash = get_syms()
    for k in symbol_hash:
        bdi = get_builddict_info(symbol_hash[k])
        if bdi is None:
            continue
        d[k] = bdi.copy()
        if not "defn" in d[k]:
            d[k]["defn"] = entry_for_one(k, symbol_hash[k])
    return d