|
Lines 1-171
Link Here
|
| 1 |
From e1e82e43c9280e7486aad49c7f84a75f4ee1654b Mon Sep 17 00:00:00 2001 |
|
|
| 2 |
From: Takeshi KOMIYA <i.tkomiya@gmail.com> |
| 3 |
Date: Tue, 12 Jul 2016 02:33:19 +0900 |
| 4 |
Subject: [PATCH 1/3] Load some library lazily on sphinx.util to lessen |
| 5 |
dependency |
| 6 |
|
| 7 |
--- |
| 8 |
sphinx/util/__init__.py | 7 +++---- |
| 9 |
1 file changed, 3 insertions(+), 4 deletions(-) |
| 10 |
|
| 11 |
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py |
| 12 |
--- sphinx/util/__init__.py.orig |
| 13 |
+++ sphinx/util/__init__.py |
| 14 |
@@ -24,12 +24,8 @@ |
| 15 |
from six import iteritems, text_type, binary_type |
| 16 |
from six.moves import range |
| 17 |
from six.moves.urllib.parse import urlsplit, urlunsplit, quote_plus, parse_qsl, urlencode |
| 18 |
-import docutils |
| 19 |
from docutils.utils import relative_path |
| 20 |
|
| 21 |
-import jinja2 |
| 22 |
- |
| 23 |
-import sphinx |
| 24 |
from sphinx.errors import PycodeError, SphinxParallelError, ExtensionError |
| 25 |
from sphinx.util.console import strip_colors |
| 26 |
from sphinx.util.fileutil import copy_asset_file |
| 27 |
@@ -186,6 +182,9 @@ def copy_static_entry(source, targetdir, builder, context={}, |
| 28 |
|
| 29 |
def save_traceback(app): |
| 30 |
"""Save the current exception's traceback in a temporary file.""" |
| 31 |
+ import sphinx |
| 32 |
+ import jinja2 |
| 33 |
+ import docutils |
| 34 |
import platform |
| 35 |
exc = sys.exc_info()[1] |
| 36 |
if isinstance(exc, SphinxParallelError): |
| 37 |
|
| 38 |
From 2ccb75c98fbe7e69e4689725affa268e7c538315 Mon Sep 17 00:00:00 2001 |
| 39 |
From: Takeshi KOMIYA <i.tkomiya@gmail.com> |
| 40 |
Date: Mon, 11 Jul 2016 00:27:06 +0900 |
| 41 |
Subject: [PATCH 2/3] Bundle sphinx/pycode/Grammar-*.pickle (ref: #2765) |
| 42 |
|
| 43 |
So far, sphinx generates the grammar files on demand. |
| 44 |
It causes uninstallation does not remove whole of files. |
| 45 |
With this fix, Sphinx bundles the files in the package. |
| 46 |
--- |
| 47 |
MANIFEST.in | 3 +-- |
| 48 |
setup.py | 5 +++++ |
| 49 |
sphinx/pycode/pgen2/driver.py | 42 ++++++++++++++++++++++++++---------------- |
| 50 |
tox.ini | 2 ++ |
| 51 |
4 files changed, 34 insertions(+), 18 deletions(-) |
| 52 |
|
| 53 |
diff --git a/MANIFEST.in b/MANIFEST.in |
| 54 |
--- MANIFEST.in.orig |
| 55 |
+++ MANIFEST.in |
| 56 |
@@ -20,8 +20,7 @@ recursive-include sphinx/search/non-minified-js *.js |
| 57 |
recursive-include sphinx/ext/autosummary/templates * |
| 58 |
recursive-include tests * |
| 59 |
recursive-include utils * |
| 60 |
-include sphinx/pycode/Grammar-py2.txt |
| 61 |
-include sphinx/pycode/Grammar-py3.txt |
| 62 |
+include sphinx/pycode/Grammar-py* |
| 63 |
|
| 64 |
recursive-include doc * |
| 65 |
prune doc/_build |
| 66 |
diff --git a/setup.py b/setup.py |
| 67 |
--- setup.py.orig |
| 68 |
+++ setup.py |
| 69 |
@@ -6,6 +6,7 @@ |
| 70 |
from distutils import log |
| 71 |
|
| 72 |
import sphinx |
| 73 |
+from sphinx.pycode.pgen2.driver import compile_grammar |
| 74 |
|
| 75 |
long_desc = ''' |
| 76 |
Sphinx is a tool that makes it easy to create intelligent and beautiful |
| 77 |
@@ -72,6 +73,10 @@ |
| 78 |
if sys.platform == 'win32': |
| 79 |
requires.append('colorama>=0.3.5') |
| 80 |
|
| 81 |
+# Compile grammars before packaging |
| 82 |
+compile_grammar('sphinx/pycode/Grammar-py2.txt') |
| 83 |
+compile_grammar('sphinx/pycode/Grammar-py3.txt') |
| 84 |
+ |
| 85 |
# Provide a "compile_catalog" command that also creates the translated |
| 86 |
# JavaScript files if Babel is available. |
| 87 |
|
| 88 |
diff --git a/sphinx/pycode/pgen2/driver.py b/sphinx/pycode/pgen2/driver.py |
| 89 |
--- sphinx/pycode/pgen2/driver.py.orig |
| 90 |
+++ sphinx/pycode/pgen2/driver.py |
| 91 |
@@ -109,27 +109,37 @@ def generate_lines(text): |
| 92 |
yield "" |
| 93 |
|
| 94 |
|
| 95 |
-def load_grammar(gt="Grammar.txt", gp=None, |
| 96 |
- save=True, force=False, logger=None): |
| 97 |
+def get_compiled_path(filename): |
| 98 |
+ head, tail = os.path.splitext(filename) |
| 99 |
+ if tail == ".txt": |
| 100 |
+ tail = "" |
| 101 |
+ # embed Sphinx major version for the case we ever change the grammar... |
| 102 |
+ return "%s%s-sphinx%s.pickle" % (head, tail, ".".join(map(str, sphinx.version_info[:2]))) |
| 103 |
+ |
| 104 |
+ |
| 105 |
+def compile_grammar(gt='Grammar.txt', logger=None): |
| 106 |
+ """Compile the grammer.""" |
| 107 |
+ if logger is None: |
| 108 |
+ logger = logging.getLogger() |
| 109 |
+ |
| 110 |
+ logger.info("Generating grammar tables from %s", gt) |
| 111 |
+ g = pgen.generate_grammar(gt) |
| 112 |
+ gp = get_compiled_path(gt) |
| 113 |
+ logger.info("Writing grammar tables to %s", gp) |
| 114 |
+ try: |
| 115 |
+ g.dump(gp) |
| 116 |
+ except IOError as e: |
| 117 |
+ logger.info("Writing failed:"+str(e)) |
| 118 |
+ |
| 119 |
+ |
| 120 |
+def load_grammar(gt="Grammar.txt", logger=None): |
| 121 |
"""Load the grammar (maybe from a pickle).""" |
| 122 |
if logger is None: |
| 123 |
logger = logging.getLogger() |
| 124 |
- if gp is None: |
| 125 |
- head, tail = os.path.splitext(gt) |
| 126 |
- if tail == ".txt": |
| 127 |
- tail = "" |
| 128 |
- # embed Sphinx major version for the case we ever change the grammar... |
| 129 |
- gp = head + tail + "-sphinx" + \ |
| 130 |
- ".".join(map(str, sphinx.version_info[:2])) + ".pickle" |
| 131 |
- if force or not _newer(gp, gt): |
| 132 |
+ gp = get_compiled_path(gt) |
| 133 |
+ if not os.path.exists(gp): |
| 134 |
logger.info("Generating grammar tables from %s", gt) |
| 135 |
g = pgen.generate_grammar(gt) |
| 136 |
- if save: |
| 137 |
- logger.info("Writing grammar tables to %s", gp) |
| 138 |
- try: |
| 139 |
- g.dump(gp) |
| 140 |
- except IOError as e: |
| 141 |
- logger.info("Writing failed:"+str(e)) |
| 142 |
else: |
| 143 |
g = grammar.Grammar() |
| 144 |
g.load(gp) |
| 145 |
|
| 146 |
From 1cabc17edb0c61a7c702c72f98ada38ae0ecaa22 Mon Sep 17 00:00:00 2001 |
| 147 |
From: Takeshi KOMIYA <i.tkomiya@gmail.com> |
| 148 |
Date: Tue, 12 Jul 2016 12:10:36 +0900 |
| 149 |
Subject: [PATCH 3/3] Remove sphinx version from the filename of compiled |
| 150 |
grammar files |
| 151 |
|
| 152 |
Now sphinx bundles the compiled grammar files. Then it will be replaced |
| 153 |
on upgrading sphinx. So the sphinx version is not needed on its |
| 154 |
filename. |
| 155 |
--- |
| 156 |
sphinx/pycode/pgen2/driver.py | 3 +-- |
| 157 |
1 file changed, 1 insertion(+), 2 deletions(-) |
| 158 |
|
| 159 |
diff --git a/sphinx/pycode/pgen2/driver.py b/sphinx/pycode/pgen2/driver.py |
| 160 |
--- sphinx/pycode/pgen2/driver.py.orig |
| 161 |
+++ sphinx/pycode/pgen2/driver.py |
| 162 |
@@ -113,8 +113,7 @@ def get_compiled_path(filename): |
| 163 |
head, tail = os.path.splitext(filename) |
| 164 |
if tail == ".txt": |
| 165 |
tail = "" |
| 166 |
- # embed Sphinx major version for the case we ever change the grammar... |
| 167 |
- return "%s%s-sphinx%s.pickle" % (head, tail, ".".join(map(str, sphinx.version_info[:2]))) |
| 168 |
+ return "%s%s.pickle" % (head, tail) |
| 169 |
|
| 170 |
|
| 171 |
def compile_grammar(gt='Grammar.txt', logger=None): |