[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#850664: RFS: python-pynzb/0.1.0-3



Hi Gianfranco,

Thanks for your comments!


what about calling 2to3 in setup.py?

I somehow overlooked that this was possible. That's much more sensible than what I was doing.


and you can patch the code with a retro-compatible code
if you can't find a way that works with both python2 and 3, there is the version_info
variable that can help you in understanding what is the current interpreter

Ok, I've added a patch to do it the sys.version_info way since there doesn't seem to be a more elegant option.


I'm mostly sure upstream would appreciate a porting/retrocompatible patch :)

I hope so!


I've uploaded a new version which removes the d/rules hacks and implements proper patches (to be forwarded upstream at a later date). New diff from the same base is below.

Cheers,
Carl


$ git diff 281489c

diff --git a/debian/.git-dpm b/debian/.git-dpm
index b634411..f93cbbb 100644
--- a/debian/.git-dpm
+++ b/debian/.git-dpm
@@ -1,6 +1,6 @@
 # see git-dpm(1) from git-dpm package
-0a5a3e9b44be1ec1a150c027a07754a53f039189
-0a5a3e9b44be1ec1a150c027a07754a53f039189
+591e67b26a2d694d5aae2d77985eab4d8daf2d9e
+591e67b26a2d694d5aae2d77985eab4d8daf2d9e
 124074ce42e5d83c71e028a8757afb392cc96548
 124074ce42e5d83c71e028a8757afb392cc96548
 python-pynzb_0.1.0.orig.tar.gz
diff --git a/debian/changelog b/debian/changelog
index c9a8606..2895253 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,27 +2,33 @@ python-pynzb (0.1.0-3) unstable; urgency=medium

   * Add myself to uploaders.
   * Switch to pybuild and dh-python.
-  * Bump d/compat to 10.
+  * Bump d/compat to 10 and update version of B-D on debhelper.
   * Bump standards-version to 3.9.8 (no changes).
-  * d/copyright: add myself and fix license short names
-    - "public domain" -> public-domain
+  * d/copyright: add myself and fix license short names:
+    - "public domain" -> public-domain,
     - BSD -> BSD-3-clause.
   * Change Vcs to DPMT git repository and use https.
-  * Change Homepage to GitHub.
-  * Build the Python 3 module and drop the Python 2 module (no rdeps).
-  * Run the test suite with pytest.
-  * Call 2to3 during auto build.
-  * 0001-set-message_id-properly-in-expat-parser.patch: fix an upstream code.
-    This change allows the tests to pass for Python 2.
+  * Change Homepage to Github.
+  * Build the Python 3 module.
+    - replace B-D: python{,3}-setuptools and python{,3}-all
+  * Drop the Python 2 module (no rdeps):
+  * Run the test suite with pytest:
+    - cleanup the produced .cache/ in d/clean,
+    - add B-D on python3-pytest.
+  * 0001-set-message_id-properly-in-expat-parser.patch: fix an upstream code
+    typo. This change allows the tests to pass for Python 2.
+  * 0002-enable-use_2to3-in-setup.py.patch: enable 2to3 invocation in setup.py.
   * Move lxml to Suggests rather than Depends since there are fallbacks using
     standard library XML parsers.
   * Build-Depend on lxml in order to run the test for the implementation of the
     NZB parser using lxml (LXMLNZBParser).
-  * For Python 3, add a command to PYBUILD_AFTTER_BUILD_python3 in d/rules to
-    change the code to decode strings -> bytes as utf-8 for lxml's benefit.
-  * Fix watch file.
+  * 0003-give-lxml-etree-BytesIO-in-Python-3.patch: make the code Python 3
+    compatible by decoding strings -> bytes as UTF-8 and substituting BytesIO
+    for StringIO. This only affects the LXMLNZPParser.
+  * Fix watch file and declare version 4 format.
+  * Cleanup .egg-info files in d/clean and d/source/options.

- -- Carl Suster <carl@contraflo.ws>  Tue, 10 Jan 2017 15:49:05 +1100
+ -- Carl Suster <carl@contraflo.ws>  Wed, 11 Jan 2017 23:24:01 +1100

 python-pynzb (0.1.0-2) unstable; urgency=low

diff --git a/debian/patches/0002-enable-use_2to3-in-setup.py.patch b/debian/patches/0002-enable-use_2to3-in-setup.py.patch
new file mode 100644
index 0000000..16f2a85
--- /dev/null
+++ b/debian/patches/0002-enable-use_2to3-in-setup.py.patch
@@ -0,0 +1,21 @@
+From 01027917584eafdf4228bf0590123dfd47fe14a8 Mon Sep 17 00:00:00 2001
+From: Carl Suster <carl@contraflo.ws>
+Date: Wed, 11 Jan 2017 22:23:32 +1100
+Subject: enable use_2to3 in setup.py
+
+---
+ setup.py | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/setup.py b/setup.py
+index 0fd9d51..62f1ff3 100644
+--- a/setup.py
++++ b/setup.py
+@@ -168,4 +168,5 @@ setup(
+     include_package_data=True,
+     zip_safe=False,
+     install_requires=['setuptools'],
+-)
+\ No newline at end of file
++    use_2to3=True,
++)
diff --git a/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch b/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch
new file mode 100644
index 0000000..aac136f
--- /dev/null
+++ b/debian/patches/0003-give-lxml-etree-BytesIO-in-Python-3.patch
@@ -0,0 +1,40 @@
+From 591e67b26a2d694d5aae2d77985eab4d8daf2d9e Mon Sep 17 00:00:00 2001
+From: Carl Suster <carl@contraflo.ws>
+Date: Wed, 11 Jan 2017 22:34:34 +1100
+Subject: give lxml etree BytesIO in Python 3
+
+The lxml etree API changed in Python 3 to take BytesIO instead of
+StringIO. This patch maintains the original behaviour in Python 2 but
+switches to BytesIO in Python 3, decoding the XML data as UTF-8.
+---
+ pynzb/lxml_nzb.py | 16 +++++++++++-----
+ 1 file changed, 11 insertions(+), 5 deletions(-)
+
+diff --git a/pynzb/lxml_nzb.py b/pynzb/lxml_nzb.py
+index 790671d..e74ba34 100644
+--- a/pynzb/lxml_nzb.py
++++ b/pynzb/lxml_nzb.py
+@@ -6,11 +6,17 @@ except ImportError:
+     raise ImportError("You must have lxml installed before you can use the " +
+         "lxml NZB parser.")
+
+-try:
+-    from cStringIO import StringIO
+-except ImportError:
+-    from StringIO import StringIO
++import sys
++if sys.version_info.major < 3:
++    try:
++        from cStringIO import StringIO
++    except ImportError:
++        from StringIO import StringIO
++    def as_io(xml): return StringIO(xml)
++else:
++    from io import BytesIO
++    def as_io(xml): return BytesIO(bytes(xml, 'utf-8'))
+
+ class LXMLNZBParser(BaseETreeNZBParser):
+     def get_etree_iter(self, xml, et=etree):
+-        return iter(et.iterparse(StringIO(xml), events=("start", "end")))
+\ No newline at end of file
++        return iter(et.iterparse(as_io(xml), events=("start", "end")))
diff --git a/debian/patches/series b/debian/patches/series
index 6e8e20b..37dcf18 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,3 @@
 0001-set-message_id-properly-in-expat-parser.patch
