Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit b1304eb

Browse files
authored
Enables support for Sphinx 4.0 (#339)
* fix for sphinx 4.0 * switch document, builder * removes jsdemo
1 parent b15433e commit b1304eb

File tree

11 files changed

+41
-53
lines changed

11 files changed

+41
-53
lines changed

_doc/sphinxdoc/source/blog/2015/2015-12-12_sphinx_extensions.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
`Sphinx <http://sphinx-doc.org/>`_ documentation:
1313

1414
* `imagesvg <https://pypi.python.org/pypi/sphinxcontrib-imagesvg/>`_: to include svg figures
15-
* `jsdemo <https://pypi.python.org/pypi/sphinxcontrib-imagesvg/>`_: to demo javascript and HTML
1615

1716
.. demo::
1817

_unittests/ut_sphinxext/test_style_doc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def test_docstyle(self):
2626
extensions = [_ for _ in extensions if "matplotlib" not in _ and
2727
"images" not in _ and "IPython" not in _ and
2828
"nbsphinx" not in _ and "jupyter" not in _ and
29-
"jsdemo" not in _ and
3029
"inheritance_diagram" not in _]
3130
external_docnames = [
3231
"_modules/src/pyquickhelper/helpgen/_fake_function_to_documentation"]

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ PyYAML
4646
scipy
4747
semantic_version
4848
setuptools
49-
Sphinx>=3.0,<4.0
49+
Sphinx>=3.0
5050
sphinx-gallery
5151
sphinxcontrib-imagesvg
52-
sphinxcontrib-jsdemo
5352
sphinx_rtd_theme
5453
tabulate
5554
tqdm

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
'pysftp',
137137
"requests",
138138
"semantic_version",
139-
"sphinx>=3.0,<4.0",
139+
"sphinx>=3.0",
140140
"sphinx-gallery",
141141
"sphinxcontrib-imagesvg",
142142
"traitlets>=5.0",

src/pyquickhelper/helpgen/default_conf.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,14 +569,6 @@ def set_sphinx_variables(fileconf, module_name, author, year, theme, theme_path,
569569
# matplotlib is not installed.
570570
pass
571571

572-
try:
573-
import sphinxcontrib.jsdemo
574-
assert sphinxcontrib.jsdemo is not None
575-
extensions.append('sphinxcontrib.jsdemo')
576-
except ImportError: # pragma: no cover
577-
# No module sphinxcontrib.jsdemo.
578-
pass
579-
580572
if use_lunrsearch: # pragma: no cover
581573
extensions.append('sphinxcontrib.lunrsearch')
582574

src/pyquickhelper/helpgen/sphinxm_convert_doc_sphinx_helper.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
from sphinx.project import Project
2727
from sphinx.errors import ApplicationError
2828
from sphinx.util.logging import getLogger
29-
from ..sphinxext.sphinx_doctree_builder import DocTreeBuilder, DocTreeWriter, DocTreeTranslator
29+
from ..sphinxext.sphinx_doctree_builder import (
30+
DocTreeBuilder, DocTreeWriter, DocTreeTranslator)
3031
from ..sphinxext.sphinx_md_builder import MdBuilder, MdWriter, MdTranslator
31-
from ..sphinxext.sphinx_latex_builder import EnhancedLaTeXBuilder, EnhancedLaTeXWriter, EnhancedLaTeXTranslator
32+
from ..sphinxext.sphinx_latex_builder import (
33+
EnhancedLaTeXBuilder, EnhancedLaTeXWriter, EnhancedLaTeXTranslator)
3234
from ..sphinxext.sphinx_rst_builder import RstBuilder, RstWriter, RstTranslator
3335
from ._single_file_html_builder import CustomSingleFileHTMLBuilder
3436

@@ -171,8 +173,8 @@ class HTMLTranslatorWithCustomDirectives(_AdditionalVisitDepart, HTMLTranslator)
171173
See @see cl HTMLWriterWithCustomDirectives.
172174
"""
173175

174-
def __init__(self, builder, *args, **kwds):
175-
HTMLTranslator.__init__(self, builder, *args, **kwds)
176+
def __init__(self, document, builder, *args, **kwds):
177+
HTMLTranslator.__init__(self, document, builder, *args, **kwds)
176178
_AdditionalVisitDepart.__init__(self, 'html')
177179
nodes_list = getattr(builder, '_function_node', None)
178180
if nodes_list is not None:
@@ -201,11 +203,11 @@ class RSTTranslatorWithCustomDirectives(_AdditionalVisitDepart, RstTranslator):
201203
See @see cl HTMLWriterWithCustomDirectives.
202204
"""
203205

204-
def __init__(self, builder, *args, **kwds):
206+
def __init__(self, document, builder, *args, **kwds):
205207
"""
206208
constructor
207209
"""
208-
RstTranslator.__init__(self, builder, *args, **kwds)
210+
RstTranslator.__init__(self, document, builder, *args, **kwds)
209211
_AdditionalVisitDepart.__init__(self, 'rst')
210212
for name, f1, f2 in builder._function_node:
211213
setattr(self.__class__, "visit_" + name, f1)
@@ -218,11 +220,11 @@ class MDTranslatorWithCustomDirectives(_AdditionalVisitDepart, MdTranslator):
218220
See @see cl HTMLWriterWithCustomDirectives.
219221
"""
220222

221-
def __init__(self, builder, *args, **kwds):
223+
def __init__(self, document, builder, *args, **kwds):
222224
"""
223225
constructor
224226
"""
225-
MdTranslator.__init__(self, builder, *args, **kwds)
227+
MdTranslator.__init__(self, document, builder, *args, **kwds)
226228
_AdditionalVisitDepart.__init__(self, 'md')
227229
for name, f1, f2 in builder._function_node:
228230
setattr(self.__class__, "visit_" + name, f1)
@@ -235,11 +237,11 @@ class DocTreeTranslatorWithCustomDirectives(DocTreeTranslator):
235237
See @see cl HTMLWriterWithCustomDirectives.
236238
"""
237239

238-
def __init__(self, builder, *args, **kwds):
240+
def __init__(self, document, builder, *args, **kwds):
239241
"""
240242
constructor
241243
"""
242-
DocTreeTranslator.__init__(self, builder, *args, **kwds)
244+
DocTreeTranslator.__init__(self, document, builder, *args, **kwds)
243245
self.base_class = DocTreeTranslator
244246

245247

@@ -248,7 +250,7 @@ class LatexTranslatorWithCustomDirectives(_AdditionalVisitDepart, EnhancedLaTeXT
248250
See @see cl LatexWriterWithCustomDirectives.
249251
"""
250252

251-
def __init__(self, builder, document, *args, **kwds):
253+
def __init__(self, document, builder, *args, **kwds):
252254
"""
253255
constructor
254256
"""
@@ -258,7 +260,7 @@ def __init__(self, builder, document, *args, **kwds):
258260
raise TypeError( # pragma: no cover
259261
"Builder has no config: {} - {}".format(type(builder), type(document)))
260262
EnhancedLaTeXTranslator.__init__(
261-
self, builder, document, *args, **kwds)
263+
self, document, builder, *args, **kwds)
262264
_AdditionalVisitDepart.__init__(self, 'md')
263265
for name, f1, f2 in builder._function_node:
264266
setattr(self.__class__, "visit_" + name, f1)
@@ -319,9 +321,6 @@ def write(self, document, destination):
319321
320322
Normally not overridden or extended in subclasses.
321323
"""
322-
# trans = self.builder.create_translator(self.builder, document)
323-
# if not isinstance(trans, HTMLTranslatorWithCustomDirectives):
324-
# raise TypeError("The translator is not of a known type but '{0}'".format(type(trans)))
325324
self.base_class.write(self, document, destination)
326325

327326

@@ -347,7 +346,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
347346

348347
def translate(self):
349348
self.visitor = visitor = self.translator_class(
350-
self.builder, self.document)
349+
self.document, self.builder)
351350
self.document.walkabout(visitor)
352351
self.output = visitor.astext()
353352
for attr in ('head_prefix', 'stylesheet', 'head', 'body_prefix',
@@ -374,7 +373,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
374373
self, RstWriter, RSTTranslatorWithCustomDirectives, app)
375374

376375
def translate(self):
377-
visitor = self.translator_class(self.builder, self.document)
376+
visitor = self.translator_class(self.document, self.builder)
378377
self.document.walkabout(visitor)
379378
self.output = visitor.body
380379

@@ -394,7 +393,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
394393
self, MdWriter, MDTranslatorWithCustomDirectives, app)
395394

396395
def translate(self):
397-
visitor = self.translator_class(self.builder, self.document)
396+
visitor = self.translator_class(self.document, self.builder)
398397
self.document.walkabout(visitor)
399398
self.output = visitor.body
400399

@@ -414,7 +413,7 @@ def __init__(self, builder=None, app=None): # pylint: disable=W0231
414413
self, DocTreeWriter, DocTreeTranslatorWithCustomDirectives, app)
415414

