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

Commit

Permalink
remove warnings, back to latex and not elatex for notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Sep 14, 2018
1 parent 5b07013 commit 28c520c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 140 deletions.
Empty file removed _unittests/ut_sphinxext/Python.tex
Empty file.
105 changes: 0 additions & 105 deletions _unittests/ut_sphinxext/sphinxhighlight.sty

This file was deleted.

6 changes: 3 additions & 3 deletions _unittests/ut_sphinxext/test_latex_builder.py
Expand Up @@ -383,11 +383,11 @@ def test_latex_image(self):
img2 = os.path.join(root, "data", "thumbnail", "im.png")
content = """
.. image:: {0}
:width: 200
:width: 59
:alt: alternative1
* .. image:: {1}
:width: 200
:width: 59
:alt: alternative2
""".replace(" ", "").format(img1, img2).replace("\\", "/")
if sys.version_info[0] >= 3:
Expand All @@ -400,7 +400,7 @@ def test_latex_image(self):

text = text.replace("\r", "")
self.assertIn('sphinxincludegraphics', text)
self.assertIn('=200', text)
self.assertIn('=59', text)
self.assertIn("png", text)
with open(os.path.join(temp, "elatex_image.tex"), "w", encoding="utf8") as f:
f.write(text)
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/helpgen/_nbconvert_preprocessor.py
Expand Up @@ -8,7 +8,7 @@

class LatexRawOutputPreprocessor(Preprocessor):
"""
Custom processor to apply a different syle on raw output.
Custom processor to apply a different style on raw output.
"""

def preprocess_cell(self, cell, resources, cell_index):
Expand Down
10 changes: 5 additions & 5 deletions src/pyquickhelper/helpgen/process_notebooks.py
Expand Up @@ -387,15 +387,15 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
list_args.extend(['--config', '"%s"' % custom_config,
'--SphinxTransformer.author=""',
'--SphinxTransformer.overridetitle="{0}"'.format(title)])
format = "elatex"
format = "latex"
compilation = True
thisfiles.append(os.path.splitext(outputfile)[0] + ".tex")
elif format in ("latex", "elatex"):
if not os.path.exists(custom_config):
raise FileNotFoundError(custom_config)
list_args.extend(['--config', '"%s"' % custom_config])
compilation = False
format = "elatex"
format = "latex"
elif format in ("word", "docx"):
format = "html"
compilation = False
Expand All @@ -409,7 +409,7 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
compilation = False

# output
templ = {'html': 'full', 'latex': 'article'}.get(format, format)
templ = {'html': 'full', 'latex': 'article', 'elatex': 'article'}.get(format, format)
fLOG("[_process_notebooks_in] ### convert into ", format_, " NB: ", notebook,
" ### ", os.path.exists(outputfile), ":", outputfile)

