#5 [DON'T MERGE YET] Add upstream patch for Python 3.8 compatibility
Closed a month ago by nonamedotc. Opened a month ago by churchyard.
rpms/ churchyard/python-nbconvert py38  into  master

@@ -0,0 +1,42 @@ 

+ From 1aa14e34ce5b7aa13ef7480216daa3f9a824766f Mon Sep 17 00:00:00 2001

+ From: Min RK <benjaminrk@gmail.com>

+ Date: Wed, 6 Mar 2019 15:13:59 +0100

+ Subject: [PATCH] address deprecation warning in cgi.escape

+ 

+ use html.escape when available

+ ---

+  nbconvert/filters/markdown_mistune.py | 13 +++++++------

+  1 file changed, 7 insertions(+), 6 deletions(-)

+ 

+ diff --git a/nbconvert/filters/markdown_mistune.py b/nbconvert/filters/markdown_mistune.py

+ index 8435e0ed..cfe4cd4f 100644

+ --- a/nbconvert/filters/markdown_mistune.py

+ +++ b/nbconvert/filters/markdown_mistune.py

+ @@ -9,7 +9,12 @@

+  from __future__ import print_function

+  

+  import re

+ -import cgi

+ +

+ +try:

+ +    from html import escape as html_escape

+ +except ImportError:

+ +    # Python 2

+ +    from cgi import escape as html_escape

+  

+  import mistune

+  

+ @@ -126,12 +131,8 @@ def header(self, text, level, raw=None):

+          anchor_link_text = self.options.get('anchor_link_text', u'¶')

+          return add_anchor(html, anchor_link_text=anchor_link_text)

+  

+ -    # We must be careful here for compatibility

+ -    # html.escape() is not availale on python 2.7

+ -    # For more details, see:

+ -    # https://wiki.python.org/moin/EscapingHtml

+      def escape_html(self, text):

+ -        return cgi.escape(text)

+ +        return html_escape(text)

+  

+      def block_math(self, text):

+          return '$$%s$$' % self.escape_html(text)

file modified
+7 -2

@@ -8,6 +8,10 @@ 

  License:        BSD and MIT

  URL:            http://jupyter.org

  Source0:        %pypi_source

+ 

+ # Python 3.8 compatibility

+ Patch1:         https://github.com/jupyter/nbconvert/commit/1aa14e34ce5b7aa13ef7480216daa3f9a824766f.patch

+ 

  BuildArch:      noarch

  

  BuildRequires:  python3-pandocfilters

@@ -72,7 +76,7 @@ 

  Documentation for nbconvert

  

  %prep

- %autosetup -n %{pypi_name}-%{version}

+ %autosetup -p1 -n %{pypi_name}-%{version}

  rm -rf %{pypi_name}.egg-info

  

  %build

@@ -99,7 +103,8 @@ 

  # test_minimal_version - our pandoc is too new

  # test_pandoc_available - our pandoc is too new

  # test_run_notebooks - slightly different output, probably a jupyter version mismatch

- %{__python3} -m pytest -v -k "not test_markdown2rst and not test_minimal_version and not test_pandoc_available and not test_run_notebooks"

+ # test_markdown2html_math - not compatible with Patch1

+ %{__python3} -m pytest -v -k "not test_markdown2rst and not test_minimal_version and not test_pandoc_available and not test_run_notebooks and not test_markdown2html_math"

  %endif

  

  %files -n python3-%{pypi_name}

https://bugzilla.redhat.com/show_bug.cgi?id=1702082

Since it breaks 1 test, only merge this if no fixed release is out before 3.8 happens.

I will watch for this. Thanks.

Of course, feel free to merge if you get to this before I do. 👍

I will push nbconvert 5.5 to rawhide later today. 5.5 already has this fixed.

This patch and the PR is no longer needed. Closing. Please comment/reopen as needed,

Pull-Request has been closed by nonamedotc

a month ago

5.5 is building now. Can you verify everything works as expected?

I got this now:

============================= test session starts ==============================
platform linux -- Python 3.8.0a3, pytest-4.4.1, py-1.8.0, pluggy-0.9.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /builddir/build/BUILD/nbconvert-5.5.0
collecting ... collected 248 items / 1 errors / 3 deselected / 244 selected

==================================== ERRORS ====================================
________ ERROR collecting nbconvert/preprocessors/tests/test_execute.py ________
ImportError while importing test module '/builddir/build/BUILD/nbconvert-5.5.0/nbconvert/preprocessors/tests/test_execute.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
nbconvert/preprocessors/tests/test_execute.py:26: in <module>
    from mock import MagicMock
E   ModuleNotFoundError: No module named 'mock'
=============================== warnings summary ===============================

You did too:

============================= test session starts ==============================
platform linux -- Python 3.7.3, pytest-4.4.1, py-1.8.0, pluggy-0.9.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /builddir/build/BUILD/nbconvert-5.5.0
collecting ... collected 248 items / 1 errors / 3 deselected / 244 selected
==================================== ERRORS ====================================
________ ERROR collecting nbconvert/preprocessors/tests/test_execute.py ________
ImportError while importing test module '/builddir/build/BUILD/nbconvert-5.5.0/nbconvert/preprocessors/tests/test_execute.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
nbconvert/preprocessors/tests/test_execute.py:26: in <module>
    from mock import MagicMock
E   ModuleNotFoundError: No module named 'mock'
=============================== warnings summary ===============================

Yeah the test failure when I got back. That was an easy fix. Just needed python3-mock.

The tests fail at another location though -

>                   raise CellExecutionError.from_cell_and_msg(cell, out)
E                   nbconvert.preprocessors.execute.CellExecutionError: An error occurred while executing the following cell:
E                   ------------------
E                   import ipywidgets
E                   label = ipywidgets.Label('Hello World')
E                   label
E                   ------------------
E                   
E                   ---------------------------------------------------------------------------
E                   ModuleNotFoundError                       Traceback (most recent call last)
E                   <ipython-input-1-bf282e52d5bc> in <module>
E                   ----> 1 import ipywidgets
E                         2 label = ipywidgets.Label('Hello World')
E                         3 label
E                   
E                   ModuleNotFoundError: No module named 'ipywidgets'
E                   ModuleNotFoundError: No module named 'ipywidgets'
nbconvert/preprocessors/execute.py:424: CellExecutionError

Here is the link to the mock build if you want to see the complete build log -

https://koji.fedoraproject.org/koji/taskinfo?taskID=34568085

I thought ipywidgets was provided by jupyter_core. Clearly not. I am not even sure if we have this in Fedora. :disappointed:

No, that is a standalone package:

https://pypi.org/project/ipywidgets/

$ dnf repoquery --repo=compose -l python3-jupyter-core | grep ipywidgets || echo nope
nope

May I suggest to first try a scratch build (or a PR) before pushing package update next time?

I'll check if ipywidgets is only used in the test.

May I suggest to first try a scratch build (or a PR) before pushing package update next time?

I usually do. I tested this on mock with tests disabled a couple of days ago and of course it built. I forgot that I tested without tests. :sad: