[Reproducible-commits] [diffoscope] 23/23: Switch to Python 3 XXX

Jérémy Bobbio lunar at moszumanska.debian.org
Sat Sep 19 23:18:22 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/py3
in repository diffoscope.

commit 0effabb3a0c9b64bff7bc5d64661d375407a133c
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Sun Sep 20 01:15:51 2015 +0200

    Switch to Python 3 XXX
---
 README                              |  2 +-
 bin/diffoscope                      |  2 +-
 debian/control                      | 20 +++++------
 debian/rules                        |  2 +-
 debian/tests/control                |  2 +-
 debian/tests/pytest                 |  2 +-
 diffoscope/__main__.py              |  6 ++--
 diffoscope/comparators/__init__.py  |  4 +--
 diffoscope/comparators/gettext.py   |  2 +-
 diffoscope/comparators/rpm.py       |  9 ++---
 diffoscope/comparators/tar.py       |  2 +-
 diffoscope/comparators/utils.py     |  6 ++--
 setup.py                            |  2 +-
 tests/data/rpm_header_expected_diff | 68 ++++++++++++++++++-------------------
 14 files changed, 65 insertions(+), 64 deletions(-)

diff --git a/README b/README
index f7e3e7c..3587c6c 100644
--- a/README
+++ b/README
@@ -32,7 +32,7 @@ This will compare `build1.changes` and `build2.changes` and create
 External dependencies
 ---------------------
 
-Required Python modules:
+diffoscope requires Python 3 and the following modules:
 
  * Available on PyPI: libarchive-c, python-debian.
  * Magic-file-extension is built from file:
diff --git a/bin/diffoscope b/bin/diffoscope
index 1ac89a8..2393807 100755
--- a/bin/diffoscope
+++ b/bin/diffoscope
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 #
 # diffoscope: in-depth comparison of files, archives, and directories
diff --git a/debian/control b/debian/control
index 2673149..08696db 100644
--- a/debian/control
+++ b/debian/control
@@ -7,18 +7,18 @@ Uploaders: Jérémy Bobbio <lunar at debian.org>,
  Holger Levsen <holger at debian.org>
 Build-Depends: debhelper (>= 9),
                dh-python,
-               python-all,
-               python-debian,
-               python-docutils,
-               python-libarchive-c,
-               python-magic,
-               python-pytest,
-               python-rpm,
-               python-setuptools,
-               python-tlsh,
+               python3-all,
+               python3-debian,
+               python3-docutils,
+               python3-libarchive-c,
+               python3-magic,
+               python3-pytest,
+               python3-rpm,
+               python3-setuptools,
+               python3-tlsh,
                rpm-common
 Standards-Version: 3.9.6
-X-Python-Version: >= 2.7
+X-Python-Version: >= 3
 Homepage: http://diffoscope.org/
 Vcs-Git: git://anonscm.debian.org/reproducible/diffoscope.git
 Vcs-Browser: https://anonscm.debian.org/cgit/reproducible/diffoscope.git
diff --git a/debian/rules b/debian/rules
index c868422..e7b5ed4 100755
--- a/debian/rules
+++ b/debian/rules
@@ -3,7 +3,7 @@
 VERSION = $(shell dpkg-parsechangelog --show-field Version)
 
 %:
-	dh $@ --with python2 --buildsystem=pybuild
+	dh $@ --with python3 --buildsystem=pybuild
 
 override_dh_auto_build:
 	@if ! grep -q 'VERSION = "$(VERSION)"' diffoscope/__init__.py; then \
diff --git a/debian/tests/control b/debian/tests/control
index ead0816..7819245 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1,3 +1,3 @@
 Tests: pytest
-Depends: diffoscope, python-pytest
+Depends: diffoscope, python3-pytest
 Restrictions: needs-recommends
diff --git a/debian/tests/pytest b/debian/tests/pytest
index 0c398a5..38b6eee 100755
--- a/debian/tests/pytest
+++ b/debian/tests/pytest
@@ -8,4 +8,4 @@ if ! [ -d "$ADTTMP" ]; then
 fi
 
 cp -r tests $ADTTMP
-(cd $ADTTMP; py.test)
+(cd $ADTTMP; py.test-3)
diff --git a/diffoscope/__main__.py b/diffoscope/__main__.py
index 6971c2f..bd7300e 100644
--- a/diffoscope/__main__.py
+++ b/diffoscope/__main__.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 #
 # diffoscope: in-depth comparison of files, archives, and directories
@@ -82,8 +82,8 @@ def create_parser():
 def make_printer(path):
     if path == '-':
         output = sys.stdout
-        if not sys.stdout.isatty():
-            output = codecs.getwriter(sys.stdin.encoding or 'utf-8')(sys.stdout)
+        if not sys.stdout.isatty() and hasattr(sys.stdout, 'buffer'):
+            output = codecs.getwriter(sys.stdin.encoding or 'utf-8')(sys.stdout.buffer)
     else:
         output = codecs.open(path, 'w', encoding='utf-8')
     def print_func(*args, **kwargs):
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 3a6d0d6..9f9f3a1 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -161,11 +161,11 @@ def perform_fuzzy_matching(members1, members2):
     # Perform local copies because they will be modified by consumer
     members1 = dict(members1)
     members2 = dict(members2)
