def apidoc(rootdir, tempdir, apidoc_params): _, kwargs = apidoc_params coderoot = rootdir / kwargs.get('coderoot', 'test-root') outdir = tempdir / 'out' args = ['-o', outdir, '-F', coderoot] + kwargs.get('options', []) apidoc_main(args) return namedtuple('apidoc', 'coderoot,outdir')(coderoot, outdir)
def test_package_file_module_first(tempdir): outdir = path(tempdir) (outdir / 'testpkg').makedirs() (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8') (outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8') apidoc_main(['--module-first', '-o', tempdir, tempdir]) content = (outdir / 'testpkg.rst').read_text(encoding='utf8') assert content == ("testpkg package\n" "===============\n" "\n" ".. automodule:: testpkg\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n" "\n" "Submodules\n" "----------\n" "\n" "testpkg.example module\n" "----------------------\n" "\n" ".. automodule:: testpkg.example\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
def setup(app): # Add custom CSS app.add_stylesheet('custom.css') # Make the version number available to ifconfig app.add_config_value('ag_version', ag_version, 'env') # Do not generate apidocs for these: exclude = ['franz/miniclient', 'franz/openrdf/tests', # These are re-exported in franz.openrdf.model 'franz/openrdf/model/literal.py', 'franz/openrdf/model/statement.py', 'franz/openrdf/model/value.py', 'franz/openrdf/model/valuefactory.py', # More reexported stuff 'franz/openrdf/vocabulary/owl.py', 'franz/openrdf/vocabulary/rdf.py', 'franz/openrdf/vocabulary/rdfs.py', 'franz/openrdf/vocabulary/xmlschema.py',] abs_exclude = [os.path.abspath(os.path.join('../src', path)) for path in exclude] # Generate apidocs # Options: # -f = overwrite old files # -o ... = output directory # ../src = path to the sources # rest = exclusion patterns apidoc_main(['-f', '-o', os.path.abspath('src/_gen'), os.path.abspath('../src')] + abs_exclude)
def run_apidoc(_): """Call sphinx-apidoc on Bio and BioSQL modules.""" from sphinx.ext.apidoc import main as apidoc_main cur_dir = os.path.abspath(os.path.dirname(__file__)) # Can't see a better way than running apidoc twice, for Bio & BioSQL # We don't care about the index.rst / conf.py (we have our own) # or the Makefile / make.bat (effectively same) clashing, # $ sphinx-apidoc -e -F -o /tmp/api/BioSQL BioSQL # $ sphinx-apidoc -e -F -o /tmp/api/Bio Bio tmp_path = tempfile.mkdtemp() apidoc_main(["-e", "-F", "-o", tmp_path, "../../BioSQL"]) apidoc_main([ "-e", "-F", "-o", tmp_path, # The input path: "../../Bio", # These are patterns to exclude: "../../Bio/Alphabet/", "../../Bio/Restriction/Restriction.py", ]) os.remove(os.path.join(tmp_path, "index.rst")) # Using our own for filename in os.listdir(tmp_path): if filename.endswith(".rst"): shutil.move(os.path.join(tmp_path, filename), os.path.join(cur_dir, filename)) shutil.rmtree(tmp_path) for f in os.listdir(cur_dir): if f.startswith("Bio") and f.endswith(".rst"): insert_github_link(f)
def test_no_duplicates(rootdir, tempdir): """Make sure that a ".pyx" and ".so" don't cause duplicate listings. We can't use pytest.mark.apidoc here as we use a different set of arguments to apidoc_main """ original_suffixes = sphinx.ext.apidoc.PY_SUFFIXES try: # Ensure test works on Windows sphinx.ext.apidoc.PY_SUFFIXES += ('.so', ) package = rootdir / 'test-apidoc-duplicates' / 'fish_licence' outdir = tempdir / 'out' apidoc_main(['-o', outdir, "-T", package, "--implicit-namespaces"]) # Ensure the module has been documented assert (outdir / 'fish_licence.rst').isfile() # Ensure the submodule only appears once text = (outdir / 'fish_licence.rst').read_text(encoding="utf-8") count_submodules = text.count(r'fish\_licence.halibut module') assert count_submodules == 1 finally: sphinx.ext.apidoc.PY_SUFFIXES = original_suffixes
def run_apidoc(_): from sphinx.ext.apidoc import main as apidoc_main cur_dir = os.path.normpath(os.path.dirname(__file__)) output_path = os.path.join(cur_dir, 'api') modules = os.path.normpath(os.path.join(cur_dir, "../clmm")) paramlist = ['--separate', '--no-toc', '-f', '-M', '-o', output_path, modules] apidoc_main(paramlist)
def run_apidoc(_): """Call sphinx-apidoc """ from sphinx.ext.apidoc import main as apidoc_main curdir = os.path.abspath(os.path.dirname(__file__)) apidir = os.path.join(curdir, 'api') module = os.path.join(curdir, os.path.pardir, 'gwdetchar') apidoc_main([module, '--separate', '--force', '--output-dir', apidir])
def run_apidoc(_): from sphinx.ext.apidoc import main as apidoc_main import os import sys out_dir = os.path.dirname(__file__) src_dir = os.path.join(out_dir, '../../src') sys.path.append(src_dir) apidoc_main(['-f', '-e', '--no-toc', '-o', out_dir, src_dir])
def apidoc(rootdir, tempdir, apidoc_params): _, kwargs = apidoc_params coderoot = rootdir / kwargs.get('coderoot', 'test-root') outdir = tempdir / 'out' excludes = [coderoot / e for e in kwargs.get('excludes', [])] args = ['-o', outdir, '-F', coderoot] + excludes + kwargs.get('options', []) apidoc_main(args) return namedtuple('apidoc', 'coderoot,outdir')(coderoot, outdir)
def run_apidoc(_): from sphinx.ext.apidoc import main as apidoc_main cur_dir = os.path.abspath(os.path.dirname(__file__)) included_module = "../../subaligner" excluded_module = "../../subaligner/models" apidoc_main([ "-e", "-o", cur_dir, included_module, excluded_module, "--force" ])
def test_module_file_noheadings(tempdir): outdir = path(tempdir) (outdir / 'example.py').write_text('', encoding='utf8') apidoc_main(['--no-headings', '-o', tempdir, tempdir]) assert (outdir / 'example.rst').exists() content = (outdir / 'example.rst').read_text(encoding='utf8') assert content == (".. automodule:: example\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
def test_package_file(tempdir): outdir = path(tempdir) (outdir / 'testpkg').makedirs() (outdir / 'testpkg' / '__init__.py').write_text('') (outdir / 'testpkg' / 'example.py').write_text('') (outdir / 'testpkg' / 'subpkg').makedirs() (outdir / 'testpkg' / 'subpkg' / '__init__.py').write_text('') apidoc_main(['-o', tempdir, tempdir / 'testpkg']) assert (outdir / 'testpkg.rst').exists() assert (outdir / 'testpkg.subpkg.rst').exists() content = (outdir / 'testpkg.rst').text() assert content == ("testpkg package\n" "===============\n" "\n" "Subpackages\n" "-----------\n" "\n" ".. toctree::\n" "\n" " testpkg.subpkg\n" "\n" "Submodules\n" "----------\n" "\n" "testpkg.example module\n" "----------------------\n" "\n" ".. automodule:: testpkg.example\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n" "\n" "\n" "Module contents\n" "---------------\n" "\n" ".. automodule:: testpkg\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n") content = (outdir / 'testpkg.subpkg.rst').text() assert content == ("testpkg.subpkg package\n" "======================\n" "\n" "Module contents\n" "---------------\n" "\n" ".. automodule:: testpkg.subpkg\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
def test_private(tempdir): (tempdir / 'hello.py').write_text('') (tempdir / '_world.py').write_text('') # without --private option apidoc_main(['-o', tempdir, tempdir]) assert (tempdir / 'hello.rst').exists() assert not (tempdir / '_world.rst').exists() # with --private option apidoc_main(['--private', '-o', tempdir, tempdir]) assert (tempdir / 'hello.rst').exists() assert (tempdir / '_world.rst').exists()
def build_api_docs(input_path: str, output_path: str, ignore="*_tests.py"): """ Autogenerate the Python API documentation for the module found at input_path. :raises AssertionError: If input directory does not exist. :param input_path: Folder to read module contents from. :param output_path: Folder to output .rst files to. :param ignore: Ignore files pattern. """ skeletonization.skeleton.io_tools.assert_directory_exists(input_path) skeletonization.skeleton.io_tools.force_directory(output_path) apidoc_main(["-f", "-o", output_path, input_path, ignore])
def test_module_file(tempdir): outdir = path(tempdir) (outdir / 'example.py').write_text('') apidoc_main(['-o', tempdir, tempdir]) assert (outdir / 'example.rst').exists() content = (outdir / 'example.rst').read_text() assert content == ("example module\n" "==============\n" "\n" ".. automodule:: example\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
def _run_test(): rmtree("doc/", ignore_errors=True) rmtree("doc_build/", ignore_errors=True) # [OPTIONS] -o <OUTPUT_PATH> <MODULE_PATH> [EXCLUDE_PATTERN, ...] # apidoc_main(["-h"]) ret = apidoc_main( ["--module-first", "--force", "--full", "--output-dir", "doc/", "."]) if ret != 0: raise AssertionError("apidoc_main failed with err %d" % ret) # -b buildername # -a If given, always write all output files. The default is to only write output files for new and changed source files. (This may not apply to all builders.) # -E Don’t use a saved environment (the structure caching all cross-references), but rebuild it completely. The default is to only read and parse source files that are new or have changed since the last run. # -C Don’t look for a configuration file; only take options via the -D option. # [OPTIONS] SOURCEDIR OUTPUTDIR [FILENAMES...] # sphinx_main(["-h"]) ret = sphinx_main([ "-b", "html", "-E", "-c", cwd, "doc/", "doc_build/", ]) if ret != 0: raise AssertionError("sphinx_main failed with err %d" % ret)
def test_toc_file(tempdir): outdir = path(tempdir) (outdir / 'module').makedirs() (outdir / 'example.py').write_text('', encoding='utf8') (outdir / 'module' / 'example.py').write_text('', encoding='utf8') apidoc_main(['-o', tempdir, tempdir]) assert (outdir / 'modules.rst').exists() content = (outdir / 'modules.rst').read_text(encoding='utf8') assert content == ("test_toc_file0\n" "==============\n" "\n" ".. toctree::\n" " :maxdepth: 4\n" "\n" " example\n")
def test_private(tempdir): (tempdir / 'hello.py').write_text('', encoding='utf8') (tempdir / '_world.py').write_text('', encoding='utf8') # without --private option apidoc_main(['-o', tempdir, tempdir]) assert (tempdir / 'hello.rst').exists() assert ':private-members:' not in (tempdir / 'hello.rst').read_text(encoding='utf8') assert not (tempdir / '_world.rst').exists() # with --private option apidoc_main(['--private', '-f', '-o', tempdir, tempdir]) assert (tempdir / 'hello.rst').exists() assert ':private-members:' in (tempdir / 'hello.rst').read_text(encoding='utf8') assert (tempdir / '_world.rst').exists()
def test_package_file_without_submodules(tempdir): outdir = path(tempdir) (outdir / 'testpkg').makedirs() (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8') apidoc_main(['-o', tempdir, tempdir / 'testpkg']) assert (outdir / 'testpkg.rst').exists() content = (outdir / 'testpkg.rst').read_text(encoding='utf8') assert content == ("testpkg package\n" "===============\n" "\n" "Module contents\n" "---------------\n" "\n" ".. automodule:: testpkg\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
def run_apidoc(_): """Call sphinx-apidoc on Bio and BioSQL modules.""" from sphinx.ext.apidoc import main as apidoc_main cur_dir = os.path.abspath(os.path.dirname(__file__)) # Can't see a better way than running apidoc twice, for Bio & BioSQL # We don't care about the index.rst / conf.py (we have our own) # or the Makefile / make.bat (effectively same) clashing, # $ sphinx-apidoc -e -F -o /tmp/api/BioSQL BioSQL # $ sphinx-apidoc -e -F -o /tmp/api/Bio Bio tmp_path = tempfile.mkdtemp() apidoc_main(['-e', '-F', '-o', tmp_path, '../../BioSQL']) apidoc_main(['-e', '-F', '-o', tmp_path, '../../Bio']) os.remove(os.path.join(tmp_path, 'index.rst')) # Using our own for filename in os.listdir(tmp_path): if filename.endswith(".rst"): shutil.move(os.path.join(tmp_path, filename), os.path.join(cur_dir, filename)) shutil.rmtree(tmp_path)
def test_namespace_package_file(tempdir): outdir = path(tempdir) (outdir / 'testpkg').makedirs() (outdir / 'testpkg' / 'example.py').write_text('') apidoc_main(['--implicit-namespace', '-o', tempdir, tempdir / 'testpkg']) assert (outdir / 'testpkg.rst').exists() content = (outdir / 'testpkg.rst').read_text() assert content == ("testpkg namespace\n" "=================\n" "\n" "Submodules\n" "----------\n" "\n" "testpkg.example module\n" "----------------------\n" "\n" ".. automodule:: testpkg.example\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
def test_package_file_separate(tempdir): outdir = path(tempdir) (outdir / 'testpkg').makedirs() (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8') (outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8') apidoc_main(['--separate', '-o', tempdir, tempdir / 'testpkg']) assert (outdir / 'testpkg.rst').exists() assert (outdir / 'testpkg.example.rst').exists() content = (outdir / 'testpkg.rst').read_text(encoding='utf8') assert content == ("testpkg package\n" "===============\n" "\n" "Submodules\n" "----------\n" "\n" ".. toctree::\n" " :maxdepth: 4\n" "\n" " testpkg.example\n" "\n" "Module contents\n" "---------------\n" "\n" ".. automodule:: testpkg\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n") content = (outdir / 'testpkg.example.rst').read_text(encoding='utf8') assert content == ("testpkg.example module\n" "======================\n" "\n" ".. automodule:: testpkg.example\n" " :members:\n" " :undoc-members:\n" " :show-inheritance:\n")
# If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # on_rtd is whether we are on readthedocs.org on_rtd = os.environ.get('READTHEDOCS', None) == 'True' html_theme = 'alabaster' apidoc_options[:] = ['members', 'no-undoc-members', 'show-inheritance'] apidoc_main('-M -f -e -d 2 -o api ../PyOpenWorm'.split(' ')) # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. html_theme_options = {'show_related': True} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None
def generate_docs(root_folder="", docs_src_path_rel_to_root="", docs_dest_path_rel_to_root="docs", apidoc_paths_rel_to_root=[], doctree_temp_location_rel_to_sys_temp="", ignored_modules=[], generate_api_docs=False, update_inventories=False, force_clean_build=False, build_coverage=True, logger=None): """Build this application documentation. Parameters ---------- root_folder : str, optional Path to the main folder that most paths should be relative to. docs_src_path_rel_to_root : str, optional Docs sources path relative to root_folder. docs_dest_path_rel_to_root : str, optional Built docs destination path relative to root_folder. apidoc_paths_rel_to_root : list, optional A list of tuples. Each tuple of length two contains the path to the Python modules folder at index zero from which to extract docstrings and the path to where to store the generated rst files at index one. doctree_temp_location_rel_to_sys_temp : str, optional Name of a temporary folder that will be used to create a path relative to the system temporary folder. ignored_modules : list, optional A list of paths to Python modules relative to the root_folder. These are ignored modules whose docstrings are a mess and/or are incomplete. Because such docstrings will produce hundred of annoying Sphinx warnings. generate_api_docs : bool If False, do not extract docstrings from Python modules. update_inventories : bool, optional Whether to force the update of the inventory files. Inventory files will be updated anyway f they don't exist. force_clean_build : bool, optional Remove destination and doctrees directories before building the documentation. build_coverage : bool, optional If True, build Sphinx coverage documents. logger : LogSystem The logger. """ doctree_temp_location = os.path.join(get_system_tempdir(), doctree_temp_location_rel_to_sys_temp) docs_sources_path = os.path.join(root_folder, docs_src_path_rel_to_root) docs_destination_path = os.path.join(root_folder, docs_dest_path_rel_to_root) check_inventories_existence(update_inventories, docs_sources_path, logger) if force_clean_build: rmtree(doctree_temp_location, ignore_errors=True) rmtree(docs_destination_path, ignore_errors=True) if generate_api_docs: logger.info(shell_utils.get_cli_separator("-"), date=False) logger.info("**Generating automodule directives...**") # NOTE: Countermeasure for retarded new Sphinx behavior. # https://github.com/sphinx-doc/sphinx/issues/8664 # In short, I have to force down os.environ's throat the SPHINX_APIDOC_OPTIONS environment # variable because the options it contains aren't exposed to be passed as arguments. # By default, SPHINX_APIDOC_OPTIONS will contain the undoc-members option, overriding its # value without the undoc-members option will prevent apidoc from belching a trillion # warnings unnecessarily. os.environ["SPHINX_APIDOC_OPTIONS"] = "members,show-inheritance" from sphinx.ext.apidoc import main as apidoc_main commmon_args = ["--module-first", "--separate", "--private", "--force", "--suffix", "rst", "--output-dir"] for rel_source_path, rel_destination_path in apidoc_paths_rel_to_root: apidoc_destination_path = os.path.join(root_folder, rel_destination_path) if force_clean_build: rmtree(apidoc_destination_path, ignore_errors=True) apidoc_main(argv=commmon_args + [ apidoc_destination_path, os.path.join(root_folder, rel_source_path) ] + ignored_modules) try: if build_coverage: logger.info(shell_utils.get_cli_separator("-"), date=False) logger.info("**Building coverage data...**") sphinx_main(argv=[docs_sources_path, "-b", "coverage", "-d", doctree_temp_location, docs_sources_path + "/coverage"]) finally: logger.info(shell_utils.get_cli_separator("-"), date=False) logger.info("**Generating HTML documentation...**") sphinx_main(argv=[docs_sources_path, "-b", "html", "-d", doctree_temp_location, docs_destination_path])
def run_apidoc(_): """Call sphinx-apidoc on faucet module""" from sphinx.ext.apidoc import main as apidoc_main apidoc_main(['-e', '-o', 'source/apidoc', '../faucet'])
proportional=True, ) notskipregex = re.compile("_[^_]+") def skip(app, what, name, obj, skip, options): # do not skip hiden methods if name == "__init__" or notskipregex.match(name): return False return None def setup(app): app.connect("autodoc-skip-member", skip) # update *.rst pages for file in glob.glob("*.rst"): if file != "index.rst": print("removing: ", file) os.remove(file) excluded_tests = list(find_files("../", "*_test.py")) + [ "../hwtLib/tests", "../hwtLib/examples/showcase0.hwt.py" ] apidoc_main([ "--module-first", "--full", "--maxdepth", "-1", "--output-dir", "../docs", "../hwtLib" ] + excluded_tests)
def run_apidoc(_): from sphinx.ext.apidoc import main as apidoc_main cur_dir = os.path.abspath(".") output_path = os.path.join(cur_dir, "source") apidoc_main(["-e", "-f", "-o", output_path, modules_path, "--force"])
templates_path = ['_templates'] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. exclude_patterns = [] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'bootstrap' html_theme_path = sphinx_bootstrap_theme.get_html_theme_path() # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # update generated *.rst pages for file in glob.glob("*.rst"): if file != "index.rst": print("removing: ", file) os.remove(file) apidoc_main([ "--module-first", "--full", "--maxdepth", "-1", "--output-dir", "../doc", "../hwtSimApi" ])
templates_path = ['_templates'] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. exclude_patterns = [] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'bootstrap' html_theme_path = sphinx_bootstrap_theme.get_html_theme_path() # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # update generated *.rst pages for file in glob.glob("*.rst"): if file != "index.rst": print("removing: ", file) os.remove(file) apidoc_main([ "--module-first", "--full", "--maxdepth", "-1", "--output-dir", "../doc", "../sphinx_hwt" ])
epub_copyright = copyright # The unique identifier of the text. This can be a ISBN number # or the project homepage. # # epub_identifier = '' # A unique identification for the text. # # epub_uid = '' # A list of files that should not be packed into the epub file. epub_exclude_files = ['search.html'] notskipregex = re.compile("_[^_]+") def skip(app, what, name, obj, skip, options): if name == "__init__" or notskipregex.match(name): return False return skip def setup(app): app.connect("autodoc-skip-member", skip) # update *.rst pages apidoc_main(["--module-first", "--full", "--output-dir", "../docs", "../hdlConvertorAst"])
def run_apidoc(_): """Call sphinx-apidoc on Bio and BioSQL modules.""" from sphinx.ext.apidoc import main as apidoc_main apidoc_main(["-e", "-F", "-o", "api/", "../pyani"])
# List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. exclude_patterns = [] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = 'bootstrap' html_theme_path = sphinx_bootstrap_theme.get_html_theme_path() # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # update generated *.rst pages for file in glob.glob("*.rst"): if file != "index.rst": print("removing: ", file) os.remove(file) excluded_tests = ["../ipCorePackager/tests"] apidoc_main(["--module-first", "--full", "--maxdepth", "-1", "--output-dir", "../doc", "../ipCorePackager"] + excluded_tests)
aafig_default_options = dict( scale=.75, aspect=0.5, proportional=True, ) notskipregex = re.compile("_[^_]+") def skip(app, what, name, obj, skip, options): # do not skip hiden methods if name == "__init__" or notskipregex.match(name): return False return None def setup(app): app.connect("autodoc-skip-member", skip) # update *.rst pages for file in glob.glob("*.rst"): if file != "index.rst": print("removing: ", file) os.remove(file) excluded_tests = list(find_files("../", "*_test.py")) + [ "../hwtLib/tests", "../hwtLib/examples/showcase0.hwt.py"] apidoc_main(["--module-first", "--full", "--maxdepth", "-1", "--output-dir", "../docs", "../hwtLib"] + excluded_tests)