def run(self): if self.package: import pydoc cwd = os.getcwd() self.mkpath(self.build_dir) os.chdir(self.build_dir) try: pydoc.writedocs(os.path.join(cwd, self.package), pkgpath=self.package+'.') except: if not self.dry_run: os.chdir(cwd) raise os.chdir(cwd)
def main(): parser = optparse.OptionParser() parser.add_option( '-w', '--write', dest='dir', metavar='FILE', default=os.path.join(os.getcwd(), 'pyauto_docs'), help=('Directory path to write all of the documentation. ' 'Defaults to "pyauto_docs" in current directory.')) parser.add_option('-p', '--pyautolib', dest='pyautolib', metavar='FILE', default=os.getcwd(), help='Location of pyautolib directory') (options, args) = parser.parse_args() if not os.path.isdir(options.dir): os.makedirs(options.dir) # Add these paths so pydoc can find everything sys.path.append(os.path.join(options.pyautolib, '../../../third_party/')) sys.path.append(options.pyautolib) # Get a snapshot of the current directory where pydoc will export the files previous_contents = set(os.listdir(os.getcwd())) pydoc.writedocs(options.pyautolib) current_contents = set(os.listdir(os.getcwd())) if options.dir == os.getcwd(): print 'Export complete, files are located in %s' % options.dir return new_files = current_contents.difference(previous_contents) for file_name in new_files: basename, extension = os.path.splitext(file_name) if extension == '.html': # Build the complete path full_path = os.path.join(os.getcwd(), file_name) existing_file_path = os.path.join(options.dir, file_name) if os.path.isfile(existing_file_path): os.remove(existing_file_path) shutil.move(full_path, options.dir) print 'Export complete, files are located in %s' % options.dir
def handle(self, *args, **options): moduleDir = args[0] docDir = args[1] origDir = os.getcwd() sys.path.append(moduleDir) try: os.chdir(docDir) except OSError: os.mkdir(docDir) os.chdir(docDir) print 'Building docs...' pydoc.writedocs(moduleDir) # attempt to add the new docs to git os.chdir(moduleDir) os.system('find . -name *.html | xargs git add') os.chdir(origDir)
def myWritedocs(dir, pkgpath='', done=None): """Write out HTML documentation for all modules in a directory tree.""" if done is None: done = {} for file in os.listdir(dir): path = os.path.join(dir, file) if ispackage(path): writedocs(path, pkgpath + file + '.', done) elif os.path.isfile(path): modname = inspect.getmodulename(path) if modname: if modname == '__init__': modname = pkgpath[:-1] # remove trailing period else: modname = pkgpath + modname if modname not in done: done[modname] = 1 try: writedoc(modname) except: print 'failed to document', modname
def main(): parser = optparse.OptionParser() parser.add_option('-w', '--write', dest='dir', metavar='FILE', default=os.path.join(os.getcwd(), 'pyauto_docs'), help=('Directory path to write all of the documentation. ' 'Defaults to "pyauto_docs" in current directory.')) parser.add_option('-p', '--pyautolib', dest='pyautolib', metavar='FILE', default=os.getcwd(), help='Location of pyautolib directory') (options, args) = parser.parse_args() if not os.path.isdir(options.dir): os.makedirs(options.dir) # Add these paths so pydoc can find everything sys.path.append(os.path.join(options.pyautolib, '../../../third_party/')) sys.path.append(options.pyautolib) # Get a snapshot of the current directory where pydoc will export the files previous_contents = set(os.listdir(os.getcwd())) pydoc.writedocs(options.pyautolib) current_contents = set(os.listdir(os.getcwd())) if options.dir == os.getcwd(): print 'Export complete, files are located in %s' % options.dir return 1 new_files = current_contents.difference(previous_contents) for file_name in new_files: basename, extension = os.path.splitext(file_name) if extension == '.html': # Build the complete path full_path = os.path.join(os.getcwd(), file_name) existing_file_path = os.path.join(options.dir, file_name) if os.path.isfile(existing_file_path): os.remove(existing_file_path) shutil.move(full_path, options.dir) print 'Export complete, files are located in %s' % options.dir return 0
def write_docs(dirname='../../py_progs'): ''' Locate all of the .py files in dirname and write out help in the current working directory using pydocs ''' # First, we delete all the existing documentation in this directory for item in os.listdir('.'): if item.endswith(".html"): os.remove(item) # Now, we write new docs pydoc.writedocs(dirname) # Now make a page that points to all the html pages # that have already been made roots = [ item.replace('.py', '') for item in os.listdir(dirname) if item.endswith('.py') ] make_toplevel(dirname, roots) # Now check that we have the files we expected got_all = True for root in roots: if not os.path.isfile(root + '.html'): print('Failed to create an html file for %s.py' % root) got_all = False if got_all: print('html files were created for all of the .py scripts') return 0 print( 'Failed to generate documentation for some files.\n' 'Please look at the earlier output to find more details on the error.') return 1 # Return nonzero to indicate error
EYDOC_OUTPUT_DIR = str(PROJECT_BASE)+"/build/docs/python/epydoc" print "PYDOC_OUTPUT_DIR: " + PYDOC_OUTPUT_DIR print "EYDOC_OUTPUT_DIR: " + EYDOC_OUTPUT_DIR try: shutil.rmtree(PROJECT_BASE+"/build/docs/python") except: pass os.makedirs(PYDOC_OUTPUT_DIR) os.chdir(PROJECT_BASE+"/src/main/api_shim") # pydoc # Replace some of the pydoc methods to all them to work with java inheritance pydoc.html = CustomHTMLDoc() pydoc.inspect.classify_class_attrs = custom_classify_class_attrs pydoc.inspect.getclasstree = custom_getclasstree pydoc.writedoc = custom_writedoc pydoc.writedocs("./") pydoc.html.write_index() print "\n\n" # epydoc import epydoc.cli class Options(object): def __init__(self, defaults): for (attr, val) in defaults.items(): setattr(self, attr, val) def __getattr__(self, name): return None options = Options(epydoc.cli.option_defaults()) options.introspect = False options.default_target = EYDOC_OUTPUT_DIR
import os, pydoc if __name__ == "__main__": try: os.mkdir('../html') except: pass os.chdir('../html') pydoc.writedocs('../python')
import sys import os import pydoc import re mybasedir = "../src" mydocsdir = "../docs" myfile = "FIASFileDownloader.html" sys.path.append(mybasedir) pydoc.writedocs(mybasedir) with open(myfile) as f: content = f.read() if os.path.exists(myfile): os.rename(myfile, mydocsdir + "/" + myfile) myregex = re.findall(r'(?<=<a href=")([^"]*).html', content) for mymodule in myregex: pydoc.writedoc(mymodule) mydochtml = mymodule + ".html" if os.path.exists(mydochtml): os.rename(mydochtml, mydocsdir + "/" + mydochtml) print "Process completed"
################################################################################ # # Generate documentation with pydoc # ################################################################################ if sys.argv[1] == "sdist": import os, os.path import pydoc os.chdir("doc") moddir = os.path.join(os.pardir, "i2py") sys.path.insert(0, moddir) pydoc.writedocs(moddir, "i2py.") sys.path.pop(0) os.chdir(os.pardir) ################################################################################ # # Run setup() # ################################################################################ # Grab the description from the package's doc string desc = i2py.__doc__.split("\n\n") setup(
print "PYDOC_OUTPUT_DIR: " + PYDOC_OUTPUT_DIR print "EYDOC_OUTPUT_DIR: " + EYDOC_OUTPUT_DIR try: shutil.rmtree(PROJECT_BASE + "/build/docs/python") except: pass os.makedirs(PYDOC_OUTPUT_DIR) os.chdir(PROJECT_BASE + "/src/main/python_scripts") # pydoc # Replace some of the pydoc methods to all them to work with java inheritance pydoc.html = CustomHTMLDoc() pydoc.inspect.classify_class_attrs = custom_classify_class_attrs pydoc.inspect.getclasstree = custom_getclasstree pydoc.writedoc = custom_writedoc pydoc.writedocs("./") pydoc.html.write_index() print "\n\n" # epydoc import epydoc.cli class Options(object): def __init__(self, defaults): for (attr, val) in defaults.items(): setattr(self, attr, val) def __getattr__(self, name): return None
def _make_docs(self, src): print('making htmls for ' + src) pydoc.writedocs(src) print(os.listdir())
import i2py ################################################################################ # # Generate documentation with pydoc # ################################################################################ if len(sys.argv) > 1: if sys.argv[1] == 'sdist': import os, os.path import pydoc os.chdir('doc') moddir = os.path.join(os.pardir, 'i2py') sys.path.insert(0, moddir) pydoc.writedocs(moddir, 'i2py.') sys.path.pop(0) os.chdir(os.pardir) ################################################################################ # # Run setup() # ################################################################################ # Grab the description from the package's doc string desc = i2py.__doc__.split('\n\n') setup( name='i2py', version=i2py.__version__,
def gotResults_documentation(self,words,fullResults): oldPath = os.getcwd() uniGrammars = self.ini.getList('documentation', 'unimacro grammars') uniModules = self.ini.getList('documentation', 'unimacro modules') otherGrammars = self.ini.getList('documentation', 'other grammars') otherModules = self.ini.getList('documentation', 'other modules') base = natqh.getUnimacroUserDirectory() docPath = os.path.join(base, 'doc') pickleFile = os.path.join(docPath, '@unimacro.pickle') try: psock = open(pickleFile, 'r') memory = pickle.load(psock) psock.close() print '--------------------memory from pickle: %s'% pickleFile except: memory = {} print '--------------------no or invalid pickle file: %s'% pickleFile utilsqh.createFolderIfNotExistent(docPath) os.chdir(docPath) self.DisplayMessage('writing documentation to: %s'% docPath) pydoc.writedocs(base) self.DisplayMessage('checking unimacro grammars, modules and other grammars, modules') loadedGrammars = natlinkmain.loadedFiles.keys() if 'unimacro grammars' not in memory: memory['unimacro grammars'] = {} mem = memory['unimacro grammars'] for m in uniGrammars: if m in loadedGrammars: mem[m] = sys.modules[m].__doc__ else: if not m in mem: mem[m] = '' if 'unimacro modules' not in memory: memory['unimacro modules'] = {} mem = memory['unimacro modules'] for m in uniModules: if m in sys.modules: mem[m] = sys.modules[m].__doc__ else: try: M = __import__(m) except ImportError: print 'cannot import module: %s'% m continue mem[m] = M.__doc__ mem[m] = M.__doc__ del M print 'writing to pickle file: %s'% pickleFile psock = open(pickleFile, 'w') pickle.dump(memory, psock) psock.close() L = [] htmlFiles = filter(isHtmlFile, os.listdir(docPath)) categories = self.ini.get('documentation') if not categories: self.DisplayMessage('please fill in documentation categories') for c in categories: if not c in memory: continue L.append("<H1>%s</H1>"% c) mem = memory[c] for m in mem: file = m+'.html' if os.path.isfile(os.path.join(docPath, m+'.html')): link = "<a href=%s.html>%s</a>"% (m, m) htmlFiles.remove(file) else: link = "???%s"% m if mem[m] == None: text = 'no doc string for this module' elif mem[m] == '': text = 'module could not be loaded, possibly start program and do "Make documentation" again' else: text = mem[m] if text.find('\n\n'): T = text.split('\n\n') text = T[0] L.append("<p>%s: %s</p>"% (link, text)) if htmlFiles: M = [] L.append("<H1>%s</H1>"% "other files") for f in htmlFiles: if f == 'index.html': continue name = f.split('.')[0] link = "<a href=%s>%s</a>"% (f, name) M.append(link) L.append("<p>%s</p>"% ', '.join(M)) HTMLpage = '''<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Natlink grammars and modules documentations</title> <style type="text/css"><!-- TT { font-family: lucidatypewriter, lucida console, courier } --></style></head><body bgcolor="#f0f0f8"> %s </body></html>''' % '\n'.join(L) fsock = open(os.path.join(docPath, 'index.html'), 'w') fsock.write(HTMLpage) fsock.close() os.chdir(oldPath) self.DisplayMessage('okay')
import os OUTPUT_DIR = "api" SOURCE_DIR = r"..\..\src" cwd = os.getcwd() os.chdir(OUTPUT_DIR) for fn in os.listdir("."): (base,ext) = os.path.split(fn) if ext == '.html': os.remove(fn) import pydoc pydoc.writedocs(SOURCE_DIR) os.chdir(cwd)
def update_event(self, inp=-1): self.set_output_val( 0, pydoc.writedocs(self.input(0), self.input(1), self.input(2)))
################################################################################ # # Generate documentation with pydoc # ################################################################################ if len(sys.argv) > 1 : if sys.argv[1] == 'sdist': import os, os.path import pydoc os.chdir('doc') moddir = os.path.join(os.pardir, 'i2py') sys.path.insert(0, moddir) pydoc.writedocs(moddir, 'i2py.') sys.path.pop(0) os.chdir(os.pardir) ################################################################################ # # Run setup() # ################################################################################ # Grab the description from the package's doc string desc = i2py.__doc__.split('\n\n') setup(name='i2py',
import sys sys.path.append('../pyllprof') import pydoc import sys import os import pyllprof os.mkdir("pydocs") os.chdir("pydocs") pydoc.writedocs("/usr/lib/python2.7")
def handle_noargs(self, **options): import pydoc import settings pydoc.writedocs(settings.rootPath)
def gotResults_documentation(self, words, fullResults): oldPath = os.getcwd() uniGrammars = self.ini.getList('documentation', 'unimacro grammars') uniModules = self.ini.getList('documentation', 'unimacro modules') otherGrammars = self.ini.getList('documentation', 'other grammars') otherModules = self.ini.getList('documentation', 'other modules') base = natqh.getUnimacroUserDirectory() docPath = os.path.join(base, 'doc') pickleFile = os.path.join(docPath, '@unimacro.pickle') try: psock = open(pickleFile, 'r') memory = pickle.load(psock) psock.close() print '--------------------memory from pickle: %s' % pickleFile except: memory = {} print '--------------------no or invalid pickle file: %s' % pickleFile utilsqh.createFolderIfNotExistent(docPath) os.chdir(docPath) self.DisplayMessage('writing documentation to: %s' % docPath) pydoc.writedocs(base) self.DisplayMessage( 'checking unimacro grammars, modules and other grammars, modules') loadedGrammars = natlinkmain.loadedFiles.keys() if 'unimacro grammars' not in memory: memory['unimacro grammars'] = {} mem = memory['unimacro grammars'] for m in uniGrammars: if m in loadedGrammars: mem[m] = sys.modules[m].__doc__ else: if not m in mem: mem[m] = '' if 'unimacro modules' not in memory: memory['unimacro modules'] = {} mem = memory['unimacro modules'] for m in uniModules: if m in sys.modules: mem[m] = sys.modules[m].__doc__ else: try: M = __import__(m) except ImportError: print 'cannot import module: %s' % m continue mem[m] = M.__doc__ mem[m] = M.__doc__ del M print 'writing to pickle file: %s' % pickleFile psock = open(pickleFile, 'w') pickle.dump(memory, psock) psock.close() L = [] htmlFiles = filter(isHtmlFile, os.listdir(docPath)) categories = self.ini.get('documentation') if not categories: self.DisplayMessage('please fill in documentation categories') for c in categories: if not c in memory: continue L.append("<H1>%s</H1>" % c) mem = memory[c] for m in mem: file = m + '.html' if os.path.isfile(os.path.join(docPath, m + '.html')): link = "<a href=%s.html>%s</a>" % (m, m) htmlFiles.remove(file) else: link = "???%s" % m if mem[m] == None: text = 'no doc string for this module' elif mem[m] == '': text = 'module could not be loaded, possibly start program and do "Make documentation" again' else: text = mem[m] if text.find('\n\n'): T = text.split('\n\n') text = T[0] L.append("<p>%s: %s</p>" % (link, text)) if htmlFiles: M = [] L.append("<H1>%s</H1>" % "other files") for f in htmlFiles: if f == 'index.html': continue name = f.split('.')[0] link = "<a href=%s>%s</a>" % (f, name) M.append(link) L.append("<p>%s</p>" % ', '.join(M)) HTMLpage = '''<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Natlink grammars and modules documentations</title> <style type="text/css"><!-- TT { font-family: lucidatypewriter, lucida console, courier } --></style></head><body bgcolor="#f0f0f8"> %s </body></html>''' % '\n'.join(L) fsock = open(os.path.join(docPath, 'index.html'), 'w') fsock.write(HTMLpage) fsock.close() os.chdir(oldPath) self.DisplayMessage('okay')
import os import pydoc import sys if __name__ == '__main__': if len(sys.argv) < 2: print('Usage: {} /path/to/py/project'.format( os.path.split(__file__)[-1])) exit(-1) path = sys.argv[1] docs_dir = os.path.join(os.path.split(__file__)[0], 'doc') if not os.path.exists(docs_dir): os.makedirs(docs_dir) os.chdir(docs_dir) pydoc.writedocs(path) try: html = '.'.join([os.path.split(__file__)[-1].split('.')[0], 'html']) os.remove(html) except FileNotFoundError: pass
import sys sys.path.append('../pyllprof') import pydoc import sys import os import pyllprof os.mkdir("pydocs") os.chdir("pydocs") pydoc.writedocs("/usr/lib/python3.1")