Example #1
0
def _make_docmap(modules, options):
    """
    Construct the documentation map for the given modules.

    @param modules: The modules that should be documented.
    @type modules: C{list} of C{Module}
    @param options: Options from the command-line arguments.
    @type options: C{dict}
    """
    from epydoc.objdoc import DocMap, report_param_mismatches

    verbosity = options['verbosity']
    document_bases = 1
    document_autogen_vars = 1
    inheritance_groups = (options['inheritance'] == 'grouped')
    inherit_groups = (options['inheritance'] != 'grouped')
    d = DocMap(verbosity, document_bases, document_autogen_vars,
               inheritance_groups, inherit_groups)
    if options['verbosity'] > 0:
        print  >>sys.stderr, ('Building API documentation for %d modules.'
                              % len(modules))
    progress = _Progress('Building docs for', verbosity, len(modules))
    
    for module in modules:
        progress.report(module.__name__)
        # Add the module.  Catch any exceptions that get generated.
        try: d.add(module)
        except Exception, e:
            if options['debug']: raise
            else: _internal_error(e)
        except:   
Example #2
0
def _make_docmap(modules, options):
    """
    Construct the documentation map for the given modules.

    @param modules: The modules that should be documented.
    @type modules: C{list} of C{Module}
    @param options: Options from the command-line arguments.
    @type options: C{dict}
    """
    from epydoc.objdoc import DocMap, report_param_mismatches

    verbosity = options['verbosity']
    document_bases = 1
    document_autogen_vars = 1
    inheritance_groups = (options['inheritance'] == 'grouped')
    inherit_groups = (options['inheritance'] != 'grouped')
    d = DocMap(verbosity, document_bases, document_autogen_vars,
               inheritance_groups, inherit_groups)
    if options['verbosity'] > 0:
        print >> sys.stderr, ('Building API documentation for %d modules.' %
                              len(modules))
    progress = _Progress('Building docs for', verbosity, len(modules))

    for module in modules:
        progress.report(module.__name__)
        # Add the module.  Catch any exceptions that get generated.
        try:
            d.add(module)
        except Exception, e:
            if options['debug']: raise
            else: _internal_error(e)
        except:
Example #3
0
def document(options, progress, cancel):
    """
    Create the documentation for C{modules}, using the options
    specified by C{options}.  C{document} is designed to be started in
    its own thread by L{EpydocGUI._go}.

    @param options: The options to use for generating documentation.
        This includes keyword options that can be given to
        L{html.HTMLFormatter}, as well as the option C{outdir}, which
        controls where the output is written to.
    @type options: C{dictionary}
    @param progress: This first element of this list will be modified
        by C{document} to reflect its progress.  This first element
        will be a number between 0 and 1 while C{document} is creating
        the documentation; and the string C{"done"} once it finishes
        creating the documentation.
    @type progress: C{list}
    """
    progress[0] = 0.02
    from epydoc.html import HTMLFormatter
    from epydoc.objdoc import DocMap, report_param_mismatches
    from epydoc.imports import import_module, find_modules
    from epydoc.objdoc import set_default_docformat

    # Set the default docformat.
    set_default_docformat(options.get('docformat', 'epytext'))

    try:
        # Import the modules.
        modnames = options['modules']
        # First, expand packages.
        for name in modnames[:]:
            if os.path.isdir(name):
                modnames.remove(name)
                new_modules = find_modules(name)
                if new_modules: modnames += new_modules
                sys.stderr.write('!!!Error: %r is not a pacakge\n!!!' % name)
                
        modules = []
        for (name, num) in zip(modnames, range(len(modnames))):
            if cancel[0]: exit_thread()
            sys.stderr.write('***Importing %s\n***' % name)
            try:
                module = import_module(name)
                if module not in modules: modules.append(module)
            except ImportError, e:
                sys.stderr.write('!!!Error importing %s: %s\n!!!' % (name, e))
            progress[0] += (IMPORT_PROGRESS*0.98)/len(modnames)
        
        # Create the documentation map.
        verbosity = 0
        document_bases = 1
        document_autogen_vars = 1
        inheritance_groups = (options['inheritance'] == 'grouped')
        inherit_groups = (options['inheritance'] != 'grouped')
        d = DocMap(verbosity, document_bases, document_autogen_vars,
                   inheritance_groups, inherit_groups)
    
        # Build the documentation.
        for (module, num) in zip(modules, range(len(modules))):
            if cancel[0]: exit_thread()
            sys.stderr.write('***Building docs for %s\n***' % module.__name__)
            d.add(module)
            progress[0] += (BUILD_PROGRESS*0.98)/len(modules)

        # Report any param inheritance mismatches.
        report_param_mismatches(d)

        # Create the HTML formatter.
        htmldoc = HTMLFormatter(d, **options)
        numfiles = htmldoc.num_files()
    
        # Set up the progress callback.
        n = htmldoc.num_files()
        def progress_callback(path, numfiles=numfiles,
                              progress=progress, cancel=cancel, num=[1]):
            if cancel[0]: exit_thread()

            # Find the short name of the file we're writing.
            (dir, file) = os.path.split(path)
            (root, d) = os.path.split(dir)
            if d in ('public', 'private'): fname = os.path.join(d, file)
            else: fname = file
                
            sys.stderr.write('***Writing %s\n***' % fname)
            progress[0] += (WRITE_PROGRESS*0.98)/numfiles
            num[0] += 1
    
        # Write the documentation.
        htmldoc.write(options.get('outdir', 'html'), progress_callback)
    
        # We're done.
        sys.stderr.write('***Finished!\n***')
        progress[0] = 'done'
Example #4
0
        elif uid.is_routine(): return 'function'
        elif uid.is_variable(): return 'variable'
        else: raise AssertionError, 'Bad UID type for _name'

    def _name(self, uid):
        if uid.parent():
            parent = uid.parent()
            name = '%s %s in %s %s' % (self._kind(uid),
                                       self._bold(uid.shortname()),
                                       self._kind(parent),
                                       self._bold(parent.name()))
        else:
            name = '%s %s' % (self._kind(uid), self._bold(uid.name()))
        return '%s    %s\n\n' % (self._title('NAME'), name)

    def _descr(self, uid, doc):
        if not doc.descr(): return ''
        descr = doc.descr().to_plaintext(None, indent=4)
        return '%s%s' % (self._title('DESCRIPTION'), descr)

if __name__ == '__main__':
    docmap = DocMap(document_bases=1)

    uids = [findUID(name) for name in sys.argv[1:]]
    uids = [uid for uid in uids if uid is not None]
    for uid in uids: docmap.add(uid.value())

    formatter = ManFormatter(docmap)
    for uid in uids:
        print formatter.documentation(uid)