Created
June 3, 2019 16:15
-
-
Save ArjitJ/299fd9ca94d2ee0335ad329769473827 to your computer and use it in GitHub Desktop.
Create a sphinx documentation for your python project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import argparse | |
| from sphinx.cmd.quickstart import generate | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('--project', help='Project name') | |
| parser.add_argument('--path', help='Root path for documentation.', default='.') | |
| parser.add_argument('--sep', help='Separate source and build directories (y/n)', default='n') | |
| parser.add_argument('--dot', help='Name prefix for templates and static dir', default='_') | |
| parser.add_argument('--author', help='Author name(s)', default='author') | |
| parser.add_argument('--version', help='Project version', default='1.0') | |
| parser.add_argument('--release', help='Project release', default='1.0.0') | |
| parser.add_argument('--language', help='Project Language', default=None) | |
| parser.add_argument('--suffix', help='Source file suffix.', default='.rst') | |
| parser.add_argument('--master', help='Name of your master document (without suffix)', default='index') | |
| parser.add_argument('--makefile', help='Create Makefile? (y/n)', default='y') | |
| parser.add_argument('--batchfile', help='Create Windows command file? (y/n)', default='y') | |
| parser.add_argument('--autodoc', help='automatically insert docstrings from modules (y/n)', default='y') | |
| parser.add_argument('--doctest', help='automatically test code snippets in doctest blocks (y/n)', default='n') | |
| parser.add_argument('--intersphinx', help='link between Sphinx documentation of different projects (y/n)', default='y') | |
| parser.add_argument('--todo', help='write "todo" entries that can be shown or hidden on build (y/n)', default='y') | |
| parser.add_argument('--coverage', help='checks for documentation coverage (y/n)', default='y') | |
| parser.add_argument('--imgmath', help='include math, rendered as PNG or SVG images (y/n)', default='n') | |
| parser.add_argument('--mathjax', help='include math, rendered in the browser by MathJax (y/n)', default='y') | |
| parser.add_argument('--ifconfig', help='conditional inclusion of content based on config values (y/n)', default='n') | |
| parser.add_argument('--viewcode', help='include links to the source code of documented Python objects (y/n)', default='y') | |
| parser.add_argument('--githubpages', help='create .nojekyll file to publish the document on GitHub pages (y/n)', default='y') | |
| args = parser.parse_args() | |
| configs = {} | |
| configs['batchfile'] = args.batchfile.upper() in ('Y', 'YES') | |
| configs['makefile'] = args.makefile.upper() in ('Y', 'YES') | |
| configs['master'] = args.master | |
| configs['suffix'] = args.suffix | |
| configs['language'] = args.language | |
| configs['version'] = args.version | |
| configs['release'] = args.release | |
| configs['dot'] = args.dot | |
| configs['sep'] = args.sep.upper() in ('Y', 'YES') | |
| configs['path'] = args.path | |
| configs['project'] = args.project | |
| configs['author'] = args.author | |
| configs['extensions'] = [] | |
| if args.autodoc.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.autodoc') | |
| if args.doctest.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.doctest') | |
| if args.intersphinx.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.intersphinx') | |
| if args.todo.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.todo') | |
| if args.coverage.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.coverage') | |
| if args.imgmath.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.imgmath') | |
| if args.mathjax.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.mathjax') | |
| if args.ifconfig.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.ifconfig') | |
| if args.viewcode.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.viewcode') | |
| if args.githubpages.upper() in ('Y', 'YES'): | |
| configs['extensions'].append('sphinx.ext.githubpages') | |
| # print(configs) | |
| generate(configs) | |
| import subprocess | |
| subprocess.call(["sed","-i","13,15 s/^# *//", "conf.py"]) | |
| subprocess.call(["sphinx-apidoc", "-f", "-o", "./", "./"+args.project]) | |
| subprocess.call(["make", "html"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment