[Python-modules-team] Bug#899415: zzzeeksphinx: Cherry-picked upstream patches required for zzzeeksphinx to work with sphinx >= 1.7.0

Corey Bryant corey.bryant at canonical.com
Wed May 23 23:23:24 BST 2018


Package: zzzeeksphinx
Version: 1.0.20-1
Severity: important
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu cosmic ubuntu-patch

Dear Maintainer,

In Ubuntu, the attached patch was applied to achieve the following:

  * d/p/sphinx-has-deprecated-Directive.patch,
    d/p/use-regular-python-tokenize.patch,
    d/p/remove-find-the-docstring.patch,
    d/p/more-updates-for-sphinx.patch: Cherry-picked patches from upstream
    to handled code removed from sphinx as of 1.7.0.


Thanks for considering the patch.


-- System Information:
Debian Release: buster/sid
  APT prefers cosmic
  APT policy: (500, 'cosmic'), (500, 'bionic-security')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.15.0-20-generic (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
-------------- next part --------------
diff -Nru zzzeeksphinx-1.0.20/debian/patches/more-updates-for-sphinx.patch zzzeeksphinx-1.0.20/debian/patches/more-updates-for-sphinx.patch
--- zzzeeksphinx-1.0.20/debian/patches/more-updates-for-sphinx.patch	1969-12-31 16:00:00.000000000 -0800
+++ zzzeeksphinx-1.0.20/debian/patches/more-updates-for-sphinx.patch	2018-05-23 10:36:34.000000000 -0700
@@ -0,0 +1,45 @@
+From d7a89f115fdb3ab1431161a446d636eaad3185c7 Mon Sep 17 00:00:00 2001
+From: Mike Bayer <mike_mp at zzzcomputing.com>
+Date: Fri, 16 Feb 2018 13:33:55 -0500
+Subject: [PATCH] - more updates for sphinx
+
+---
+ zzzeeksphinx/viewsource.py | 9 +++++----
+ 1 file changed, 5 insertions(+), 4 deletions(-)
+
+diff --git a/zzzeeksphinx/viewsource.py b/zzzeeksphinx/viewsource.py
+index 7ee590b..8b20c43 100644
+--- a/zzzeeksphinx/viewsource.py
++++ b/zzzeeksphinx/viewsource.py
+@@ -100,7 +100,7 @@ def _view_source_node(env, text, state):
+         code = analyzer.code
+ 
+     if state is not None:
+-        docstring = _find_mod_docstring(analyzer)
++        docstring = _find_mod_docstring(pathname)
+         if docstring:
+             # get rid of "foo.py" at the top
+             docstring = re.sub(r"^[a-zA-Z_0-9]+\.py", "", docstring)
+@@ -155,15 +155,16 @@ def _view_source_node(env, text, state):
+     return return_node
+ 
+ 
+-def _find_mod_docstring(analyzer):
++def _find_mod_docstring(pathname):
+     """attempt to locate the module-level docstring.
+ 
+     Note that sphinx autodoc just uses ``__doc__``.  But we don't want
+     to import the module, so we need to parse for it.
+ 
+     """
+-    analyzer.tokenize()
+-    for type_, parsed_line, start_pos, end_pos, raw_line in analyzer.tokens:
++    fhandle = open(pathname, 'rb')
++    for type_, parsed_line, start_pos, end_pos, raw_line in \
++            token.tokenize(fhandle.readline):
+         if type_ == token.COMMENT:
+             continue
+         elif type_ == token.STRING:
+-- 
+2.17.0
+
diff -Nru zzzeeksphinx-1.0.20/debian/patches/remove-find-the-docstring.patch zzzeeksphinx-1.0.20/debian/patches/remove-find-the-docstring.patch
--- zzzeeksphinx-1.0.20/debian/patches/remove-find-the-docstring.patch	1969-12-31 16:00:00.000000000 -0800
+++ zzzeeksphinx-1.0.20/debian/patches/remove-find-the-docstring.patch	2018-05-23 10:36:34.000000000 -0700
@@ -0,0 +1,113 @@
+From 0e2d505df24d4478030592d59c2abe07ccfc03cf Mon Sep 17 00:00:00 2001
+From: Mike Bayer <mike_mp at zzzcomputing.com>
+Date: Fri, 16 Feb 2018 16:40:33 -0500
+Subject: [PATCH] - remove the "find the docstring" aspect of this code that
+ doesn't seem to be doing anything and is breaking on old Pythons, new
+ sphinxes, too much.
+
+---
+ zzzeeksphinx/viewsource.py | 67 +++++++-------------------------------
+ 1 file changed, 11 insertions(+), 56 deletions(-)
+
+diff --git a/zzzeeksphinx/viewsource.py b/zzzeeksphinx/viewsource.py
+index 8b20c43..9fc6e2c 100644
+--- a/zzzeeksphinx/viewsource.py
++++ b/zzzeeksphinx/viewsource.py
+@@ -5,9 +5,7 @@ import imp
+ import re
+ from docutils.parsers.rst import Directive
+ import os
+-from docutils.statemachine import StringList
+ from sphinx.environment import NoUri
+-import tokenize as token
+ import warnings
+ from . import util
+ 
+@@ -99,20 +97,6 @@ def _view_source_node(env, text, state):
+     else:
+         code = analyzer.code
+ 
+-    if state is not None:
+-        docstring = _find_mod_docstring(pathname)
+-        if docstring:
+-            # get rid of "foo.py" at the top
+-            docstring = re.sub(r"^[a-zA-Z_0-9]+\.py", "", docstring)
+-
+-            # strip
+-            docstring = docstring.strip()
+-
+-            # yank only first paragraph
+-            docstring = docstring.split("\n\n")[0].strip()
+-    else:
+-        docstring = None
+-
+     pagename = '_modules/' + modname.replace('.', '/')
+     try:
+         refuri = urito(env.docname, pagename)
+@@ -127,52 +111,23 @@ def _view_source_node(env, text, state):
+         entry = code, analyzer.tags, {}
+     env._viewcode_modules[modname] = entry
+ 
+-    if docstring:
+-        # embed the ref with the doc text so that it isn't
+-        # a separate paragraph
+-        if refuri:
+-            docstring = "`%s <%s>`_ - %s" % (text, refuri, docstring)
+-        else:
+-            docstring = "``%s`` - %s" % (text, docstring)
+-        para = nodes.paragraph('', '')
+-        state.nested_parse(StringList([docstring]), 0, para)
+-        return_node = para
++    if refuri:
++        refnode = nodes.reference(
++            '', '',
++            nodes.Text(text, text),
++            refuri=urito(env.docname, pagename)
++        )
+     else:
+-        if refuri:
+-            refnode = nodes.reference(
+-                '', '',
+-                nodes.Text(text, text),
+-                refuri=urito(env.docname, pagename)
+-            )
+-        else:
+-            refnode = nodes.Text(text, text)
++        refnode = nodes.Text(text, text)
+ 
+-        if state:
+-            return_node = nodes.paragraph('', '', refnode)
+-        else:
+-            return_node = refnode
++    if state:
++        return_node = nodes.paragraph('', '', refnode)
++    else:
++        return_node = refnode
+ 
+     return return_node
+ 
+ 
+-def _find_mod_docstring(pathname):
+-    """attempt to locate the module-level docstring.
+-
+-    Note that sphinx autodoc just uses ``__doc__``.  But we don't want
+-    to import the module, so we need to parse for it.
+-
+-    """
+-    fhandle = open(pathname, 'rb')
+-    for type_, parsed_line, start_pos, end_pos, raw_line in \
+-            token.tokenize(fhandle.readline):
+-        if type_ == token.COMMENT:
+-            continue
+-        elif type_ == token.STRING:
+-            return eval(parsed_line)
+-        else:
+-            return None
+-
+-
+ def _parse_content(content):
+     d = {}
+     d['text'] = []
+-- 
+2.17.0
+
diff -Nru zzzeeksphinx-1.0.20/debian/patches/series zzzeeksphinx-1.0.20/debian/patches/series
--- zzzeeksphinx-1.0.20/debian/patches/series	1969-12-31 16:00:00.000000000 -0800
+++ zzzeeksphinx-1.0.20/debian/patches/series	2018-05-23 10:36:34.000000000 -0700
@@ -0,0 +1,4 @@
+sphinx-has-deprecated-Directive.patch
+use-regular-python-tokenize.patch
+more-updates-for-sphinx.patch
+remove-find-the-docstring.patch
diff -Nru zzzeeksphinx-1.0.20/debian/patches/sphinx-has-deprecated-Directive.patch zzzeeksphinx-1.0.20/debian/patches/sphinx-has-deprecated-Directive.patch
--- zzzeeksphinx-1.0.20/debian/patches/sphinx-has-deprecated-Directive.patch	1969-12-31 16:00:00.000000000 -0800
+++ zzzeeksphinx-1.0.20/debian/patches/sphinx-has-deprecated-Directive.patch	2018-05-23 10:36:34.000000000 -0700
@@ -0,0 +1,37 @@
+From 921f03f424eb1450ab87b3f43eae0b1b4dc8f558 Mon Sep 17 00:00:00 2001
+From: Mike Bayer <mike_mp at zzzcomputing.com>
+Date: Fri, 21 Jul 2017 13:31:28 -0400
+Subject: [PATCH] - sphinx has deprecated Directive
+
+---
+ zzzeeksphinx/dialect_info.py | 2 +-
+ zzzeeksphinx/viewsource.py   | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/zzzeeksphinx/dialect_info.py b/zzzeeksphinx/dialect_info.py
+index ce5f316..e66219f 100644
+--- a/zzzeeksphinx/dialect_info.py
++++ b/zzzeeksphinx/dialect_info.py
+@@ -1,5 +1,5 @@
+ import re
+-from sphinx.util.compat import Directive
++from docutils.parsers.rst import Directive
+ from docutils import nodes
+ 
+ 
+diff --git a/zzzeeksphinx/viewsource.py b/zzzeeksphinx/viewsource.py
+index d510582..5762d85 100644
+--- a/zzzeeksphinx/viewsource.py
++++ b/zzzeeksphinx/viewsource.py
+@@ -3,7 +3,7 @@ from sphinx.ext.viewcode import collect_pages
+ from sphinx.pycode import ModuleAnalyzer
+ import imp
+ import re
+-from sphinx.util.compat import Directive
++from docutils.parsers.rst import Directive
+ import os
+ from docutils.statemachine import StringList
+ from sphinx.environment import NoUri
+-- 
+2.17.0
+
diff -Nru zzzeeksphinx-1.0.20/debian/patches/use-regular-python-tokenize.patch zzzeeksphinx-1.0.20/debian/patches/use-regular-python-tokenize.patch
--- zzzeeksphinx-1.0.20/debian/patches/use-regular-python-tokenize.patch	1969-12-31 16:00:00.000000000 -0800
+++ zzzeeksphinx-1.0.20/debian/patches/use-regular-python-tokenize.patch	2018-05-23 10:36:34.000000000 -0700
@@ -0,0 +1,26 @@
+From cc521ca5f41af1cb396f0d00c2a7af11f5992d6a Mon Sep 17 00:00:00 2001
+From: Mike Bayer <mike_mp at zzzcomputing.com>
+Date: Fri, 16 Feb 2018 12:18:08 -0500
+Subject: [PATCH] - use regular python tokenize here as that is where sphinx
+ was getting it
+
+---
+ zzzeeksphinx/viewsource.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/zzzeeksphinx/viewsource.py b/zzzeeksphinx/viewsource.py
+index 5762d85..7ee590b 100644
+--- a/zzzeeksphinx/viewsource.py
++++ b/zzzeeksphinx/viewsource.py
+@@ -7,7 +7,7 @@ from docutils.parsers.rst import Directive
+ import os
+ from docutils.statemachine import StringList
+ from sphinx.environment import NoUri
+-from sphinx.pycode.pgen2 import token
++import tokenize as token
+ import warnings
+ from . import util
+ 
+-- 
+2.17.0
+


More information about the Python-modules-team mailing list