def do_GET(self): # Deny favicon shortcut early. if self.path == "/favicon.ico": return None importlib.invalidate_caches() code = 200 if self.path == "/": modules = [pdoc.import_module(module, reload=True) for module in self.args.modules] modules = sorted((module.__name__, inspect.getdoc(module)) for module in modules) out = pdoc._render_template('/html.mako', modules=modules, **self.template_config) elif self.path.endswith(".ext"): # External links are a bit weird. You should view them as a giant # hack. Basically, the idea is to "guess" where something lives # when documenting another module and hope that guess can actually # track something down in a more global context. # # The idea here is to start specific by looking for HTML that # exists that matches the full external path given. Then trim off # one component at the end and try again. # # If no HTML is found, then we ask `pdoc` to do its thang on the # parent module in the external path. If all goes well, that # module will then be able to find the external identifier. import_path = self.path[:-4].lstrip("/") resolved = self.resolve_ext(import_path) if resolved is None: # Try to generate the HTML... print("Generating HTML for %s on the fly..." % import_path, file=sys.stderr) try: out = pdoc.html(import_path.split(".")[0], **self.template_config) except Exception as e: print('Error generating docs: {}'.format(e), file=sys.stderr) # All hope is lost. code = 404 out = "External identifier <code>%s</code> not found." % import_path else: return self.redirect(resolved) # Redirect '/pdoc' to '/pdoc/' so that relative links work # (results in '/pdoc/cli.html' instead of 'cli.html') elif not self.path.endswith(('/', '.html')): return self.redirect(self.path + '/') # Redirect '/pdoc/index.html' to '/pdoc/' so it's more pretty elif self.path.endswith(pdoc._URL_PACKAGE_SUFFIX): return self.redirect(self.path[:-len(pdoc._URL_PACKAGE_SUFFIX)] + '/') else: try: out = self.html() except ImportError: code = 404 out = "Module <code>%s</code> not found." % self.import_path_from_req_url self.send_response(code) self.send_header("Content-type", "text/html; charset=utf-8") self.end_headers() self.echo(out)
def build_docs(dest_path='code/docs'): orig_path = os.getcwd() for lib in ['awsclients', 'cfnpipeline', 'logger']: sys.path.append('%s/code/lambda_functions/lib/%s' % (orig_path, lib)) try: import pdoc except ImportError: import pip pip.main(['install', 'pdoc']) import pdoc try: import boto3 except ImportError: import pip pip.main(['install', 'boto3']) import boto3 try: os.mkdir(dest_path) except OSError as e: if e.errno == 17: pass else: raise for lib in ['awsclients', 'cfnpipeline', 'logger']: f = open('%s/%s/%s.html' % (orig_path, dest_path, lib), 'w') f.write(pdoc.html(lib)) f.close()
def create_help_page(module,output_format='html',file_path=None): """Uses the pdoc module to create a html autogenerated help file for the specified module. If file_path is not specified it auto names it and saves it in the current working directory.""" if re.search('htm',output_format,re.IGNORECASE): html_text=pdoc.html(module_name=module,allsubmodules=True) if file_path is None: file_path=auto_name(module.replace('.','_'),'Help',directory=None,extension='html') out_file=open(file_path,'w') out_file.write(html_text) out_file.close() elif re.search('htm',output_format,re.IGNORECASE): html_text=pdoc.html(module_name=module,allsubmodules=True) if file_path is None: file_path=auto_name(module,'Help',directory=None,extension='html') out_file=open(file_path,'w') out_file.write(html_text) out_file.close()
def html(self): """ Retrieves and sends the HTML belonging to the path given in URL. This method is smart and will look for HTML files already generated and account for whether they are stale compared to the source code. """ # TODO: pass extra pdoc.html() params return pdoc.html(self.import_path_from_req_url, http_server=True)
def build_pages(): for mdl in submodules: print('building {}'.format(mdl)) html_input = pdoc.html(mdl) fname = mdl.split('.')[-1] + '.m.html' fil = open(fname, 'w') fil.write(html_input) fil.close() #this works? idk return
def make_html(moduleName_full): h = pdoc.html(moduleName_full) moduleName = moduleName_full.split('.')[-1] f = open("docs/{0}.html".format(moduleName), 'w') f.write(h) f.close()
def html(self): """ Retrieves and sends the HTML belonging to the path given in URL. This method is smart and will look for HTML files already generated and account for whether they are stale compared to the source code. """ return pdoc.html(self.import_path_from_req_url, reload=True, http_server=True, external_links=True, **self.template_config)
def generate_htmls(docs_dir, toplevel_name, show_source_code=True): toplevel = load_toplevel(toplevel_name) for module in recurse_modules(toplevel): module_file = module_path(docs_dir, module, ".html") touch(module_file) with open(module_file, "w") as file: html = pdoc.html(module.name, docfilter=exclude_filter, show_source_code=show_source_code) file.write(html.replace("…", "")) # remove ellipses from HTML
def main(): for m in documented_sdk_modules: html = pdoc.html(m, allsubmodules=True) with open(module_to_docpath(m), 'w') as f: f.write(html) import mycroft mycroft.__all__ = [m[8:] for m in documented_sdk_modules] root_module = pdoc.Module(mycroft) html = root_module.html(external_links=False, link_prefix='', source=True) with open(module_to_docpath("mycroft"), 'w') as f: f.write(html)
def create_help_page(module, output_format='html', file_path=None): """Uses the pdoc module to create a html autogenerated help file for the specified module. If file_path is not specified it auto names it and saves it in the current working directory.""" if re.search('htm', output_format, re.IGNORECASE): html_text = pdoc.html(module_name=module, allsubmodules=True) if file_path is None: file_path = auto_name(module.replace('.', '_'), 'Help', directory=None, extension='html') out_file = open(file_path, 'w') out_file.write(html_text) out_file.close()
def make_html(moduleName_full): print("Creating docs for `{0}` module".format(moduleName_full)) h = pdoc.html(moduleName_full) h = "Version: {0}".format(currentVersion) + "\n" + h moduleName = moduleName_full.split('.')[-1] f = open("../docs/{0}.html".format(moduleName), 'w') f.write(h) f.close()
def gen_docs(sample_module_name): """ Generates pdocs from sample module, and the template intentionally skip the module doc string because we use that for the sample description at top of the sample page. See gen_desc function below. """ docs = None if sample_module_name is not None: logger.debug("Generating sample docs") pdoc.tpl_lookup.directories.insert(0, settings.DOC_TEMPLATE_DIR) try: docs = pdoc.html(sample_module_name) docs = docs.split('<article id="content">') docs = docs[1] docs = docs.split('</article>') docs = docs[0] except: e = sys.exc_info()[0] tb = traceback.format_exc() logger.error("Error generating docs: %s. Traceback: %s", e, tb) docs = "There was an error while generating the sample docs." return docs
import pdoc import re # # pydoc # # Write to text file #file_name = './smuview_python_bindings_pydoc.txt' #f = open(file_name, 'w') #sys.stdout = f #pydoc.help(smuview) #f.close() #sys.stdout = sys.__stdout__ # Write html file to current directory #pydoc.writedoc(smuview) # # pdoc3 # # Install: # $ pip3 install pdoc3 # html_str = pdoc.html("smuview", show_type_annotations=True) file_name = './smuview_python_bindings_pdoc3.html' f = open(file_name, 'w') print(html_str, file=f) f.close()
output_dir = os.path.join(dir_path, package) try: os.mkdir(output_dir) except FileExistsError: pass # Loop through each method and write # the html files for ndx, name in enumerate(doc.doc): def the_filter(x): if x.name == name: return True # Get one method otpt = pdoc.html(doc, docfilter=the_filter) # Trim all the unnecessary html tags parser.parseStr(otpt) k = parser.getElementById("header-functions") v = k.getParentElementCustomFilter( lambda x: x.nodeName == 'section') v.removeChild(k) # Add the front matter and write body = html_template.replace("{section}", v.toHTML()) front_matter = make_front_matter(name, ndx) output_name = os.path.join(output_dir, name + '.html') with open(output_name, 'w') as fptr: fptr.write(front_matter + body)
def generate_doc(module_name): rd_doc = pdoc.html('von_mises_fisher.{0}'.format(module_name)) rd_doc_filename = os.path.join(DOCS_ROOT, module_name) + '.html' f = open(rd_doc_filename, 'w') f.write(rd_doc) f.close()
def return_help(object): """Returns an html help page autogenerated by the pdoc module for any live object""" module=inspect.getmodule(object).__name__ html_text=pdoc.html(module_name=module,allsubmodules=True) return html_text
import pdoc s = pdoc.html('bayesian_bootstrap.bootstrap') with open('bootstrap_documentation.html', 'w') as f: f.write(s)
import example import pdoc with open('example.html', 'w') as f: f.write(pdoc.html("example"))
import pdoc import os # os.chdir('D:\MPhil\Python\My_Python_Modules\Modelling_Tools\PyCoTools') os.chdir(r'..\Documentation') pyd= pdoc.html('pydentify2') cp= pdoc.html('pycopi') pea= pdoc.html('PEAnalysis') with open('pydentify2.html','w') as f: f.write(pyd) # with open('pycpoi.html','w') as f: f.write(cp) with open('PEAnalysis.html','w') as f: f.write(pea)
def preproccessing_doc(): ''' Generates HTML documentation for preprocessing.py. ''' return pdoc.html('preprocessing')
def app_doc(): ''' Generates HTML documentation for app.py. ''' return pdoc.html('app')
def return_help(object): """Returns an html help page autogenerated by the pdoc module for any live object""" module = inspect.getmodule(object).__name__ html_text = pdoc.html(module_name=module, allsubmodules=True) return html_text
""" import pdoc import wisps submodules = [ 'wisps.simulations', 'wisps.simulations.model', 'wisps.data_analysis.image', 'wisps.data_analysis.indices', 'wisps.data_analysis.photometry', 'wisps.data_analysis.spex_indices', 'wisps.data_analysis.spectrum_tools', 'wisps.data_analysis.selection_criteria', 'wisps.data_analysis.plot_spectrum' ] #build index.hmtl main_html = pdoc.html('wisps.data_analysis') main_file = open('index.html', 'w') main_file.write(main_html) main_file.close() def build_pages(): for mdl in submodules: print('building {}'.format(mdl)) html_input = pdoc.html(mdl) fname = mdl.split('.')[-1] + '.m.html' fil = open(fname, 'w') fil.write(html_input) fil.close() #this works? idk return
doc.name.startswith('assert') or doc.name.startswith('fail') or doc.name in FILTERED_METHODS ): return False return True if sys.argv[1] == 'document': # Automatically update the documentation import pdoc doc_dir = path.abspath(path.join(path.dirname(__file__), 'docs')) template_dir = path.join(doc_dir, 'templates') pdoc.tpl_lookup = pdoc.TemplateLookup(directories=[template_dir]) pdoc._template_path = [template_dir] docs = pdoc.html('keteparaha', docfilter=doc_filter, external_links=True, source=False) with open(path.join(doc_dir, 'index.html'), 'w') as f: f.write(docs) sys.exit(0) # To update the package on pypi: python setup.py sdist upload setup( name='keteparaha', version='0.0.24', packages=['keteparaha'], license='MIT', author="Hansel Dunlop", author_email='*****@*****.**', url='https://github.com/aychedee/keteparaha/', description='Keteparaha is a tool for testing modern JS heavy websites',
def physpy_test_suite(): test_loader = unittest.TestLoader() test_suite = test_loader.discover('tests', pattern='test_*.py') return test_suite setup( name='physpy', version='0.1.1', description= 'A SymPy-based library for calculating the error percentage for measured values', url='https://kolesnichenkods.github.io/PhysPy/', author='Daniil Kolesnichenko', author_email='*****@*****.**', license='MIT', packages=['physpy'], install_requires=[ 'pdoc', 'sympy', ], test_suite='setup.physpy_test_suite', ) import os, pdoc if not os.path.exists('docs'): os.makedirs('docs') with open('docs/index.html', 'w') as f: f.write(pdoc.html('physpy', source=False))