diff --git a/src/sage_docbuild/__init__.py b/src/sage_docbuild/__init__.py index 7d968845b1b..8a5c1a19d24 100644 --- a/src/sage_docbuild/__init__.py +++ b/src/sage_docbuild/__init__.py @@ -38,7 +38,7 @@ # **************************************************************************** import logging -import optparse +import argparse import os import pickle import re @@ -49,8 +49,6 @@ import types import warnings -logger = logging.getLogger(__name__) - import sphinx.util.console import sphinx.ext.intersphinx @@ -59,10 +57,15 @@ from sage.misc.misc import sage_makedirs from sage.env import SAGE_DOC_SRC, SAGE_DOC, SAGE_SRC, DOT_SAGE -from .build_options import (LANGUAGES, SPHINXOPTS, PAPER, OMIT, - PAPEROPTS, ALLSPHINXOPTS, NUM_THREADS, WEBSITESPHINXOPTS, +from .build_options import (LANGUAGES, SPHINXOPTS, OMIT, + ALLSPHINXOPTS, NUM_THREADS, WEBSITESPHINXOPTS, INCREMENTAL_BUILD, ABORT_ON_ERROR) +from .utils import build_many as _build_many + +logger = logging.getLogger(__name__) + + ########################################## # Parallel Building Ref Manual # ########################################## @@ -77,6 +80,7 @@ def build_ref_doc(args): kwds['use_multidoc_inventory'] = False getattr(ReferenceSubBuilder(doc, lang), format)(*args, **kwds) + ########################################## # Builders # ########################################## @@ -91,7 +95,7 @@ def builder_helper(type): Check that :trac:`25161` has been resolved:: sage: from sage_docbuild import DocBuilder, setup_parser - sage: DocBuilder._options = setup_parser().parse_args([])[0] # builder_helper needs _options to be set + sage: DocBuilder._options = setup_parser().parse_args([]) # builder_helper needs _options to be set sage: import sage_docbuild.sphinxbuild sage: def raiseBaseException(): @@ -121,7 +125,7 @@ def f(self, *args, **kwds): else: options += ' -D multidoc_first_pass=1' - build_command = '-b %s -d %s %s %s %s'%(type, self._doctrees_dir(), + build_command = '-b %s -d %s %s %s %s' % (type, self._doctrees_dir(), options, self.dir, output_dir) logger.debug(build_command) @@ -139,7 +143,7 @@ def f(self, *args, **kwds): # regular Exception. Otherwise multiprocessing.Pool.get hangs, see # #25161 if ABORT_ON_ERROR: - raise Exception("Non-exception during docbuild: %s"%(e,), e) + raise Exception("Non-exception during docbuild: %s" % (e,), e) if "/latex" in output_dir: logger.warning("LaTeX file written to {}".format(output_dir)) @@ -218,9 +222,9 @@ def _output_formats(self): ['changes', 'html', 'htmlhelp', 'inventory', 'json', 'latex', 'linkcheck', 'pickle', 'web'] """ - #Go through all the attributes of self and check to - #see which ones have an 'is_output_format' attribute. These - #are the ones created with builder_helper. + # Go through all the attributes of self and check to + # see which ones have an 'is_output_format' attribute. These + # are the ones created with builder_helper. output_formats = [] for attr in dir(self): if hasattr(getattr(self, attr), 'is_output_format'): @@ -262,8 +266,8 @@ def pdf(self): error_message = "failed to run $MAKE %s in %s" command = 'all-pdf' - if subprocess.call(make_target%(tex_dir, command, pdf_dir), shell=True): - raise RuntimeError(error_message%(command, tex_dir)) + if subprocess.call(make_target % (tex_dir, command, pdf_dir), shell=True): + raise RuntimeError(error_message % (command, tex_dir)) logger.warning("Build finished. The built documents can be found in %s", pdf_dir) def clean(self, *args): @@ -284,8 +288,6 @@ def clean(self, *args): inventory = builder_helper('inventory') -from .utils import build_many as _build_many - def build_many(target, args, processes=None): """ Thin wrapper around `sage_docbuild.utils.build_many` which uses the @@ -295,10 +297,11 @@ def build_many(target, args, processes=None): processes = NUM_THREADS try: _build_many(target, args, processes=processes) - except BaseException as exc: + except BaseException: if ABORT_ON_ERROR: raise + ########################################## # Parallel Building Ref Manual # ########################################## @@ -358,7 +361,7 @@ def _wrapper(self, name, *args, **kwds): build_other_doc(target) else: build_many(build_other_doc, L) - logger.warning("Elapsed time: %.1f seconds."%(time.time()-start)) + logger.warning("Elapsed time: %.1f seconds." % (time.time() - start)) logger.warning("Done building the documentation!") def get_all_documents(self): @@ -380,7 +383,7 @@ def get_all_documents(self): for lang in LANGUAGES: for document in os.listdir(os.path.join(SAGE_DOC_SRC, lang)): if (document not in OMIT - and os.path.isdir(os.path.join(SAGE_DOC_SRC, lang, document))): + and os.path.isdir(os.path.join(SAGE_DOC_SRC, lang, document))): documents.append(os.path.join(lang, document)) # Ensure that the reference guide is compiled first so that links from @@ -445,7 +448,7 @@ def create_html_redirects(self): # Walk through all of the files in the sage_directory for dirpath, dirnames, filenames in os.walk(sage_directory): # a string like reference/algebras/sage/algebras - short_path = dirpath[len(path)+1:] + short_path = dirpath[len(path) + 1:] # a string like sage/algebras shorter_path = os.path.join(*short_path.split(os.sep)[2:]) @@ -467,14 +470,13 @@ def create_html_redirects(self): levels_up = len(shorter_path.split(os.sep)) # the relative url that we will redirect to - redirect_url = "/".join(['..']*levels_up + [document_name, shorter_path, filename]) + redirect_url = "/".join(['..'] * levels_up + [document_name, shorter_path, filename]) # write the html file which performs the redirect with open(redirect_filename, 'w') as f: print(redirect_filename) f.write(html_template % redirect_url) - def clean(self): """ When we clean the output for the website index, we need to @@ -575,7 +577,6 @@ def _wrapper(self, format, *args, **kwds): Builds reference manuals: build the top-level document and its components. """ - refdir = self._refdir() logger.info('Building bibliography') self._build_bibliography(format, *args, **kwds) logger.info('Bibliography finished, building dependent manuals') @@ -616,7 +617,7 @@ def get_all_documents(self, refdir): n = len(os.listdir(directory)) documents.append((-n, os.path.join(self.name, doc))) - return [ doc[1] for doc in sorted(documents) ] + return [doc[1] for doc in sorted(documents)] class ReferenceTopBuilder(DocBuilder): @@ -707,7 +708,7 @@ def pdf(self): rst = re.sub(r'`([^`\n]*)`__.*\n\n__ (.*)', r'\1.', rst) rst = re.sub(r'`([^<\n]*)\s+<(.*)>`_', - r'\1', rst) + r'\1', rst) rst = re.sub(r':doc:`([^<]*?)\s+<(.*)/index>`', r'\1 ', rst) # Body: add paragraph

markup. @@ -729,7 +730,7 @@ def pdf(self): # now write the file. with open(os.path.join(output_dir, 'index.html'), 'w') as new_index: new_index.write(html[:html_end_preamble]) - new_index.write('

Sage Reference Manual (PDF version)'+ '

') + new_index.write('

Sage Reference Manual (PDF version)

') new_index.write(rst_body) new_index.write('