Expand Down Expand Up @@ -458,8 +458,8 @@ def _process_notebooks_in(notebooks, outfold, build, latex_path=None, pandoc_pat
out, err = _process_notebooks_in_private_cmd(
fnbcexe, list_args, options_args, fLOG)

if "raise ImportError" in err:
raise ImportError(err)
if "raise ImportError" in err or "Unknown exporter" in err:
raise ImportError("cmd: {0} {1}\n--ERR--\n{2}".format(fnbcexe, list_args, err))
if len(err) > 0:
if format in ("elatex", "latex"):
# There might be some errors because the latex script needs to be post-processed
Expand Down
24 changes: 18 additions & 6 deletions src/pyquickhelper/helpgen/sphinxm_convert_doc_sphinx_helper.py
Expand Up @@ -9,8 +9,9 @@
from collections import deque
import warnings
import pickle
from sphinx.deprecation import RemovedInSphinx30Warning
from sphinx.locale import _
from docutils.parsers.rst import directives, roles
from docutils.parsers.rst import directives, roles, convert_directive_function
from docutils.languages import en as docutils_en
from sphinx.writers.html import HTMLWriter
from sphinx.application import Sphinx, ENV_PICKLE_FILENAME
Expand Down Expand Up @@ -1281,13 +1282,18 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"

# read config
self.tags = Tags(tags)
self.config = Config(confdir, CONFIG_FILENAME,
confoverrides or {}, self.tags)
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
self.config = Config(confdir, CONFIG_FILENAME,
confoverrides or {}, self.tags)
self.sphinx__display_version__ = __display_version__

# create the environment
self.env = _CustomBuildEnvironment(self)
self.config.check_unicode()
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
warnings.simplefilter("ignore", ImportWarning)
self.config.check_unicode()
self.config.pre_init_values()

# set up translation infrastructure
Expand Down Expand Up @@ -1387,7 +1393,9 @@ def __init__(self, srcdir, confdir, outdir, doctreedir, buildername="memoryhtml"
# create the builder
self.builder = self.create_builder(buildername)
# check all configuration values for permissible types
self.config.check_types()
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
self.config.check_types()
# set up the build environment
self._init_env(freshenv)
# set up the builder
Expand Down Expand Up @@ -1511,7 +1519,11 @@ def add_directive(self, name, obj, content=None, arguments=None, override=False,
'already registered, it will be overridden'),
self._setting_up_extension[-1], name,
type='app', subtype='add_directive')
directive = directive_helper(obj, content, arguments, **options)

obj.content = content # type: ignore
obj.arguments = arguments or (0, 0, False) # type: ignore
obj.options = options # type: ignore
directive = convert_directive_function(obj)
directives.register_directive(name, directive)

def add_domain(self, domain, override=False):
Expand Down
25 changes: 16 additions & 9 deletions src/pyquickhelper/helpgen/sphinxm_mock_app.py
Expand Up @@ -5,6 +5,7 @@
.. versionadded:: 1.0
"""
import logging
import warnings
from docutils import nodes
from docutils.parsers.rst.directives import directive as rst_directive
from docutils.parsers.rst import directives as doc_directives, roles as doc_roles
Expand All @@ -14,6 +15,7 @@
from sphinx.application import VersionRequirementError
from sphinx.util.docutils import is_html5_writer_available
from sphinx.errors import ExtensionError
from sphinx.deprecation import RemovedInSphinx30Warning
from .sphinxm_convert_doc_sphinx_helper import HTMLWriterWithCustomDirectives, _CustomSphinx
from .sphinxm_convert_doc_sphinx_helper import MDWriterWithCustomDirectives, RSTWriterWithCustomDirectives, LatexWriterWithCustomDirectives
from ..sphinxext import get_default_extensions
Expand Down Expand Up @@ -50,7 +52,9 @@ def __init__(self, writer, app, confoverrides, new_extensions=None):
"<class 'matplotlib.sphinxext.only_directives.latex_only'>": "only",
}
self.mapping_connect = {}
self.config = Config(None, None, confoverrides, None)
with warnings.catch_warnings():
warnings.simplefilter("ignore", RemovedInSphinx30Warning)
self.config = Config(None, None, confoverrides, None)
self.confdir = "."
self.doctreedir = "."
self.srcdir = "."
Expand Down Expand Up @@ -257,14 +261,17 @@ def add_source_parser(self, ext, parser, exc=False):
app.add_source_parser(self, ext, parser)
"""
try:
self.app.add_source_parser(ext, parser)
except ExtensionError as e:
if exc:
raise
else:
logger = logging.getLogger("MockSphinxApp")
logger.warning('[MockSphinxApp] {0}'.format(e))
with warnings.catch_warnings():
warnings.simplefilter("ignore", ImportWarning)

try:
self.app.add_source_parser(ext, parser)
except ExtensionError as e:
if exc:
raise
else:
logger = logging.getLogger("MockSphinxApp")
logger.warning('[MockSphinxApp] {0}'.format(e))

def disconnect_env_collector(self, clname):
"""
Expand Down
10 changes: 6 additions & 4 deletions src/pyquickhelper/pycode/default_filter_warning.py
Expand Up @@ -18,10 +18,12 @@ def default_filter_warning(w):
class UnusedException(Exception):
pass

try:
from matplotlib.cbook import MatplotlibDeprecationWarning
except ImportError:
MatplotlibDeprecationWarning = UnusedException
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
try:
from matplotlib.cbook import MatplotlibDeprecationWarning
except ImportError:
MatplotlibDeprecationWarning = UnusedException

if isinstance(w.message, RuntimeWarning):
if "_bootstrap.py" in w.filename:
Expand Down
3 changes: 2 additions & 1 deletion src/pyquickhelper/sphinxext/_sphinx_common_builder.py
Expand Up @@ -87,7 +87,8 @@ def base_visit_image(self, node, image_dest=None):
full = os.path.join(srcdir, atts['src']) if srcdir else atts['src']
if not os.path.exists(full):
raise FileNotFoundError(
"Unable to find source file '{0}' for docname '{1}'".format(full, atts['src']))
"Unable to find source file '{0}' for docname '{1}', srcdir='{2}' src='{3}'".format(
full, atts['src'], srcdir, atts['src']))
ext = os.path.splitext(atts['src'])[-1]
name = self.hash_md5_readfile(full) + ext

Expand Down
6 changes: 5 additions & 1 deletion src/pyquickhelper/sphinxext/bokeh/bokeh_plot.py
Expand Up @@ -69,6 +69,7 @@
"""
from __future__ import absolute_import

import warnings
import ast
from os.path import basename, dirname, join
import re
Expand All @@ -80,6 +81,7 @@
from sphinx.errors import SphinxError
from sphinx.util import console, copyfile, ensuredir, status_iterator
from sphinx.util.nodes import set_source_info
from sphinx.deprecation import RemovedInSphinx30Warning

from bokeh.settings import settings
from bokeh.resources import Resources
Expand Down Expand Up @@ -336,7 +338,9 @@ def setup(app):
""" sphinx config variable to scan .py files in provided directories only """
app.add_config_value('bokeh_plot_pyfile_include_dirs', [], 'html')

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

app.add_directive('bokeh-plot', BokehPlotDirective)

Expand Down
7 changes: 2 additions & 5 deletions src/pyquickhelper/sphinxext/sphinx_md_builder.py
Expand Up @@ -894,9 +894,6 @@ def clean_refuri(uri):
(anchor, clean_refuri(node['refuri'])))
raise nodes.SkipNode
elif 'reftitle' in node:
# Include node as text, rather than with markup.
# reST seems unable to parse a construct like ` ``literal`` <url>`_
# Hence it reverts to the more simple `literal <url>`_
self.add_text('[%s](%s)' %
(node.astext(), clean_refuri(node['refuri'])))
# self.end_state(wrap=False)
Expand Down Expand Up @@ -1036,11 +1033,11 @@ def depart_collapse_node(self, node):
depart_collapse_node_rst(self, node)

def visit_issue(self, node):
self.add_text(':issue:`')
self.add_text('(issue *')
self.add_text(node['text'])

def depart_issue(self, node):
self.add_text('`')
self.add_text('*)')

def eval_expr(self, expr):
md = True
Expand Down

0 comments on commit 28c520c

Please sign in to comment.