mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #2770 from tk0miya/2765_bundle_grammars
Fix #2765: bundle grammar files
This commit is contained in:
commit
b03b7e543f
@ -21,8 +21,7 @@ recursive-include sphinx/search/non-minified-js *.js
|
|||||||
recursive-include sphinx/ext/autosummary/templates *
|
recursive-include sphinx/ext/autosummary/templates *
|
||||||
recursive-include tests *
|
recursive-include tests *
|
||||||
recursive-include utils *
|
recursive-include utils *
|
||||||
include sphinx/pycode/Grammar-py2.txt
|
include sphinx/pycode/Grammar-py*
|
||||||
include sphinx/pycode/Grammar-py3.txt
|
|
||||||
|
|
||||||
recursive-include doc *
|
recursive-include doc *
|
||||||
prune doc/_build
|
prune doc/_build
|
||||||
|
5
setup.py
5
setup.py
@ -6,6 +6,7 @@ import sys
|
|||||||
from distutils import log
|
from distutils import log
|
||||||
|
|
||||||
import sphinx
|
import sphinx
|
||||||
|
from sphinx.pycode.pgen2.driver import compile_grammar
|
||||||
|
|
||||||
long_desc = '''
|
long_desc = '''
|
||||||
Sphinx is a tool that makes it easy to create intelligent and beautiful
|
Sphinx is a tool that makes it easy to create intelligent and beautiful
|
||||||
@ -72,6 +73,10 @@ extras_require = {
|
|||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
requires.append('colorama>=0.3.5')
|
requires.append('colorama>=0.3.5')
|
||||||
|
|
||||||
|
# Compile grammars before packaging
|
||||||
|
compile_grammar('sphinx/pycode/Grammar-py2.txt')
|
||||||
|
compile_grammar('sphinx/pycode/Grammar-py3.txt')
|
||||||
|
|
||||||
# Provide a "compile_catalog" command that also creates the translated
|
# Provide a "compile_catalog" command that also creates the translated
|
||||||
# JavaScript files if Babel is available.
|
# JavaScript files if Babel is available.
|
||||||
|
|
||||||
|
@ -109,27 +109,36 @@ def generate_lines(text):
|
|||||||
yield ""
|
yield ""
|
||||||
|
|
||||||
|
|
||||||
def load_grammar(gt="Grammar.txt", gp=None,
|
def get_compiled_path(filename):
|
||||||
save=True, force=False, logger=None):
|
head, tail = os.path.splitext(filename)
|
||||||
|
if tail == ".txt":
|
||||||
|
tail = ""
|
||||||
|
return "%s%s.pickle" % (head, tail)
|
||||||
|
|
||||||
|
|
||||||
|
def compile_grammar(gt='Grammar.txt', logger=None):
|
||||||
|
"""Compile the grammer."""
|
||||||
|
if logger is None:
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
logger.info("Generating grammar tables from %s", gt)
|
||||||
|
g = pgen.generate_grammar(gt)
|
||||||
|
gp = get_compiled_path(gt)
|
||||||
|
logger.info("Writing grammar tables to %s", gp)
|
||||||
|
try:
|
||||||
|
g.dump(gp)
|
||||||
|
except IOError as e:
|
||||||
|
logger.info("Writing failed:"+str(e))
|
||||||
|
|
||||||
|
|
||||||
|
def load_grammar(gt="Grammar.txt", logger=None):
|
||||||
"""Load the grammar (maybe from a pickle)."""
|
"""Load the grammar (maybe from a pickle)."""
|
||||||
if logger is None:
|
if logger is None:
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
if gp is None:
|
gp = get_compiled_path(gt)
|
||||||
head, tail = os.path.splitext(gt)
|
if not os.path.exists(gp):
|
||||||
if tail == ".txt":
|
|
||||||
tail = ""
|
|
||||||
# embed Sphinx major version for the case we ever change the grammar...
|
|
||||||
gp = head + tail + "-sphinx" + \
|
|
||||||
".".join(map(str, sphinx.version_info[:2])) + ".pickle"
|
|
||||||
if force or not _newer(gp, gt):
|
|
||||||
logger.info("Generating grammar tables from %s", gt)
|
logger.info("Generating grammar tables from %s", gt)
|
||||||
g = pgen.generate_grammar(gt)
|
g = pgen.generate_grammar(gt)
|
||||||
if save:
|
|
||||||
logger.info("Writing grammar tables to %s", gp)
|
|
||||||
try:
|
|
||||||
g.dump(gp)
|
|
||||||
except IOError as e:
|
|
||||||
logger.info("Writing failed:"+str(e))
|
|
||||||
else:
|
else:
|
||||||
g = grammar.Grammar()
|
g = grammar.Grammar()
|
||||||
g.load(gp)
|
g.load(gp)
|
||||||
|
@ -24,12 +24,8 @@ from collections import deque
|
|||||||
from six import iteritems, text_type, binary_type
|
from six import iteritems, text_type, binary_type
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
from six.moves.urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
|
from six.moves.urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode
|
||||||
import docutils
|
|
||||||
from docutils.utils import relative_path
|
from docutils.utils import relative_path
|
||||||
|
|
||||||
import jinja2
|
|
||||||
|
|
||||||
import sphinx
|
|
||||||
from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError
|
from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError
|
||||||
from sphinx.util.console import strip_colors
|
from sphinx.util.console import strip_colors
|
||||||
from sphinx.util.fileutil import copy_asset_file
|
from sphinx.util.fileutil import copy_asset_file
|
||||||
@ -186,6 +182,9 @@ _DEBUG_HEADER = '''\
|
|||||||
|
|
||||||
def save_traceback(app):
|
def save_traceback(app):
|
||||||
"""Save the current exception's traceback in a temporary file."""
|
"""Save the current exception's traceback in a temporary file."""
|
||||||
|
import sphinx
|
||||||
|
import jinja2
|
||||||
|
import docutils
|
||||||
import platform
|
import platform
|
||||||
exc = sys.exc_info()[1]
|
exc = sys.exc_info()[1]
|
||||||
if isinstance(exc, SphinxParallelError):
|
if isinstance(exc, SphinxParallelError):
|
||||||
|
Loading…
Reference in New Issue
Block a user