def test_http(self): host, port = 'localhost', randint(9000, 12000) args = '--http :{} pdoc {}'.format( port, os.path.join(TESTS_BASEDIR, EXAMPLE_MODULE)).split() with self._timeout(10): with redirect_streams() as (stdout, stderr): t = threading.Thread(target=main, args=(parser.parse_args(args),)) t.start() sleep(.1) if not t.is_alive(): sys.stderr.write(stderr.getvalue()) raise AssertionError try: url = 'http://{}:{}/'.format(host, port) with self.subTest(url='/'): with urlopen(url, timeout=3) as resp: html = resp.read() self.assertIn(b'Python package <code>pdoc</code>', html) self.assertNotIn(b'gzip', html) with self.subTest(url='/' + EXAMPLE_MODULE): with urlopen(url + 'pdoc', timeout=3) as resp: html = resp.read() self.assertIn(b'__pdoc__', html) with self.subTest(url='/csv.ext'): with urlopen(url + 'csv.ext', timeout=3) as resp: html = resp.read() self.assertIn(b'DictReader', html) finally: pdoc.cli._httpd.shutdown() t.join()
def _http(self, modules: list): port = randint(9000, 12000) with self._timeout(1000): with redirect_streams() as (stdout, stderr): t = threading.Thread( target=main, args=(parser.parse_args(['--http', ':%d' % port] + modules), )) t.start() sleep(.1) if not t.is_alive(): sys.__stderr__.write(stderr.getvalue()) raise AssertionError try: yield 'http://localhost:{}/'.format(port) except Exception: sys.__stderr__.write(stderr.getvalue()) sys.__stdout__.write(stdout.getvalue()) raise finally: pdoc.cli._httpd.shutdown() # type: ignore t.join()
def run(*args, _check=True, **kwargs) -> int: params = (('--' + key.replace('_', '-'), value) for key, value in kwargs.items()) params = list(filter(None, chain.from_iterable(params))) # type: ignore _args = parser.parse_args([*params, *args]) # type: ignore try: returncode = main(_args) return returncode or 0 except SystemExit as e: return e.code
def _docs(): rmtree(API_PATH, ignore_errors=True) args = pdoc_parser.parse_args([ PACKAGE, '--output-dir', str(DOCS_PATH), '--html', ]) pdoc(args) run([ 'git', 'add', 'docs', ]) return 0
keywords="prometeia template project pipeline jenkins", ) if __name__ == '__main__': setup(METADATA) # Don't mess with STDOUT, il would parsed by jenkins to discover package name! old_stdout = sys.stdout sys.stdout = mystdout = six.StringIO() doc_final_path = os.path.join("dist", "doc", METADATA["name"], METADATA["version"]) try: from pdoc.cli import main, parser print("INFO: Generating doc in {}".format(doc_final_path)) params = "-o {} --html --template-dir template_dir {} --force".format( os.path.join("dist", "doc", METADATA["name"]), METADATA["name"]).split() main(parser.parse_args(params)) if os.path.isdir(doc_final_path): shutil.rmtree(doc_final_path) os.rename( os.path.join("dist", "doc", METADATA["name"], METADATA["name"]), doc_final_path) print("INFO: Doc entrypoint is {}".format( os.path.join(doc_final_path, "index.html"))) except ImportError: print("WARNING: Cannot import pdoc3, skipping doc generation") finally: sys.stdout = old_stdout print(mystdout.getvalue(), file=sys.stderr)
def dynamic_docstrings(module): for pkg in list(sub_packages(module)): if hasattr(pkg, '__all__'): for attr, obj in pkg.__dict__.items(): if attr in pkg.__all__: if hasattr(obj, '__specifications__'): if obj.__doc__ is None: obj.__doc__ = '' if 'Implementation of' not in obj.__doc__: implementation_string ='Implementation of ' \ + ', '.join(['`{}`'.format(x.__module__ + '.' + x.__qualname__) for x in obj.__specifications__]) specification_string = '\n<br>\n' + '<br>\n'.join([s.__doc__ for s in obj.__specifications__ if s.__doc__]) obj.__doc__ = implementation_string + specification_string + '<br>\n' + obj.__doc__ l = link(obj, pkg, attr) d = doc_str(obj) if pkg.__doc__ is None: pkg.__doc__ = '' pkg.__doc__ += '\n<br>\n{}\n{}\n<br>'.format(l, d) pkg.__pdoc__ = {x: False for x in pkg.__all__} pkg.__qualname__ = pkg.__name__.split('.')[-1] from pdoc.cli import main as pdoc, parser as pdoc_parser if __name__ == '__main__': print(os.getcwd()) dynamic_docstrings(structpy) pdoc(pdoc_parser.parse_args('--html --force --template-dir docs/pdoc_templates --output-dir docs structpy'.split())) os.system('google-chrome docs/structpy/index.html')