-    for name1, file1 in members1.viewitems():
+    for name1, file1 in members1.items():
         if file1.is_directory() or not file1.fuzzy_hash:
             continue
         comparisons = []
-        for name2, file2 in members2.viewitems():
+        for name2, file2 in members2.items():
             if name2 in already_compared or file2.is_directory() or not file2.fuzzy_hash:
                 continue
             comparisons.append((tlsh.diff(file1.fuzzy_hash, file2.fuzzy_hash), name2))
diff --git a/diffoscope/comparators/gettext.py b/diffoscope/comparators/gettext.py
index 4e02dea..d5812d7 100644
--- a/diffoscope/comparators/gettext.py
+++ b/diffoscope/comparators/gettext.py
@@ -27,7 +27,7 @@ from diffoscope import logger
 
 
 class Msgunfmt(Command):
-    CHARSET_RE = re.compile(r'^"Content-Type: [^;]+; charset=([^\\]+)\\n"$')
+    CHARSET_RE = re.compile(rb'^"Content-Type: [^;]+; charset=([^\\]+)\\n"$')
 
     def __init__(self, *args, **kwargs):
         super(Msgunfmt, self).__init__(*args, **kwargs)
diff --git a/diffoscope/comparators/rpm.py b/diffoscope/comparators/rpm.py
index ddeab56..b68e9cb 100644
--- a/diffoscope/comparators/rpm.py
+++ b/diffoscope/comparators/rpm.py
@@ -19,6 +19,7 @@
 # along with diffoscope.  If not, see <http://www.gnu.org/licenses/>.
 
 from __future__ import absolute_import
+import binascii
 import os.path
 import subprocess
 import rpm
@@ -40,10 +41,10 @@ def get_rpm_header(path, ts):
             if rpmtag not in hdr:
                 continue
             # header fields can contain binary data
-            try:
-                value = str(hdr[rpmtag]).decode('utf-8')
-            except UnicodeDecodeError:
-                value = str(hdr[rpmtag]).encode('hex_codec')
+            if isinstance(hdr[rpmtag], bytes):
+                value = binascii.hexlify(hdr[rpmtag]).decode('us-ascii')
+            else:
+                value = str(hdr[rpmtag])
             header += "%s: %s\n" % (rpm.tagnames[rpmtag], value)
 
     return header
diff --git a/diffoscope/comparators/tar.py b/diffoscope/comparators/tar.py
index 6a79759..84a9509 100644
--- a/diffoscope/comparators/tar.py
+++ b/diffoscope/comparators/tar.py
@@ -105,7 +105,7 @@ class TarContainer(Archive):
     def extract(self, member_name, dest_dir):
         logger.debug('tar extracting %s to %s', member_name, dest_dir)
         self.archive.extract(member_name, dest_dir)
-        return os.path.join(dest_dir, member_name).decode('utf-8')
+        return os.path.join(dest_dir, member_name)
 
     def get_member(self, member_name):
         tarinfo = self.archive.getmember(member_name)
diff --git a/diffoscope/comparators/utils.py b/diffoscope/comparators/utils.py
index 6364abc..b9aec11 100644
--- a/diffoscope/comparators/utils.py
+++ b/diffoscope/comparators/utils.py
@@ -186,16 +186,16 @@ class Container(object):
     def comparisons(self, other):
         my_members = self.get_members()
         other_members = other.get_members()
-        for name in sorted(my_members.viewkeys() & other_members.viewkeys()):
+        for name in sorted(my_members.keys() & other_members.keys()):
             yield my_members.pop(name), other_members.pop(name), NO_COMMENT
         for my_name, other_name, score in diffoscope.comparators.perform_fuzzy_matching(my_members, other_members):
             comment = 'Files similar despite different names (difference score: %d)' % score
             yield my_members.pop(my_name), other_members.pop(other_name), comment
         if Config.general.new_file:
-            for my_name in my_members.viewkeys() - other_members.viewkeys():
+            for my_name in my_members.keys() - other_members.keys():
                 my_file = my_members[my_name]
                 yield my_file, NonExistingFile('/dev/null', my_file), NO_COMMENT
-            for other_name in other_members.viewkeys() - my_members.viewkeys():
+            for other_name in other_members.keys() - my_members.keys():
                 other_file = other_members[other_name]
                 yield NonExistingFile('/dev/null', other_file), other_file, NO_COMMENT
 
diff --git a/setup.py b/setup.py
index f21fcc0..a327e8d 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 
 import sys
 from setuptools import setup, find_packages