416415
def translate(self):
417-
visitor = self.translator_class(self.builder, self.document)
416+
visitor = self.translator_class(self.document, self.builder)
418417
self.document.walkabout(visitor)
419418
self.output = visitor.body
420419

@@ -441,10 +440,10 @@ def translate(self):
441440
raise TypeError( # pragma: no cover
442441
"Builder has no config: {}".format(type(self.builder)))
443442
# The instruction
444-
# visitor = self.builder.create_translator(self.builder, self.document)
443+
# visitor = self.builder.create_translator(self.document, self.builder)
445444
# automatically adds methods visit_ and depart_ for translator
446445
# based on the list of registered extensions. Might be worth using it.
447-
visitor = self.translator_class(self.builder, self.document)
446+
visitor = self.translator_class(self.document, self.builder)
448447
self.document.walkabout(visitor)
449448
self.output = visitor.body
450449

@@ -1208,7 +1207,7 @@ def _citems():
12081207

12091208
# create the project
12101209
self.project = Project(self.srcdir, self.config.source_suffix)
1211-
# create the builder
1210+
# create the builder, initializes _MemoryBuilder
12121211
self.builder = self.create_builder(buildername)
12131212
# set up the build environment
12141213
self._init_env(freshenv)
@@ -1221,9 +1220,17 @@ def _citems():
12211220

