From 5219663cf6fb6dfd92efcf57360ddd2cd4c9f204 Mon Sep 17 00:00:00 2001 From: Pavel Šimerda Date: Nov 10 2016 11:24:47 +0000 Subject: [PATCH 1/3] python3: fix configparser usage Trivial change that makes use of `six.moves` import already present in the codebase. Related: https://pagure.io/rpkg/issue/45 Signed-off-by: Pavel Šimerda --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 2ee6a02..fc4ca22 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -25,8 +25,6 @@ import six import sys import tempfile -from ConfigParser import ConfigParser - import gssapi from osbs.api import OSBS @@ -2548,7 +2546,7 @@ class Commands(object): def container_build_setup(self, get_autorebuild=None, set_autorebuild=None): - cfp = ConfigParser.SafeConfigParser() + cfp = configparser.SafeConfigParser() if os.path.exists(self.osbs_config_filename): cfp.read(self.osbs_config_filename) From e0951d90c064d26aa92ea9cc355fdc43b289a7d0 Mon Sep 17 00:00:00 2001 From: Pavel Šimerda Date: Nov 10 2016 11:25:39 +0000 Subject: [PATCH 2/3] python3: fix string types Fix text/binary string issues in pyrpkg. Could not execute verrel: endswith first arg must be bytes or a tuple of bytes, not str Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1295, in verrel print('%s-%s-%s' % (self.cmd.module_name, self.cmd.ver, File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 526, in module_name self.load_module_name() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 545, in load_module_name if module_name.endswith('.git'): TypeError: endswith first arg must be bytes or a tuple of bytes, not str Could not execute verrel: 'str' does not support the buffer interface Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1295, in verrel print('%s-%s-%s' % (self.cmd.module_name, self.cmd.ver, File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 808, in ver self.load_nameverrel() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 624, in load_nameverrel cmd.extend(self.rpmdefines) File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 687, in rpmdefines self.load_rpmdefines() File "/usr/lib64/python3.4/site-packages/fedpkg/__init__.py", line 167, in load_rpmdefines self.mockconfig = 'fedora-rawhide-%s' % self.localarch File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 493, in localarch self.load_localarch() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 501, in load_localarch self._localarch = proc.communicate()[0].strip('\n') TypeError: 'str' does not support the buffer interface Could not execute verrel: endswith first arg must be str or a tuple of str, not bytes Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1295, in verrel print('%s-%s-%s' % (self.cmd.module_name, self.cmd.ver, File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 526, in module_name self.load_module_name() File "/usr/lib64/python3.4/site-packages/pyrpkg/__init__.py", line 545, in load_module_name if module_name.endswith(b'.git'): TypeError: endswith first arg must be str or a tuple of str, not bytes Related: https://pagure.io/rpkg/issue/45 Signed-off-by: Pavel Šimerda --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index fc4ca22..57fb0a7 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -407,9 +407,9 @@ class Commands(object): raise rpkgError('Unable to find remote push url: %s' % e) if isinstance(url, six.text_type): # GitPython >= 1.0 return unicode. It must be encoded to string. - self._push_url = url.encode('utf-8') - else: self._push_url = url + else: + self._push_url = url.decode('utf-8') @property def commithash(self): @@ -490,7 +490,8 @@ class Commands(object): """Get the local arch as defined by rpm""" proc = subprocess.Popen(['rpm --eval %{_arch}'], shell=True, - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, + universal_newlines=True) self._localarch = proc.communicate()[0].strip('\n') @property @@ -534,8 +535,8 @@ class Commands(object): # self._module_name = "/".join(parts.path.split("/")[-2:]) module_name = posixpath.basename(parts.path) - if module_name.endswith(b'.git'): - module_name = module_name[:-len(b'.git')] + if module_name.endswith('.git'): + module_name = module_name[:-len('.git')] self._module_name = module_name return except rpkgError: diff --git a/tests/commands/test_package_name.py b/tests/commands/test_package_name.py index 23cdb69..69cf45a 100644 --- a/tests/commands/test_package_name.py +++ b/tests/commands/test_package_name.py @@ -20,7 +20,5 @@ class CommandPackageNameTestCase(CommandTestCase): moduledir = os.path.join(self.path, self.module) cmd.path = moduledir - # pycurl can't handle unicode variable - # module_name needs to be a byte string - self.assertNotEqual(type(cmd.module_name), six.text_type) - self.assertEqual(type(cmd.module_name), six.binary_type) + self.assertNotEqual(type(cmd.module_name), six.binary_type) + self.assertEqual(type(cmd.module_name), six.text_type) From cc92c639c8577234b8699452066683b669d5506c Mon Sep 17 00:00:00 2001 From: Pavel Šimerda Date: Nov 10 2016 11:25:39 +0000 Subject: [PATCH 3/3] python3: fix container usage Copy dictionary items into a list to avoid RuntimeError. Traceback: Could not execute build: dictionary changed size during iteration Traceback (most recent call last): File "/usr/lib/python-exec/python3.4/fedpkg", line 16, in main() File "/usr/lib64/python3.4/site-packages/fedpkg/__main__.py", line 78, in main sys.exit(client.args.command()) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 963, in build return self._watch_koji_tasks(self.cmd.kojisession, [task_id]) File "/usr/lib64/python3.4/site-packages/pyrpkg/cli.py", line 1351, in _watch_koji_tasks for task_id, task in tasks.items(): RuntimeError: dictionary changed size during iteration Related: https://pagure.io/rpkg/issue/45 Signed-off-by: Pavel Šimerda --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index fa89303..246c4a4 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1403,7 +1403,7 @@ see API KEY section of copr-cli(1) man page. quiet=self.args.q) while True: all_done = True - for task_id, task in tasks.items(): + for task_id, task in list(tasks.items()): changed = task.update() if not task.is_done(): all_done = False