Пример #1
0
def runintrospecter(s, attribs='', introspect=None, exclude=''):
    """
    This test function takes a string containing the contents of a
    module.  It writes the string contents to a file, imports the file
    as a module, and uses C{introspect_docs} to introspect it, and
    pretty prints the resulting ModuleDoc object.  The C{attribs}
    argument specifies which attributes of the C{APIDoc}s should be
    displayed.  The C{introspect} argument gives the name of a variable
    in the module whose value should be introspected, instead of
    introspecting the whole module.
    """
    # Write it to a temp file.
    file_path = write_pystring_to_tmp_dir(s)
    # Import it.
    sys.path.insert(0, os.path.dirname(file_path))
    if introspect is None:
        import epydoc_test as val
    else:
        import epydoc_test
        val = getattr(epydoc_test, introspect)
    del sys.path[0]
    # Introspect it.
    val_doc = introspect_docs(val)
    # Display it.
    s = val_doc.pp(include=attribs.split(), exclude=exclude.split())
    s = re.sub(r"(filename = ).*", r"\1...", s)
    s = re.sub(r"(<module 'epydoc_test' from ).*", r'\1...', s)
    s = re.sub(r"(<function \w+ at )0x\w+>", r"\1...>", s)
    s = re.sub(r"(<\w+ object at )0x\w+>", r"\1...>", s)
    print(s)
    # Clean up.
    cleanup_tmp_dir(file_path)
Пример #2
0
def runintrospecter(s, attribs='', introspect=None, exclude=''):
    """
    This test function takes a string containing the contents of a
    module.  It writes the string contents to a file, imports the file
    as a module, and uses C{introspect_docs} to introspect it, and
    pretty prints the resulting ModuleDoc object.  The C{attribs}
    argument specifies which attributes of the C{APIDoc}s should be
    displayed.  The C{introspect} argument gives the name of a variable
    in the module whose value should be introspected, instead of
    introspecting the whole module.
    """
    # Write it to a temp file.
    tmp_dir = write_pystring_to_tmp_dir(s)
    # Import it.
    sys.path.insert(0, tmp_dir)
    if introspect is None:
        import epydoc_test as val
    else:
        import epydoc_test
        val = getattr(epydoc_test, introspect)
    del sys.path[0]
    # Introspect it.
    val_doc = introspect_docs(val)
    # Display it.
    s = val_doc.pp(include=attribs.split(), exclude=exclude.split())
    s = re.sub(r"(filename = ).*", r"\1...", s)
    s = re.sub(r"(<module 'epydoc_test' from ).*", r'\1...', s)
    s = re.sub(r"(<function \w+ at )0x\w+>", r"\1...>", s)
    s = re.sub(r"(<\w+ object at )0x\w+>", r"\1...>", s)
    print(s)
    # Clean up.
    cleanup_tmp_dir(tmp_dir)
Пример #3
0
def _get_docs_from_pyscript(filename, introspect, parse, progress_estimator):
    # [xx] I should be careful about what names I allow as filenames,
    # and maybe do some munging to prevent problems.

    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    if introspect:
        try:
            introspect_doc = introspect_docs(filename=filename, is_script=True)
        except ImportError, e:
            introspect_error = str(e)
Пример #4
0
def _get_docs_from_pyscript(filename, introspect, parse, progress_estimator):
    # [xx] I should be careful about what names I allow as filenames,
    # and maybe do some munging to prevent problems.

    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    if introspect:
        try:
            introspect_doc = introspect_docs(filename=filename, is_script=True)
        except ImportError, e:
            introspect_error = str(e)
Пример #5
0
def _get_docs_from_pyname(name, introspect, parse, progress_estimator,
                          supress_warnings=False):
    progress_estimator.complete += 1
    log.progress(progress_estimator.progress(), name)
    
    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    if introspect:
        try:
            introspect_doc = introspect_docs(name=name)
        except ImportError, e:
            introspect_error = str(e)
Пример #6
0
def _get_docs_from_pyobject(obj, introspect, parse, progress_estimator):
    progress_estimator.complete += 1
    log.progress(progress_estimator.progress(), `obj`)
    
    if not introspect:
        log.error("Cannot get docs for Python objects without "
                  "introspecting them.")
            
    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    try:
        introspect_doc = introspect_docs(value=obj)
    except ImportError, e:
        log.error(e)
        return (None, None)
