Esempio n. 1
0
    def add_module(self, name, check=0):
        from epydoc.imports import import_module, find_modules

        # First, expand packages.
        if os.path.isdir(name):
            module_names = find_modules(name)
            if not module_names:
                sys.stderr.write('!!!Error: %r is not a pacakge\n!!!' % name)
                self._update_messages()
                self._root.bell()
        else:
            module_names = [name]

        for name in module_names:
            # Check that it's a good module, if requested.
            if check:
                try: import_module(name)
                except ImportError, e:
                    print >>sys.stderr, e
                    self._update_messages()
                    self._root.bell()
                    continue

            # Add the module to the list of modules.
            self._module_list.insert('end', name)
            self._module_list.yview('end')
Esempio n. 2
0
def _import(module_names, verbosity):
    """
    @return: A list of the modules contained in the given files.
        Duplicates are removed.  Order is preserved.
    @rtype: C{list} of C{module}
    @param module_names: The list of module filenames.
    @type module_names: C{list} of C{string}
    @param verbosity: Verbosity level for tracing output.
    @type verbosity: C{int}
    """
    from epydoc.imports import import_module, find_modules

    # First, expand packages.
    for name in module_names[:]:
        if os.path.isdir(name):
            # In-place replacement.
            index = module_names.index(name)
            new_modules = find_modules(name)
            if new_modules:
                module_names[index:index+1] = new_modules
            elif verbosity >= 0:
                if sys.stderr.softspace: print >>sys.stderr
                print  >>sys.stderr, 'Error: %r is not a pacakge' % name

    if verbosity > 0:
        print >>sys.stderr, 'Importing %s modules.' % len(module_names)
    modules = []
    progress = _Progress('Importing', verbosity, len(module_names))
    
    for name in module_names:
        progress.report(name)
        # Import the module, and add it to the list.
        try:
            module = import_module(name)
            if module not in modules: modules.append(module)
            elif verbosity > 2:
                if sys.stderr.softspace: print >>sys.stderr
                print >>sys.stderr, '  (duplicate)'
        except ImportError, e:
            if verbosity >= 0:
                if sys.stderr.softspace: print >>sys.stderr
                print  >>sys.stderr, e
Esempio n. 3
0
def _import(module_names, verbosity):
    """
    @return: A list of the modules contained in the given files.
        Duplicates are removed.  Order is preserved.
    @rtype: C{list} of C{module}
    @param module_names: The list of module filenames.
    @type module_names: C{list} of C{string}
    @param verbosity: Verbosity level for tracing output.
    @type verbosity: C{int}
    """
    from epydoc.imports import import_module, find_modules

    # First, expand packages.
    for name in module_names[:]:
        if os.path.isdir(name):
            # In-place replacement.
            index = module_names.index(name)
            new_modules = find_modules(name)
            if new_modules:
                module_names[index:index + 1] = new_modules
            elif verbosity >= 0:
                if sys.stderr.softspace: print >> sys.stderr
                print >> sys.stderr, 'Error: %r is not a pacakge' % name

    if verbosity > 0:
        print >> sys.stderr, 'Importing %s modules.' % len(module_names)
    modules = []
    progress = _Progress('Importing', verbosity, len(module_names))

    for name in module_names:
        progress.report(name)
        # Import the module, and add it to the list.
        try:
            module = import_module(name)
            if module not in modules: modules.append(module)
            elif verbosity > 2:
                if sys.stderr.softspace: print >> sys.stderr
                print >> sys.stderr, '  (duplicate)'
        except ImportError, e:
            if verbosity >= 0:
                if sys.stderr.softspace: print >> sys.stderr
                print >> sys.stderr, e
Esempio n. 4
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'