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'
% 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: if options['debug']: raise else: _internal_error() if not options['ignore_param_mismatch']: if not report_param_mismatches(d): estr = ' (To supress these warnings, ' estr += 'use --ignore-param-mismatch)' print >>sys.stderr, estr return d def _run(cmd, options): from epydoc.markup import wordwrap if '|' in cmd: name = cmd.split('|')[1].strip().split(' ', 1)[0] else: name = cmd.strip().split(' ', 1)[0] if options['verbosity'] == 1: print >>sys.stderr, 'Running %s...' % name elif options['verbosity'] > 1: cmd_str = wordwrap(`cmd`, 10+len(name)).lstrip() print >>sys.stderr, 'Running %s' % cmd_str.rstrip()
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: if options['debug']: raise else: _internal_error() if not options['ignore_param_mismatch']: if not report_param_mismatches(d): estr = ' (To supress these warnings, ' estr += 'use --ignore-param-mismatch)' print >> sys.stderr, estr return d HEADER = """<?xml version="1.0" encoding="utf-8" ?> <XMI xmi.version="1.1" xmlns:UML="org.omg/standards/UML"> <XMI.header> <XMI.metamodel name="UML" version="1.3" href="UML.xml"/> <XMI.model name="PyXMPP" href="pyxmpp.xml"/> </XMI.header> <XMI.content> <UML:Model>