def run(self): from sphinx.apidoc import main """Run command.""" try: from sphinx.ext.apidoc import main as sphinx_apidoc sphinx_apidoc(['-f', '-o', './docs', './src/pygalle']) #self.run_command('build_sphinx') except: pass
'--update=command_index.rst' ] + glob('*rst')) # # Run sphinx-apidoc # # Remove any previous API docs # Read the Docs doesn't clean up after previous builds # Without this, the API Docs will never actually update # apidoc_args = [ '--force', # Overwrite existing files '--no-toc', # Don't create a table of contents file '--output-dir=.', # Directory to place all output ] sphinx_apidoc(apidoc_args + ['_spack_root/lib/spack/spack']) sphinx_apidoc(apidoc_args + ['_spack_root/lib/spack/llnl']) # Enable todo items todo_include_todos = True # # Disable duplicate cross-reference warnings. # from sphinx.domains.python import PythonDomain class PatchedPythonDomain(PythonDomain): def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): if 'refspecific' in node:
stdout=index) # # Run sphinx-apidoc # # Remove any previous API docs # Read the Docs doesn't clean up after previous builds # Without this, the API Docs will never actually update # apidoc_args = [ '--force', # Older versions of Sphinx ignore the first argument '--force', # Overwrite existing files '--no-toc', # Don't create a table of contents file '--output-dir=.', # Directory to place all output ] sphinx_apidoc(apidoc_args + ['../spack']) sphinx_apidoc(apidoc_args + ['../llnl']) # Enable todo items todo_include_todos = True # # Disable duplicate cross-reference warnings. # from sphinx.domains.python import PythonDomain class PatchedPythonDomain(PythonDomain): def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode): if 'refspecific' in node: del node['refspecific'] return super(PatchedPythonDomain, self).resolve_xref( env, fromdocname, builder, typ, target, node, contnode)
# The full version, including alpha/beta/rc tags version = LMODULE_VERSION release = "alpha" # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ "sphinx.ext.autodoc", ] apidoc = ["--force", "--no-toc", "-e", "--output-dir=api"] sphinx_apidoc(apidoc + ["../lmod"]) # Add any paths that contain templates here, relative to this directory. 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 = ["_build", "Thumbs.db", ".DS_Store"] # -- 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 = "sphinx_rtd_theme"
on_rtd = os.environ.get('READTHEDOCS', None) == 'True' docs_dir = os.path.dirname(os.path.realpath(__file__)) root_dir = os.path.dirname(docs_dir) src_dir = os.path.join(os.path.abspath(root_dir), 'src', slug) ext_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'ext') docs_modules_dir = os.path.join(docs_dir, 'modules') tpl_dir = os.path.join(docs_dir, 'templates') sys.path.insert(0, root_dir) sys.path.insert(0, src_dir) sys.path.insert(0, ext_dir) # -- Auto build module docs -------------------------------------------------- sphinx_apidoc(['-e', '-f', '-t', tpl_dir, '-o', docs_modules_dir, src_dir]) os.remove(os.path.join(docs_modules_dir, 'modules.rst')) # -- Set extensions ---------------------------------------------------------- extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.viewcode', 'sphinx.ext.githubpages', 'sphinxarg.ext', ] # -- Setting readthedocs theme and config -----------------------------------
def _generate_py_apidoc(self, output_dir): # In this function we are in the code documentation output directory root_pkg_name = os.path.basename(self.src_dir) # python modules apidoc sphinx_apidoc([ '--implicit-namespaces', '--separate', '--force', '-o', output_dir, self.src_dir ] + [ os.path.join(self.src_dir, os.path.normpath(p)) for p in PY_EXCLUDE ]) os.remove('modules.rst') os.rename(root_pkg_name + '.rst', 'modules.rst') for f in os.listdir(output_dir): f_path = os.path.join(output_dir, f) # 1. calculate new file path f_spl = f.split('.') d = f_spl[1:-2] # 2. search and replace root package name in file + change paths fh = open(f_path, 'r') content = fh.readlines() fh.close() for i in range(len(content)): line = re.sub('\\\\(?P<char>[_-])', '\g<char>', content[i]) if '.. toctree::' in line: # replace reference by relative path i += 2 line = content[i] while line != '\n': path = line.replace(root_pkg_name + '.', '') \ .strip().split('.') new_path = [] for j in range(len(path)): if j < len(d) and d[j] == path[j]: continue new_path.append(path[j]) content[i] = ' %s\n' % '/'.join(new_path) i += 1 line = content[i] continue if (root_pkg_name + '.') in line \ and ('.. automodule:: ' + root_pkg_name) not in line: content[i] = re.sub(root_pkg_name + r'\.', '', line) next_line = content[i + 1] if ''.join(set(next_line[:-1])) in ('=', '-'): content[i + 1] = next_line[-len(content[i]):] if f == 'modules.rst': # replace title and strip module contents for root package content[0] = 'Python\n' content[1] = content[1][0] * (len(content[0]) - 1) + '\n' content = content[:-8] fh = open(f_path, 'w') fh.write(''.join(content)) fh.close() if len(f_spl) == 2: # do not move/rename modules.rst continue # 3. move the file to its correct directory if len(d): d = os.path.join(*d) try: os.makedirs(d) except OSError: # directory exists pass else: d = '.' dest = os.path.join(d, '.'.join(f_spl[-2:])) try: os.remove(dest) except OSError: # file does not exist already pass os.rename(f, dest)
# access setup.py as text file to find the necessary lines, then execute those with open(setup_path, 'r') as f: for i, line in enumerate(f): line = line.strip() line_list = line.split() if len(line_list) > 0 and line_list[0] in desired: exec(line) desired.remove(line_list[0]) from sphinx.ext.apidoc import main as sphinx_apidoc file_path = pathlib.Path(__file__).parent sphinx_apidoc([ "-o", str(file_path.absolute() / "source"), str(file_path.parent.absolute() / "pymepix") ]) # accessing the setup.py file to get current information about the project name, project, version, release, author, copyright = [""] * 6 desired = ["copyright", "project", "name", "version", "release", "author"] # first get the path of the setup.py file current_path = pathlib.Path(__file__).parent.absolute() setup_path = current_path.parent.joinpath("setup.py") # access setup.py as text file to find the necessary lines, then execute those # importlib.util.spec_from_file_location didn't work with open(setup_path, "r") as f: for line in f: