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

Commit

Permalink
Fixes #250, fix sphinx to 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Jun 3, 2019
1 parent 2be30a8 commit 80811af
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 174 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ sudo: true
language: python
matrix:
include:
- python: 3.6.6
name: "python3.6 sphinx1.8"
env: sphinxconstraint="<2.0"
- python: 3.7.3
- python: Py.3.7.3-Sph.2.1
name: "python3.7 sphinx2.0"
env: sphinxconstraint=">=2.0"
env: sphinxconstraint=">=2.1"
install:
- pip install -r requirements.txt
- pip install git+https://github.com/fancycode/pylzma.git --upgrade --no-deps
Expand Down
9 changes: 2 additions & 7 deletions _unittests/ut_sphinxext/test_builders_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ class TestBuildersMissing(ExtTestCase):

def test_builders_missing(self):
from docutils import nodes as skip_
try:
from sphinx.builders.latex.util import ExtBabel
sphinx20 = True
except ImportError:
sphinx20 = False
from sphinx.builders.latex.util import ExtBabel

context = {'sphinxpkgoptions': '', 'latex_engine': 'pdflatex',
'fontenc': [], 'babel': [],
Expand Down Expand Up @@ -55,8 +51,7 @@ def __init__(self):
self.md_image_dest = ''
self.env = dummy0()
self.context = context
if sphinx20:
self.babel = ExtBabel('en')
self.babel = ExtBabel('en')

def get(self, name): # pylint: disable=R1711
return None
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ install:
# Install miktex to get pdflatex, if we don't get it from the cache
# - if not exist c:\miktex\texmfs\install\miktex\bin\pdflatex.exe appveyor DownloadFile http://miktex.org/download/ctan/systems/win32/miktex/setup/windows-x86/miktex-portable.exe
# - if not exist c:\miktex\texmfs\install\miktex\bin\pdflatex.exe 7z x miktex-portable.exe -oC:\miktex >NUL
- set miktex_install=miktex-portable-2.9.6942.exe
- if not exist c:\miktex\texmfs\install\miktex\bin\pdflatex.exe appveyor DownloadFile https://miktex.org/download/ctan/systems/win32/miktex/setup/windows-x86/%miktex_install%
- set miktex_install=miktex-portable.exe
- if not exist c:\miktex\texmfs\install\miktex\bin\pdflatex.exe appveyor DownloadFile http://mirrors.ctan.org/systems/win32/miktex/setup/windows-x86/%miktex_install%
- if not exist c:\miktex\texmfs\install\miktex\bin\pdflatex.exe 7z x %miktex_install% -oC:\miktex >NUL
- if not exist c:\miktex @echo Unable to find c:\miktex
- if not exist c:\miktex\texmfs\install\miktex\bin\pdflatex.exe @echo Unable to find c:\miktex\texmfs\install\miktex\bin\pdflatex.exe
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ python-jenkins>=1.0.0
PyYAML
semantic_version
setuptools
Sphinx>=1.8
Sphinx>=2.1
sphinx-gallery
sphinxcontrib-imagesvg
sphinxcontrib-jsdemo
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def write_version():
"semantic_version",
"setuptools",
"simplegeneric",
"sphinx>=1.8",
"sphinx>=2.1",
"sphinx-gallery",
"sphinxcontrib-imagesvg",
"tqdm",
Expand Down
8 changes: 1 addition & 7 deletions src/pyquickhelper/helpgen/sphinx_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
from datetime import datetime
from io import StringIO
from docutils.parsers.rst import directives, roles

try:
from sphinx.cmd.build import main as build_main
except ImportError:
# Sphinx >= 1.7
from sphinx import build_main

from sphinx.cmd.build import main as build_main
from ..filehelper import remove_folder
from ..loghelper import python_path_append
from ..loghelper.process_script import execute_script_get_local_variables, dictionary_as_class
Expand Down
82 changes: 14 additions & 68 deletions src/pyquickhelper/helpgen/sphinxm_convert_doc_sphinx_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,10 @@
from sphinx.transforms import SphinxTransformer
from sphinx.util.docutils import is_html5_writer_available
from sphinx.writers.html import HTMLWriter

try:
from sphinx.util.build_phase import BuildPhase
except ImportError:
class BuildPhase:
pass
BuildPhase.INITIALIZATION = "initialization"

try:
from sphinx.util.logging import prefixed_warnings
sphinx20 = True
except ImportError:
# Sphinx < 2.0
prefixed_warnings = None
sphinx20 = False
try:
from sphinx.project import Project
except ImportError:
# Sphinx < 2.0
class Project:
def __init__(self, srcdir, source_suffix):
self.srcdir = srcdir
self.source_suffix = source_suffix
try:
from sphinx.errors import ApplicationError
except ImportError:
ApplicationError = Exception

from sphinx.util.build_phase import BuildPhase
from sphinx.util.logging import prefixed_warnings
from sphinx.project import Project
from sphinx.errors import ApplicationError
from ..sphinxext.sphinx_doctree_builder import DocTreeBuilder, DocTreeWriter, DocTreeTranslator
from ..sphinxext.sphinx_md_builder import MdBuilder, MdWriter, MdTranslator
from ..sphinxext.sphinx_latex_builder import EnhancedLaTeXBuilder, EnhancedLaTeXWriter, EnhancedLaTeXTranslator
Expand Down Expand Up @@ -1022,10 +998,6 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"
self.post_transforms = [] # type: List[Transform]
self.html_themes = {} # type: Dict[unicode, unicode]

# sphinx 1.8
if not sphinx20:
self._setting_up_extension = [None]

if doctreedir is None:
doctreedir = "IMPOSSIBLE:TOFIND"
if srcdir is None:
Expand Down Expand Up @@ -1057,11 +1029,7 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"
self.quiet = False

from sphinx.events import EventManager
try:
self.events = EventManager(self)
except TypeError:
self.info('Running sphinx version <= 2.1')
self.events = EventManager()
self.events = EventManager(self)

# keep last few messages for traceback
# This will be filled by sphinx.util.logging.LastMessagesWriter
Expand All @@ -1075,19 +1043,14 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"
self.statuscode = 0

# delayed import to speed up time
try:
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
except ImportError:
RemovedInSphinx30Warning = DeprecationWarning
RemovedInSphinx40Warning = DeprecationWarning
from sphinx.application import CONFIG_FILENAME, Config

# read config
from sphinx.application import Tags
self.tags = Tags(tags)
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
warnings.simplefilter("ignore", RemovedInSphinx40Warning)
warnings.simplefilter(
"ignore", (DeprecationWarning, PendingDeprecationWarning))
if self.confdir is None:
try:
self.config = Config({}, confoverrides or {})
Expand All @@ -1106,9 +1069,8 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"

# create the environment
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
warnings.simplefilter("ignore", RemovedInSphinx40Warning)
warnings.simplefilter("ignore", ImportWarning)
warnings.simplefilter(
"ignore", (DeprecationWarning, PendingDeprecationWarning, ImportWarning))
self.config.check_unicode()
self.config.pre_init_values()

Expand Down Expand Up @@ -1218,10 +1180,7 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"

# now that we know all config values, collect them from conf.py
self.config.init_values()
try:
self.events.emit('config-inited', self.config)
except TypeErrpr:
self.emit('config-inited', self.config)
self.events.emit('config-inited', self.config)

# /2 addition to the original code
# check extension versions if requested
Expand Down Expand Up @@ -1294,7 +1253,7 @@ def _init_env(self, freshenv):
self.env = _CustomBuildEnvironment(self)
if hasattr(self.env, 'setup'):
self.env.setup(self)
if sphinx20 and (not hasattr(self.env, 'project') or self.env.project is None):
if not hasattr(self.env, 'project') or self.env.project is None:
raise AttributeError("self.env.project is not initialized.")

def create_builder(self, name):
Expand Down Expand Up @@ -1355,20 +1314,14 @@ def finalize(self, doctree, external_docnames=None):
# If a path startswith('/'), it is removed.
from sphinx.environment.collectors.asset import logger as logger_asset
logger_asset.setLevel(40) # only errors
try:
self.events.emit('doctree-read', doctree)
except TypeError:
self.emit('doctree-read', doctree)
self.events.emit('doctree-read', doctree)
logger_asset.setLevel(30) # back to warnings

for img in imgs:
img['uri'] = img['save_uri']

try:
self.events.emit('doctree-resolved', doctree,
self.config.master_doc)
except TypeError:
self.emit('doctree-resolved', doctree, self.config.master_doc)
self.events.emit('doctree-resolved', doctree,
self.config.master_doc)
self.builder.write(None, None, 'all')

def debug(self, message, *args, **kwargs):
Expand Down Expand Up @@ -1399,17 +1352,10 @@ def setup_extension(self, extname):
self._added_objects.append(('extension', extname))

# delayed import to speed up time
try:
from sphinx.deprecation import RemovedInSphinx30Warning
except ImportError:
RemovedInSphinx30Warning = DeprecationWarning

try:
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", category=DeprecationWarning)
warnings.filterwarnings(
"ignore", category=RemovedInSphinx30Warning)
self.registry.load_extension(self, extname)
except Exception as e:
raise ExtensionError(
Expand Down
12 changes: 2 additions & 10 deletions src/pyquickhelper/helpgen/sphinxm_custom_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,9 @@ def __init__(self, srcdir, outdir, confdir=None, doctreedir=None,
confoverrides['extensions'] = exts

# delayed import to speed up time
try:
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning, RemovedInSphinx20Warning
except ImportError:
RemovedInSphinx20Warning = DeprecationWarning
RemovedInSphinx30Warning = DeprecationWarning
RemovedInSphinx40Warning = DeprecationWarning

with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx20Warning)
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
warnings.simplefilter("ignore", RemovedInSphinx40Warning)
warnings.simplefilter(
"ignore", (DeprecationWarning, PendingDeprecationWarning))
Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
buildername, confoverrides, status,
warning, freshenv, warningiserror, tags,
Expand Down
14 changes: 3 additions & 11 deletions src/pyquickhelper/helpgen/sphinxm_mock_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,12 @@ def __init__(self, writer, app, confoverrides, new_extensions=None):
}

# delayed import to speed up import time
try:
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
except ImportError:
RemovedInSphinx30Warning = DeprecationWarning
RemovedInSphinx40Warning = DeprecationWarning
from sphinx.config import Config

self.mapping_connect = {}
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
warnings.simplefilter("ignore", RemovedInSphinx40Warning)
warnings.simplefilter(
"ignore", (DeprecationWarning, PendingDeprecationWarning))
self.config = Config(None, None, confoverrides, None)
self.confdir = "."
self.doctreedir = "."
Expand Down Expand Up @@ -137,10 +132,7 @@ def emit(self, event, *args):
"""
See :epkg:`class Sphinx`.
"""
try:
return self.app.events.emit(event, *args)
except TypeError:
return self.app.emit(event, *args)
return self.app.events.emit(event, *args)

def emit_firstresult(self, event, *args):
"""
Expand Down
9 changes: 2 additions & 7 deletions src/pyquickhelper/sphinxext/bokeh/bokeh_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
from sphinx.errors import SphinxError
from sphinx.util import console, copyfile, ensuredir, status_iterator
from sphinx.util.nodes import set_source_info
try:
from sphinx.deprecation import RemovedInSphinx30Warning, RemovedInSphinx40Warning
except ImportError:
RemovedInSphinx30Warning = DeprecationWarning
RemovedInSphinx40Warning = DeprecationWarning

from bokeh.settings import settings
from bokeh.resources import Resources
Expand Down Expand Up @@ -341,8 +336,8 @@ def setup(app):
app.add_config_value('bokeh_plot_pyfile_include_dirs', [], 'html')

with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
warnings.simplefilter("ignore", RemovedInSphinx40Warning)
warnings.simplefilter(
"ignore", (DeprecationWarning, PendingDeprecationWarning))
app.add_source_parser('.py', PlotScriptParser)

app.add_directive('bokeh-plot', BokehPlotDirective)
Expand Down
50 changes: 3 additions & 47 deletions src/pyquickhelper/sphinxext/sphinx_latex_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,9 @@
from sphinx.writers.latex import rstdim_to_latexdim
from sphinx.util import logging
from sphinx import addnodes

try:
from sphinx.writers.latex import toRoman
except ImportError:
# Sphinx 1.7
def toRoman(x):
return x
try:
# Sphinx >= 1.8
from sphinx.writers.latex import ENUMERATE_LIST_STYLE
except ImportError:
# Sphinx < 1.8
from collections import defaultdict
ENUMERATE_LIST_STYLE = defaultdict(lambda: r'\arabic',
{
'arabic': r'\arabic',
'loweralpha': r'\alph',
'upperalpha': r'\Alph',
'lowerroman': r'\roman',
'upperroman': r'\Roman',
})

try:
# Sphinx >= 1.8
from sphinx.util.docutils import SphinxFileOutput
except ImportError:
# Sphinx < 1.8
from docutils.io import FileOutput

class SphinxFileOutput(FileOutput):
"""Better FileOutput class for Sphinx."""

def __init__(self, **kwargs):
# type: (Any) -> None
self.overwrite_if_changed = kwargs.pop(
'overwrite_if_changed', False)
FileOutput.__init__(self, **kwargs)

def write(self, data):
# type: (unicode) -> unicode
if (self.destination_path and self.autoclose and 'b' not in self.mode and
self.overwrite_if_changed and os.path.exists(self.destination_path)):
with open(self.destination_path, encoding=self.encoding) as f:
# skip writing: content not changed
if f.read() == data:
return data
return FileOutput.write(self, data)
from sphinx.writers.latex import toRoman
from sphinx.writers.latex import ENUMERATE_LIST_STYLE
from sphinx.util.docutils import SphinxFileOutput


class CustomizedSphinxFileOutput(SphinxFileOutput):
Expand Down
5 changes: 1 addition & 4 deletions src/pyquickhelper/sphinxext/sphinx_tocdelay_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from docutils import nodes
from docutils.parsers.rst import Directive, directives
from sphinx.util import logging
try:
from sphinx.errors import NoUri
except ImportError:
from sphinx.environment import NoUri
from sphinx.errors import NoUri
import sphinx


Expand Down
5 changes: 1 addition & 4 deletions src/pyquickhelper/sphinxext/sphinx_todoext_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

import sphinx
from sphinx.locale import _ as locale_
try:
from sphinx.errors import NoUri
except ImportError:
from sphinx.environment import NoUri
from sphinx.errors import NoUri
from docutils.parsers.rst import Directive
from docutils.parsers.rst.directives.admonitions import BaseAdmonition
from sphinx.util.nodes import set_source_info, process_index_entry
Expand Down

0 comments on commit 80811af

Please sign in to comment.