Gentoo Archives: gentoo-commits

From: Andrew Ammerlaan <andrewammerlaan@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: dev-python/nbconvert/files/
Date: Tue, 08 Nov 2022 08:52:55
Message-Id: 1667897559.5cc1b10a626073823136d7ebf6a0aa760ea6bdcd.andrewammerlaan@gentoo
1 commit: 5cc1b10a626073823136d7ebf6a0aa760ea6bdcd
2 Author: Michael Mair-Keimberger <mmk <AT> levelnine <DOT> at>
3 AuthorDate: Tue Nov 8 06:20:14 2022 +0000
4 Commit: Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org>
5 CommitDate: Tue Nov 8 08:52:39 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5cc1b10a
7
8 dev-python/nbconvert: remove unused patch(es)
9
10 Signed-off-by: Michael Mair-Keimberger <mmk <AT> levelnine.at>
11 Closes: https://github.com/gentoo/gentoo/pull/28183
12 Signed-off-by: Andrew Ammerlaan <andrewammerlaan <AT> gentoo.org>
13
14 .../files/nbconvert-6.5.0-mistune-2.patch | 339 ---------------------
15 1 file changed, 339 deletions(-)
16
17 diff --git a/dev-python/nbconvert/files/nbconvert-6.5.0-mistune-2.patch b/dev-python/nbconvert/files/nbconvert-6.5.0-mistune-2.patch
18 deleted file mode 100644
19 index 4a3f4731b32d..000000000000
20 --- a/dev-python/nbconvert/files/nbconvert-6.5.0-mistune-2.patch
21 +++ /dev/null
22 @@ -1,339 +0,0 @@
23 -From 6e5ba41803cc8c3192f001b3ede9b74454220bda Mon Sep 17 00:00:00 2001
24 -From: Tiago de Paula <tiagodepalves@×××××.com>
25 -Date: Mon, 9 May 2022 09:39:31 -0300
26 -Subject: [PATCH] Update to Mistune 2.0.2 (#1764)
27 -
28 -Co-authored-by: Steven Silvester <steven.silvester@××××.org>
29 ----
30 - nbconvert/filters/markdown_mistune.py | 212 ++++++++++++++------------
31 - setup.py | 2 +-
32 - 2 files changed, 119 insertions(+), 95 deletions(-)
33 -
34 -diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py
35 -index 382a5388..636e1e8c 100644
36 ---- a/nbconvert/filters/markdown_mistune.py
37 -+++ b/nbconvert/filters/markdown_mistune.py
38 -@@ -21,7 +21,7 @@ except ImportError:
39 - from cgi import escape as html_escape
40 -
41 - import bs4
42 --import mistune
43 -+from mistune import BlockParser, HTMLRenderer, InlineParser, Markdown
44 - from pygments import highlight
45 - from pygments.formatters import HtmlFormatter
46 - from pygments.lexers import get_lexer_by_name
47 -@@ -34,158 +34,183 @@ class InvalidNotebook(Exception):
48 - pass
49 -
50 -
51 --class MathBlockGrammar(mistune.BlockGrammar):
52 -- """This defines a single regex comprised of the different patterns that
53 -- identify math content spanning multiple lines. These are used by the
54 -- MathBlockLexer.
55 -+class MathBlockParser(BlockParser):
56 -+ """This acts as a pass-through to the MathInlineParser. It is needed in
57 -+ order to avoid other block level rules splitting math sections apart.
58 - """
59 -
60 -- multi_math_str = "|".join(
61 -- [r"^\$\$.*?\$\$", r"^\\\\\[.*?\\\\\]", r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}"]
62 -+ MULTILINE_MATH = re.compile(
63 -+ r"(?<!\\)[$]{2}.*?(?<!\\)[$]{2}|"
64 -+ r"\\\\\[.*?\\\\\]|"
65 -+ r"\\begin\{([a-z]*\*?)\}.*?\\end\{\1\}",
66 -+ re.DOTALL,
67 - )
68 -- multiline_math = re.compile(multi_math_str, re.DOTALL)
69 -
70 -+ RULE_NAMES = ("multiline_math",) + BlockParser.RULE_NAMES
71 -
72 --class MathBlockLexer(mistune.BlockLexer):
73 -- """This acts as a pass-through to the MathInlineLexer. It is needed in
74 -- order to avoid other block level rules splitting math sections apart.
75 -- """
76 -+ # Regex for header that doesn't require space after '#'
77 -+ AXT_HEADING = re.compile(r" {0,3}(#{1,6})(?!#+)\s*([^\n]*?)$")
78 -
79 -- default_rules = ["multiline_math"] + mistune.BlockLexer.default_rules
80 -+ def parse_multiline_math(self, m, state):
81 -+ """Pass token through mutiline math."""
82 -+ return {"type": "multiline_math", "text": m.group(0)}
83 -
84 -- def __init__(self, rules=None, **kwargs):
85 -- if rules is None:
86 -- rules = MathBlockGrammar()
87 -- super().__init__(rules, **kwargs)
88 -
89 -- def parse_multiline_math(self, m):
90 -- """Add token to pass through mutiline math."""
91 -- self.tokens.append({"type": "multiline_math", "text": m.group(0)})
92 -+def _dotall(pattern):
93 -+ """Make the '.' special character match any character inside the pattern, including a newline.
94 -
95 --
96 --class MathInlineGrammar(mistune.InlineGrammar):
97 -- """This defines different ways of declaring math objects that should be
98 -- passed through to mathjax unaffected. These are used by the MathInlineLexer.
99 -+ This is implemented with the inline flag `(?s:...)` and is equivalent to using `re.DOTALL` when
100 -+ it is the only pattern used. It is necessary since `mistune>=2.0.0`, where the pattern is passed
101 -+ to the undocumented `re.Scanner`.
102 - """
103 --
104 -- inline_math = re.compile(r"^\$(.+?)\$|^\\\\\((.+?)\\\\\)", re.DOTALL)
105 -- block_math = re.compile(r"^\$\$(.*?)\$\$|^\\\\\[(.*?)\\\\\]", re.DOTALL)
106 -- latex_environment = re.compile(r"^\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}", re.DOTALL)
107 -- text = re.compile(r"^[\s\S]+?(?=[\\<!\[_*`~$]|https?://| {2,}\n|$)")
108 -+ return f"(?s:{pattern})"
109 -
110 -
111 --class MathInlineLexer(mistune.InlineLexer):
112 -- r"""This interprets the content of LaTeX style math objects using the rules
113 -- defined by the MathInlineGrammar.
114 -+class MathInlineParser(InlineParser):
115 -+ r"""This interprets the content of LaTeX style math objects.
116 -
117 - In particular this grabs ``$$...$$``, ``\\[...\\]``, ``\\(...\\)``, ``$...$``,
118 - and ``\begin{foo}...\end{foo}`` styles for declaring mathematics. It strips
119 - delimiters from all these varieties, and extracts the type of environment
120 - in the last case (``foo`` in this example).
121 - """
122 -- default_rules = [
123 -- "block_math",
124 -- "inline_math",
125 -+ BLOCK_MATH_TEX = _dotall(r"(?<!\\)\$\$(.*?)(?<!\\)\$\$")
126 -+ BLOCK_MATH_LATEX = _dotall(r"(?<!\\)\\\\\[(.*?)(?<!\\)\\\\\]")
127 -+ INLINE_MATH_TEX = _dotall(r"(?<![$\\])\$(.+?)(?<![$\\])\$")
128 -+ INLINE_MATH_LATEX = _dotall(r"(?<!\\)\\\\\((.*?)(?<!\\)\\\\\)")
129 -+ LATEX_ENVIRONMENT = _dotall(r"\\begin\{([a-z]*\*?)\}(.*?)\\end\{\1\}")
130 -+
131 -+ # The order is important here
132 -+ RULE_NAMES = (
133 -+ "block_math_tex",
134 -+ "block_math_latex",
135 -+ "inline_math_tex",
136 -+ "inline_math_latex",
137 - "latex_environment",
138 -- ] + mistune.InlineLexer.default_rules
139 --
140 -- def __init__(self, renderer, rules=None, **kwargs):
141 -- if rules is None:
142 -- rules = MathInlineGrammar()
143 -- super().__init__(renderer, rules, **kwargs)
144 --
145 -- def output_inline_math(self, m):
146 -- return self.renderer.inline_math(m.group(1) or m.group(2))
147 --
148 -- def output_block_math(self, m):
149 -- return self.renderer.block_math(m.group(1) or m.group(2) or "")
150 --
151 -- def output_latex_environment(self, m):
152 -- return self.renderer.latex_environment(m.group(1), m.group(2))
153 --
154 --
155 --class MarkdownWithMath(mistune.Markdown):
156 -- def __init__(self, renderer, **kwargs):
157 -- if "inline" not in kwargs:
158 -- kwargs["inline"] = MathInlineLexer
159 -- if "block" not in kwargs:
160 -- kwargs["block"] = MathBlockLexer
161 -- super().__init__(renderer, **kwargs)
162 --
163 -- def output_multiline_math(self):
164 -- return self.inline(self.token["text"])
165 --
166 --
167 --class IPythonRenderer(mistune.Renderer):
168 -- def block_code(self, code, lang):
169 -- if lang:
170 -+ ) + InlineParser.RULE_NAMES
171 -+
172 -+ def parse_block_math_tex(self, m, state):
173 -+ # sometimes the Scanner keeps the final '$$', so we use the
174 -+ # full matched string and remove the math markers
175 -+ text = m.group(0)[2:-2]
176 -+ return "block_math", text
177 -+
178 -+ def parse_block_math_latex(self, m, state):
179 -+ text = m.group(1)
180 -+ return "block_math", text
181 -+
182 -+ def parse_inline_math_tex(self, m, state):
183 -+ text = m.group(1)
184 -+ return "inline_math", text
185 -+
186 -+ def parse_inline_math_latex(self, m, state):
187 -+ text = m.group(1)
188 -+ return "inline_math", text
189 -+
190 -+ def parse_latex_environment(self, m, state):
191 -+ name, text = m.group(1), m.group(2)
192 -+ return "latex_environment", name, text
193 -+
194 -+
195 -+class MarkdownWithMath(Markdown):
196 -+ def __init__(self, renderer, block=None, inline=None, plugins=None):
197 -+ if block is None:
198 -+ block = MathBlockParser()
199 -+ if inline is None:
200 -+ inline = MathInlineParser(renderer, hard_wrap=False)
201 -+ super().__init__(renderer, block, inline, plugins)
202 -+
203 -+ def render(self, s):
204 -+ """Compatibility method with `mistune==0.8.4`."""
205 -+ return self.parse(s)
206 -+
207 -+
208 -+class IPythonRenderer(HTMLRenderer):
209 -+ def __init__(
210 -+ self,
211 -+ escape=True,
212 -+ allow_harmful_protocols=True,
213 -+ embed_images=False,
214 -+ exclude_anchor_links=False,
215 -+ anchor_link_text="¶",
216 -+ path="",
217 -+ attachments=None,
218 -+ ):
219 -+ super().__init__(escape, allow_harmful_protocols)
220 -+ self.embed_images = embed_images
221 -+ self.exclude_anchor_links = exclude_anchor_links
222 -+ self.anchor_link_text = anchor_link_text
223 -+ self.path = path
224 -+ if attachments is not None:
225 -+ self.attachments = attachments
226 -+ else:
227 -+ self.attachments = {}
228 -+
229 -+ def block_code(self, code, info=None):
230 -+ if info:
231 - try:
232 -+ lang = info.strip().split(None, 1)[0]
233 - lexer = get_lexer_by_name(lang, stripall=True)
234 - except ClassNotFound:
235 - code = lang + "\n" + code
236 - lang = None
237 -
238 - if not lang:
239 -- return "\n<pre><code>%s</code></pre>\n" % mistune.escape(code)
240 -+ return super().block_code(code)
241 -
242 - formatter = HtmlFormatter()
243 - return highlight(code, lexer, formatter)
244 -
245 - def block_html(self, html):
246 -- embed_images = self.options.get("embed_images", False)
247 --
248 -- if embed_images:
249 -+ if self.embed_images:
250 - html = self._html_embed_images(html)
251 -
252 - return super().block_html(html)
253 -
254 - def inline_html(self, html):
255 -- embed_images = self.options.get("embed_images", False)
256 --
257 -- if embed_images:
258 -+ if self.embed_images:
259 - html = self._html_embed_images(html)
260 -
261 - return super().inline_html(html)
262 -
263 -- def header(self, text, level, raw=None):
264 -- html = super().header(text, level, raw=raw)
265 -- if self.options.get("exclude_anchor_links"):
266 -+ def heading(self, text, level):
267 -+ html = super().heading(text, level)
268 -+ if self.exclude_anchor_links:
269 - return html
270 -- anchor_link_text = self.options.get("anchor_link_text", "¶")
271 -- return add_anchor(html, anchor_link_text=anchor_link_text)
272 -+ return add_anchor(html, anchor_link_text=self.anchor_link_text)
273 -
274 - def escape_html(self, text):
275 - return html_escape(text)
276 -
277 -+ def multiline_math(self, text):
278 -+ return text
279 -+
280 - def block_math(self, text):
281 -- return "$$%s$$" % self.escape_html(text)
282 -+ return f"$${self.escape_html(text)}$$"
283 -
284 - def latex_environment(self, name, text):
285 -- name = self.escape_html(name)
286 -- text = self.escape_html(text)
287 -- return rf"\begin{{{name}}}{text}\end{{{name}}}"
288 -+ name, text = self.escape_html(name), self.escape_html(text)
289 -+ return f"\\begin{{{name}}}{text}\\end{{{name}}}"
290 -
291 - def inline_math(self, text):
292 -- return "$%s$" % self.escape_html(text)
293 -+ return f"${self.escape_html(text)}$"
294 -
295 -- def image(self, src, title, text):
296 -+ def image(self, src, text, title):
297 - """Rendering a image with title and text.
298 -
299 - :param src: source link of the image.
300 -- :param title: title text of the image.
301 - :param text: alt text of the image.
302 -+ :param title: title text of the image.
303 - """
304 -- attachments = self.options.get("attachments", {})
305 - attachment_prefix = "attachment:"
306 -- embed_images = self.options.get("embed_images", False)
307 -
308 - if src.startswith(attachment_prefix):
309 - name = src[len(attachment_prefix) :]
310 -
311 -- if name not in attachments:
312 -+ if name not in self.attachments:
313 - raise InvalidNotebook(f"missing attachment: {name}")
314 -
315 -- attachment = attachments[name]
316 -+ attachment = self.attachments[name]
317 - # we choose vector over raster, and lossless over lossy
318 - preferred_mime_types = ["image/svg+xml", "image/png", "image/jpeg"]
319 - for preferred_mime_type in preferred_mime_types:
320 -@@ -197,13 +222,13 @@ class IPythonRenderer(mistune.Renderer):
321 - data = attachment[mime_type]
322 - src = "data:" + mime_type + ";base64," + data
323 -
324 -- elif embed_images:
325 -+ elif self.embed_images:
326 - base64_url = self._src_to_base64(src)
327 -
328 - if base64_url is not None:
329 - src = base64_url
330 -
331 -- return super().image(src, title, text)
332 -+ return super().image(src, text, title)
333 -
334 - def _src_to_base64(self, src):
335 - """Turn the source file into a base64 url.
336 -@@ -211,8 +236,7 @@ class IPythonRenderer(mistune.Renderer):
337 - :param src: source link of the file.
338 - :return: the base64 url or None if the file was not found.
339 - """
340 -- path = self.options.get("path", "")
341 -- src_path = os.path.join(path, src)
342 -+ src_path = os.path.join(self.path, src)
343 -
344 - if not os.path.exists(src_path):
345 - return None
346 -diff --git a/setup.py b/setup.py
347 -index 7220a875..2dfa2534 100644
348 ---- a/setup.py
349 -+++ b/setup.py
350 -@@ -245,7 +245,7 @@ setup_args["install_requires"] = [
351 - "jupyter_core>=4.7",
352 - "jupyterlab_pygments",
353 - "MarkupSafe>=2.0",
354 -- "mistune>=0.8.1,<2",
355 -+ "mistune>=2.0.2",
356 - "nbclient>=0.5.0",
357 - "nbformat>=5.1",
358 - "packaging",
359 ---
360 -2.35.1
361 -