diff options
author | 2015-12-16 03:25:14 -0500 | |
---|---|---|
committer | 2015-12-17 23:12:54 -0500 | |
commit | 953facea55596261958fcedcb8b93853c6d4c37e (patch) | |
tree | c1fab978ad92e390f385f7670246c908170c024e /doc | |
parent | update pkgdist (diff) | |
download | pkgcore-953facea55596261958fcedcb8b93853c6d4c37e.tar.gz pkgcore-953facea55596261958fcedcb8b93853c6d4c37e.tar.bz2 pkgcore-953facea55596261958fcedcb8b93853c6d4c37e.zip |
doc: move generate_docs script to snakeoil
So other projects can use it.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/Makefile | 4 | ||||
-rw-r--r-- | doc/conf.py | 34 | ||||
-rwxr-xr-x | doc/generate_docs.py | 74 |
3 files changed, 19 insertions, 93 deletions
diff --git a/doc/Makefile b/doc/Makefile index 0ed0b45e8..c2f89719a 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -45,7 +45,7 @@ clean: -rm -rf $(BUILDDIR) api generated *.pyc html: - $(CURDIR)/generate_docs.py --html + $(PYTHON) -m snakeoil.dist.generate_docs --html ../ pkgcore $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." @@ -118,7 +118,7 @@ text: @echo "Build finished. The text files are in $(BUILDDIR)/text." man: - $(CURDIR)/generate_docs.py --man + $(PYTHON) -m snakeoil.dist.generate_docs --man ../ pkgcore $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @for file in man/*; do \ [ -L "$${file}" ] && rm -f "$${file}" || continue; \ diff --git a/doc/conf.py b/doc/conf.py index 9aa41578a..bcda8fc92 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -18,28 +18,16 @@ import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -lib_dir = os.path.abspath(os.path.join('..', 'build', 'lib')) -if os.path.exists(lib_dir): - sys.path.insert(0, lib_dir) -sys.path.insert(1, os.path.abspath('.')) -sys.path.insert(2, os.path.abspath('..')) +libdir = os.path.abspath(os.path.join('..', 'build', 'lib')) +if os.path.exists(libdir): + sys.path.insert(0, libdir) +sys.path.insert(1, os.path.abspath('..')) from pkgcore import __version__ -from generate_docs import generate_man, generate_html +from snakeoil.dist.generate_docs import generate_man, generate_html on_rtd = os.environ.get('READTHEDOCS', None) == 'True' -# auto-generate required files for RTD build environment -if on_rtd: - generate_man() - generate_html() - -# handle auto-generation for setup.py -if 'build_man' in sys.argv[1:]: - generate_man() -if 'build_docs' in sys.argv[1:]: - generate_man() - generate_html() # -- General configuration ----------------------------------------------------- @@ -116,6 +104,18 @@ pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] +# auto-generate required files for RTD build environment +project_dir = os.path.abspath('..') +if on_rtd: + generate_man(project, project_dir) + generate_html(project) + +# handle auto-generation for setup.py +if 'build_man' in sys.argv[1:]: + generate_man(project, project_dir) +if 'build_docs' in sys.argv[1:]: + generate_man(project, project_dir) + generate_html(project) # -- Options for HTML output --------------------------------------------------- diff --git a/doc/generate_docs.py b/doc/generate_docs.py deleted file mode 100755 index 386e36d80..000000000 --- a/doc/generate_docs.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python - -import argparse -import errno -import os -import subprocess -import sys -import textwrap - -from snakeoil.dist.generate_man_rsts import ManConverter - - -def generate_man(): - print('Generating files for man pages') - - try: - os.mkdir('generated') - except OSError as e: - if e.errno == errno.EEXIST: - return - raise - - bin_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'bin') - scripts = os.listdir(bin_path) - - # Note that filter-env is specially specified, since the command is installed - # as 'filter-env', but due to python namespace contraints, it uses a '_' - # instead. - generated_man_pages = [ - ('pkgcore.scripts.' + s.replace('-', '_'), s) for s in scripts - ] - - for module, script in generated_man_pages: - rst = script + '.rst' - # generate missing, generic man pages - if not os.path.isfile(os.path.join('man', rst)): - with open(os.path.join('generated', rst), 'w') as f: - f.write(textwrap.dedent("""\ - {header} - {script} - {header} - - .. include:: {script}/main_synopsis.rst - .. include:: {script}/main_description.rst - .. include:: {script}/main_options.rst - """.format(header=('=' * len(script)), script=script))) - os.symlink(os.path.join(os.pardir, 'generated', rst), os.path.join('man', rst)) - os.symlink(os.path.join(os.pardir, 'generated', script), os.path.join('man', script)) - ManConverter.regen_if_needed('generated', module, out_name=script) - - -def generate_html(): - print('Generating API docs') - subprocess.call(['sphinx-apidoc', '-Tef', '-o', 'api', '../pkgcore', '../pkgcore/test']) - - -if __name__ == '__main__': - sys.path.insert(1, os.path.abspath('..')) - - argparser = argparse.ArgumentParser(description='generate docs') - argparser.add_argument('--man', action='store_true', help='generate man files') - argparser.add_argument('--html', action='store_true', help='generate API files') - - opts = argparser.parse_args() - - # if run with no args, build all docs - if not opts.man and not opts.html: - opts.man = opts.html = True - - if opts.man: - generate_man() - - if opts.html: - generate_html() |