diff --git a/tests/data/rpm_header_expected_diff b/tests/data/rpm_header_expected_diff
index 01d5329..f4927bd 100644
--- a/tests/data/rpm_header_expected_diff
+++ b/tests/data/rpm_header_expected_diff
@@ -1,47 +1,47 @@
 @@ -1,36 +1,36 @@
 -HEADERIMMUTABLE: 00000030000001b00000003f00000007000001a00000001000000064000000080000000000000001000003e8000000060000000200000001000003e9000000060000000700000001000003ea000000060000000900000001000003ec000000090000000b00000001000003ed000000090000002700000001000003ee000000040000003400000001000003ef000000060000003800000001000003f1000000040000004000000001000003f6000000060000004400000001000003f8000000090000004b00000001000003fd000000060000005f00000001000003fe0000000600000065000000010000040400 [...]
 +HEADERIMMUTABLE: 00000030000001b00000003f00000007000001a00000001000000064000000080000000000000001000003e8000000060000000200000001000003e9000000060000000700000001000003ea000000060000000900000001000003ec000000090000000b00000001000003ed000000090000002700000001000003ee000000040000003400000001000003ef000000060000003800000001000003f1000000040000004000000001000003f6000000060000004400000001000003f8000000090000004b00000001000003fd000000060000005f00000001000003fe0000000600000065000000010000040400 [...]
- HEADERI18NTABLE: ['C']
+ HEADERI18NTABLE: [b'C']
 -SIGSIZE: 1583
 -SIGMD5: 06166011d2d66f8433d50b417358a31d
--SHA1HEADER: 331667229aa7e4d600f682e9cd0c6372b93b082a
+-SHA1HEADER: 33333136363732323961613765346436303066363832653963643063363337326239336230383261
 +SIGSIZE: 1722
 +SIGMD5: 746686e44fc68a5836e8043f722e436a
-+SHA1HEADER: 2780015bd7bd365949d05e29618fa833e62e4604
- NAME: test
- VERSION: 0
- RELEASE: 0
- SUMMARY: Test package for debbindiff
- DESCRIPTION: Test package
++SHA1HEADER: 32373830303135626437626433363539343964303565323936313866613833336536326534363034
+ NAME: 74657374
+ VERSION: 30
+ RELEASE: 30
+ SUMMARY: 54657374207061636b61676520666f722064656262696e64696666
+ DESCRIPTION: 54657374207061636b616765
 -BUILDTIME: 1435168523
 +BUILDTIME: 1435168561
- BUILDHOST: loar
+ BUILDHOST: 6c6f6172
 -SIZE: 446
 +SIZE: 671
- LICENSE: Public
- GROUP: Applications/System
- OS: linux
- ARCH: x86_64
--FILESIZES: [446L]
-+FILESIZES: [671L]
- FILEMODES: [33188L]
- FILERDEVS: [0L]
--FILEMTIMES: [1435168518L]
--FILEMD5S: ['7873b606429a70284d63f0674e6787bc']
-+FILEMTIMES: [1435168559L]
-+FILEMD5S: ['17866262a0c60d916e3cf3219724b2e7']
- FILELINKTOS: ['']
- FILEFLAGS: [0L]
- FILEUSERNAME: ['root']
- FILEGROUPNAME: ['root']
- SOURCERPM: test-0-0.src.rpm
- FILEVERIFYFLAGS: [4294967295L]
+ LICENSE: 5075626c6963
+ GROUP: 4170706c69636174696f6e732f53797374656d
+ OS: 6c696e7578
+ ARCH: 7838365f3634
+-FILESIZES: [446]
++FILESIZES: [671]
+ FILEMODES: [33188]
+ FILERDEVS: [0]
+-FILEMTIMES: [1435168518]
+-FILEMD5S: [b'7873b606429a70284d63f0674e6787bc']
++FILEMTIMES: [1435168559]
++FILEMD5S: [b'17866262a0c60d916e3cf3219724b2e7']
+ FILELINKTOS: [b'']
+ FILEFLAGS: [0]
+ FILEUSERNAME: [b'root']
+ FILEGROUPNAME: [b'root']
+ SOURCERPM: 746573742d302d302e7372632e72706d
+ FILEVERIFYFLAGS: [4294967295]
 -ARCHIVESIZE: 696
 +ARCHIVESIZE: 920
- PROVIDES: ['test', 'test(x86-64)']
- REQUIREFLAGS: [16777226L, 16777226L]
- REQUIRES: ['rpmlib(CompressedFileNames)', 'rpmlib(PayloadFilesHavePrefix)']
- REQUIREVERSION: ['3.0.4-1', '4.0-1']
- RPMVERSION: 4.12.0.1
- FILEDEVICES: [1L]
- FILEINODES: [1L]
+ PROVIDES: [b'test', b'test(x86-64)']
+ REQUIREFLAGS: [16777226, 16777226]
+ REQUIRES: [b'rpmlib(CompressedFileNames)', b'rpmlib(PayloadFilesHavePrefix)']
+ REQUIREVERSION: [b'3.0.4-1', b'4.0-1']
+ RPMVERSION: 342e31322e302e31
+ FILEDEVICES: [1]
+ FILEINODES: [1]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git



More information about the Reproducible-commits mailing list