+0002-enable-use_2to3-in-setup.py.patch
+0003-give-lxml-etree-BytesIO-in-Python-3.patch
diff --git a/debian/rules b/debian/rules
index e7aefc0..dee803d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -4,11 +4,6 @@
 export PYBUILD_NAME=pynzb

 export PYBUILD_TEST_ARGS=pynzb/tests.py
-# lxml expects a bytes object in Python 3 so we simply decode the string as
-# utf-8 for the Python 3 build. If this turns out to be problematic, we can
-# instead disable lxml support for the Python 3 build in pynzb/__init__.py and
-# rely on the standard library fallbacks for XML parsing.
-export PYBUILD_AFTER_BUILD_python3=2to3 -n -w {build_dir}/pynzb/; sed -i -e 's/StringIO/BytesIO/g' -e 's/BytesIO(xml)/BytesIO(bytes(xml,"utf-8"))/' {build_dir}/pynzb/lxml_nzb.py


 %:
diff --git a/pynzb/lxml_nzb.py b/pynzb/lxml_nzb.py
index 790671d..e74ba34 100644
--- a/pynzb/lxml_nzb.py
+++ b/pynzb/lxml_nzb.py
@@ -6,11 +6,17 @@ except ImportError:
     raise ImportError("You must have lxml installed before you can use the " +
         "lxml NZB parser.")

-try:
-    from cStringIO import StringIO
-except ImportError:
-    from StringIO import StringIO
+import sys
+if sys.version_info.major < 3:
+    try:
+        from cStringIO import StringIO
+    except ImportError:
+        from StringIO import StringIO
+    def as_io(xml): return StringIO(xml)
+else:
+    from io import BytesIO
+    def as_io(xml): return BytesIO(bytes(xml, 'utf-8'))

 class LXMLNZBParser(BaseETreeNZBParser):
     def get_etree_iter(self, xml, et=etree):
-        return iter(et.iterparse(StringIO(xml), events=("start", "end")))
\ No newline at end of file
+        return iter(et.iterparse(as_io(xml), events=("start", "end")))
diff --git a/setup.py b/setup.py
index 0fd9d51..62f1ff3 100644
--- a/setup.py
+++ b/setup.py
@@ -168,4 +168,5 @@ setup(
     include_package_data=True,
     zip_safe=False,
     install_requires=['setuptools'],
-)
\ No newline at end of file
+    use_2to3=True,
+)


Reply to: