Пример #1
0
 # Parse the arguments.
 for (opt, val) in opts:
     if opt in ('--builtins',):
         modules += sys.builtin_module_names
         modules.remove('__main__')
     elif opt in ('--check',): options['action'] = 'check'
     elif opt in ('--command-line-order', '--command_line_order'):
         options['alphabetical'] = 0
     elif opt in ('--css', '-c'): options['css'] = val
     elif opt in ('--debug',):
         options['debug'] = 1
         options['verbosity'] += 4
     elif opt in ('--dvi',): options['action'] = 'dvi'
     elif opt in ('--docformat', '--doc-format', '--doc_format'):
         from epydoc.objdoc import set_default_docformat
         set_default_docformat(val)
     elif opt in ('--help', '-?', '--usage', '-h'): _help(val)
     elif opt in ('--helpfile', '--help-file', '--help_file'):
         options['help'] = val
     elif opt in ('--html',): options['action'] = 'html'
     elif opt in ('--ignore_param_mismatch', '--ignore-param-mismatch'):
         options['ignore_param_mismatch'] = 1
     elif opt in ('--inheritance', '--inheritence'):
         options['inheritance']=val.lower()
     elif opt in ('--latex',): options['action']='latex'
     elif opt in ('--name', '-n'): options['prj_name']=val
     elif opt in ('--navlink', '--nav-link', '--nav_link'):
         options['prj_link'] = val
     elif opt in ('--no-frames', '--no_frames', '--noframes'):
         options['frames'] = 0
     elif opt in ('--no-private', '--no_private'): options['private']=0
Пример #2
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'