Пример #7
0
def _get_docs_from_pyname(name,
                          introspect,
                          parse,
                          progress_estimator,
                          supress_warnings=False):
    progress_estimator.complete += 1
    log.progress(progress_estimator.progress(), name)

    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    if introspect:
        try:
            introspect_doc = introspect_docs(name=name)
        except ImportError, e:
            introspect_error = str(e)
Пример #8
0
def _get_docs_from_pyobject(obj, introspect, parse, progress_estimator):
    progress_estimator.complete += 1
    log.progress(progress_estimator.progress(), ` obj `)

    if not introspect:
        log.error("Cannot get docs for Python objects without "
                  "introspecting them.")

    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    try:
        introspect_doc = introspect_docs(value=obj)
    except ImportError, e:
        log.error(e)
        return (None, None)
Пример #9
0
def getMethodTypedArgument(specFile):
    val_doc = parse_docs(specFile)
    doc = build_doc(specFile)
    moduledoc = introspect_docs(filename=specFile)
    methodDetails = dict()
    for ckey in moduledoc.variables.iterkeys():
        classdoc = moduledoc.variables[ckey].value
        for rkey in classdoc.variables.iterkeys():
            routinedoc = classdoc.variables[rkey].value
            if isinstance(routinedoc, RoutineDoc):
                argType=dict()
                for arg in routinedoc.arg_types.iterkeys():
                    argument = str(routinedoc.arg_types[arg])
                    paramType = re.findall('<epytext><para inline=True>(?P<paramtype>.*)</para></epytext>', argument)[0]
                    argType[arg] = paramType
                methodDetails[rkey] = argType
    return methodDetails
Пример #10
0
def _get_docs_from_module_file(filename,
                               introspect,
                               parse,
                               progress_estimator,
                               parent_docs=(None, None)):
    """
    Construct and return the API documentation for the python
    module with the given filename.

    @param parent_doc: The C{ModuleDoc} of the containing package.
        If C{parent_doc} is not provided, then this method will
        check if the given filename is contained in a package; and
        if so, it will construct a stub C{ModuleDoc} for the
        containing package(s).
    """
    # Record our progress.
    modulename = os.path.splitext(os.path.split(filename)[1])[0]
    if modulename == '__init__':
        modulename = os.path.split(os.path.split(filename)[0])[1]
    if parent_docs[0]:
        modulename = DottedName(parent_docs[0].canonical_name, modulename)
    elif parent_docs[1]:
        modulename = DottedName(parent_docs[1].canonical_name, modulename)
    log.progress(progress_estimator.progress(),
                 '%s (%s)' % (modulename, filename))
    progress_estimator.complete += 1

    # Normalize the filename.
    filename = os.path.normpath(os.path.abspath(filename))

    # When possible, use the source version of the file.
    try:
        filename = py_src_filename(filename)
        src_file_available = True
    except ValueError:
        src_file_available = False

    # Get the introspected & parsed docs (as appropriate)
    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    if introspect:
        try:
            introspect_doc = introspect_docs(filename=filename,
                                             context=parent_docs[0])
        except ImportError, e:
            introspect_error = str(e)
Пример #11
0
def _get_docs_from_module_file(filename, introspect, parse, progress_estimator,
                               parent_docs=(None,None)):
    """
    Construct and return the API documentation for the python
    module with the given filename.

    @param parent_doc: The C{ModuleDoc} of the containing package.
        If C{parent_doc} is not provided, then this method will
        check if the given filename is contained in a package; and
        if so, it will construct a stub C{ModuleDoc} for the
        containing package(s).
    """
    # Record our progress.
    modulename = os.path.splitext(os.path.split(filename)[1])[0]
    if modulename == '__init__':
        modulename = os.path.split(os.path.split(filename)[0])[1]
    if parent_docs[0]:
        modulename = DottedName(parent_docs[0].canonical_name, modulename)
    elif parent_docs[1]:
        modulename = DottedName(parent_docs[1].canonical_name, modulename)
    log.progress(progress_estimator.progress(),
                 '%s (%s)' % (modulename, filename))
    progress_estimator.complete += 1
    
    # Normalize the filename.
    filename = os.path.normpath(os.path.abspath(filename))

    # When possible, use the source version of the file.
    try:
        filename = py_src_filename(filename)
        src_file_available = True
    except ValueError:
        src_file_available = False

    # Get the introspected & parsed docs (as appropriate)
    introspect_doc = parse_doc = None
    introspect_error = parse_error = None
    if introspect:
        try:
            introspect_doc = introspect_docs(
                filename=filename, context=parent_docs[0])
        except ImportError, e:
            introspect_error = str(e)