12221221
# addition
12231222
self._extended_init_()
1223+
1224+
# verification
1225+
self._check_init_()
1226+
1227+
def _check_init_(self):
1228+
pass
12241229

12251230
def _init_env(self, freshenv):
1226-
if freshenv:
1231+
ENV_PICKLE_FILENAME = 'environment.pickle'
1232+
filename = os.path.join(self.doctreedir, ENV_PICKLE_FILENAME)
1233+
if freshenv or not os.path.exists(filename):
12271234
self.env = _CustomBuildEnvironment(self)
12281235
self.env.setup(self)
12291236
if self.srcdir is not None and self.srcdir != "IMPOSSIBLE:TOFIND":

src/pyquickhelper/sphinxext/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,4 @@ def get_default_standard_extensions(use_mathjax=False):
158158
'matplotlib.sphinxext.plot_directive',
159159
]
160160

161-
try:
162-
import sphinxcontrib.jsdemo
163-
assert sphinxcontrib.jsdemo is not None
164-
extensions.append('sphinxcontrib.jsdemo')
165-
except ImportError: # pragma: no cover
166-
# No module sphinxcontrib.jsdemo.
167-
pass
168-
169161
return extensions

src/pyquickhelper/sphinxext/sphinx_doctree_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DocTreeTranslator(nodes.NodeVisitor, CommonSphinxWriterHelpers):
2020
Defines a translator for doctree
2121
"""
2222

23-
def __init__(self, builder, document):
23+
def __init__(self, document, builder):
2424
if not hasattr(builder, 'config'):
2525
raise TypeError( # pragma: no cover
2626
"Unexpected type for builder {0}".format(type(builder)))
@@ -262,7 +262,7 @@ def __init__(self, builder):
262262
self.builder = builder
263263

264264
def translate(self):
265-
visitor = self.builder.create_translator(self.builder, self.document)
265+
visitor = self.builder.create_translator(self.document, self.builder)
266266
self.document.walkabout(visitor)
267267
self.output = visitor.body
268268

src/pyquickhelper/sphinxext/sphinx_latex_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class EnhancedLaTeXTranslator(LaTeXTranslator):
3535
and modifies a few functions.
3636
"""
3737

38-
def __init__(self, builder, document):
38+
def __init__(self, document, builder):
3939
if not hasattr(builder, 'config'):
4040
raise TypeError(
4141
"Unexpected type for builder {0}".format(type(builder)))
@@ -183,7 +183,7 @@ def __init__(self, builder):
183183
LaTeXWriter.__init__(self, builder)
184184

185185
def translate(self):
186-
visitor = self.builder.create_translator(self.builder, self.document)
186+
visitor = self.builder.create_translator(self.document, self.builder)
187187
self.document.walkabout(visitor)
188188
self.output = visitor.astext()
189189

@@ -259,8 +259,8 @@ def write(self, *ignored):
259259
docname, toctree_only,
260260
appendices=((docclass != 'howto') and self.config.latex_appendices or []))
261261
doctree['tocdepth'] = tocdepth
262-
self.apply_transforms(doctree)
263262
self.post_process_images(doctree)
263+
264264
self.logger.info(__("writing... "), nonl=1)
265265
doctree.settings = docsettings
266266
doctree.settings.author = author

src/pyquickhelper/sphinxext/sphinx_md_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class MdTranslator(TextTranslator, CommonSphinxWriterHelpers):
5454
Defines a :epkg:`MD` translator.
5555
"""
5656

57-
def __init__(self, builder, document):
57+
def __init__(self, document, builder):
5858
if not hasattr(builder, "config"):
5959
raise TypeError( # pragma: no cover
6060
"Builder has no config: {}".format(type(builder)))
@@ -1101,7 +1101,7 @@ def __init__(self, builder):
11011101
self.builder = builder
11021102

11031103
def translate(self):
1104-
visitor = self.builder.create_translator(self.builder, self.document)
1104+
visitor = self.builder.create_translator(self.document, self.builder)
11051105
self.document.walkabout(visitor)
11061106
self.output = visitor.body
11071107

0 commit comments

Comments
 (0)