Skip to content

Commit

Permalink
adding support for documentation spell checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Jul 10, 2017
1 parent a63595b commit b3d2163
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
30 changes: 24 additions & 6 deletions karr_lab_build_utils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ def make_and_archive_reports(self):
buildHelper = BuildHelper()
buildHelper.make_and_archive_reports()

@expose(help='Make HTML coverage report')
def make_documentation(self):
""" Make HTML documentation """
buildHelper = BuildHelper()
buildHelper.make_documentation()

@expose(help='Upload coverage report to Coveralls')
def upload_coverage_report_to_coveralls(self):
""" Upload coverage report to Coveralls """
Expand Down Expand Up @@ -122,6 +116,29 @@ def default(self):
buildHelper.run_tests(test_path=args.test_path, with_xunit=args.with_xunit, with_coverage=args.with_coverage)


class MakeDocumentationController(CementBaseController):
""" Controller for make_documentation.
Make HTML documentation. Optionally, spell check documentation.
"""

class Meta:
label = 'make-documentation'
description = 'Make HTML documentation. Optionally, spell check documentation.'
stacked_on = 'base'
stacked_type = 'nested'
arguments = [
(['--spell-check'], dict(
default=False, dest='spell_check', action='store_true', help='If set, spell check documentation')),
]

@expose(hide=True)
def default(self):
args = self.app.pargs
buildHelper = BuildHelper()
buildHelper.make_documentation(spell_check=args.spell_check)


class App(CementApp):
""" Command line application """
class Meta:
Expand All @@ -130,6 +147,7 @@ class Meta:
handlers = [
BaseController,
RunTestsController,
MakeDocumentationController,
]


Expand Down
23 changes: 22 additions & 1 deletion karr_lab_build_utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class BuildHelper(object):
proj_docs_dir (:obj:`str`): local directory with Sphinx configuration
proj_docs_static_dir (:obj:`str`): local directory of static documentation files
proj_docs_source_dir (:obj:`str`): local directory of source documentation files created by sphinx-apidoc
proj_docs_build_doctrees_dir (:obj:`str`): local directory where doc trees should be saved
proj_docs_build_html_dir (:obj:`str`): local directory where generated HTML documentation should be saved
proj_docs_build_spelling_dir (:obj:`str`): local directory where spell check results should be saved
test_server_token (:obj:`str`): test history report server token
coveralls_token (:obj:`str`): Coveralls token
Expand All @@ -66,6 +68,7 @@ class BuildHelper(object):
DEFAULT_PROJ_DOCS_DIR (:obj:`str`): default local directory with Sphinx configuration
DEFAULT_PROJ_DOCS_STATIC_DIR (:obj:`str`): default local directory of static documentation files
DEFAULT_PROJ_DOCS_SOURCE_DIR (:obj:`str`): default local directory of source documentation files created by sphinx-apidoc
DEFAULT_PROJ_DOCS_SPELLING_DIR (:obj:`str`): default local directory where spell check results should be saved
DEFAULT_PROJ_DOCS_BUILD_HTML_DIR (:obj:`str`): default local directory where generated HTML documentation should be saved
GITHUB_API_ENDPOINT (:obj:`str`): GitHub API endpoint
Expand All @@ -82,7 +85,9 @@ class BuildHelper(object):
DEFAULT_PROJ_DOCS_DIR = 'docs'
DEFAULT_PROJ_DOCS_STATIC_DIR = 'docs/_static'
DEFAULT_PROJ_DOCS_SOURCE_DIR = 'docs/source'
DEFAULT_PROJ_DOCS_BUILD_DOCTREES_DIR = 'docs/_build/doctrees'
DEFAULT_PROJ_DOCS_BUILD_HTML_DIR = 'docs/_build/html'
DEFAULT_PROJ_DOCS_BUILD_SPELLING_DIR = 'docs/_build/spelling'

GITHUB_API_ENDPOINT = 'https://api.github.com'
CIRCLE_API_ENDPOINT = 'https://circleci.com/api/v1.1'
Expand Down Expand Up @@ -114,7 +119,9 @@ def __init__(self):
self.proj_docs_dir = self.DEFAULT_PROJ_DOCS_DIR
self.proj_docs_static_dir = self.DEFAULT_PROJ_DOCS_STATIC_DIR
self.proj_docs_source_dir = self.DEFAULT_PROJ_DOCS_SOURCE_DIR
self.proj_docs_build_doctrees_dir = self.DEFAULT_PROJ_DOCS_BUILD_DOCTREES_DIR
self.proj_docs_build_html_dir = self.DEFAULT_PROJ_DOCS_BUILD_HTML_DIR
self.proj_docs_build_spelling_dir = self.DEFAULT_PROJ_DOCS_BUILD_SPELLING_DIR

self.test_server_token = os.getenv('TEST_SERVER_TOKEN')
self.coveralls_token = os.getenv('COVERALLS_REPO_TOKEN')
Expand Down Expand Up @@ -441,9 +448,12 @@ def generate_documentation_configuration(self):
template = Template(file.read())
template.stream().dump(os.path.join(self.proj_docs_dir, 'about.rst'))

def make_documentation(self):
def make_documentation(self, spell_check=False):
""" Make HTML documentation using Sphinx for one or more packages. Save documentation to `proj_docs_build_html_dir`
Args:
spell_check (:obj:`bool`): if :obj:`True`, run spell checking
Raises:
:obj:`BuildHelperError`: If project name not set
"""
Expand All @@ -457,6 +467,17 @@ def make_documentation(self):
if result != 0:
sys.exit(result)

# run spell check
if spell_check:
result = sphinx_build(['sphinx-build',
'-b', 'spelling',
'-d', self.proj_docs_build_doctrees_dir,
self.proj_docs_dir,
self.proj_docs_build_spelling_dir,
])
if result != 0:
sys.exit(result)

def get_version(self):
return '{0:s} (Python {1[0]:d}.{1[1]:d}.{1[2]:d})'.format(karr_lab_build_utils.__version__, sys.version_info)

Expand Down

0 comments on commit b3d2163

Please sign in to comment.