Quick wins for python3 support

Change-Id: I9b04543bd2fe9a3f52232040586041cb340a1133
This commit is contained in:
Tony Breeds 2016-09-29 16:21:32 +10:00
parent bf46becbcf
commit 4188b2900d
2 changed files with 10 additions and 8 deletions

View File

@ -66,7 +66,7 @@ def _freeze(requirements, python):
output = []
try:
version_out = subprocess.check_output(
[python, "--version"], stderr=subprocess.STDOUT)
[python, "--version"], stderr=subprocess.STDOUT).decode('utf-8')
output.append(version_out)
version_all = version_out.split()[1]
version = '.'.join(version_all.split('.')[:2])
@ -78,7 +78,8 @@ def _freeze(requirements, python):
[pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel']))
output.append(subprocess.check_output(
[pip_bin, 'install', '-r', requirements]))
freeze = subprocess.check_output([pip_bin, 'freeze'])
freeze = subprocess.check_output(
[pip_bin, 'freeze']).decode('utf-8')
output.append(freeze)
return (version, _parse_freeze(freeze))
except Exception as exc:
@ -116,7 +117,8 @@ def _combine_freezes(freezes, blacklist=None):
for package, versions in sorted(packages.items()):
if package.lower() in excludes:
continue
if len(versions) != 1 or versions.values()[0] != reference_versions:
if (len(versions) != 1 or
list(versions.values())[0] != reference_versions):
# markers
for version, py_versions in sorted(versions.items()):
# Once the ecosystem matures, we can consider using OR.
@ -126,7 +128,7 @@ def _combine_freezes(freezes, blacklist=None):
(package, version, py_version))
else:
# no markers
yield '%s===%s\n' % (package, versions.keys()[0])
yield '%s===%s\n' % (package, list(versions.keys())[0])
# -- untested UI glue from here down.

View File

@ -14,7 +14,7 @@
from __future__ import print_function
import StringIO
import six
import sys
import textwrap
@ -42,7 +42,7 @@ class SmokeTest(testtools.TestCase):
self.assertIn("jsonschema!=1.4.0,<2,>=1.0.0", global_reqs)
# And test the end to end call of update.py, UI and all.
self.project = self.useFixture(common.project_fixture)
capture = StringIO.StringIO()
capture = six.StringIO()
update.main(['--source', global_env.root, self.project.root], capture)
reqs = common._file_to_list(self.project.req_file)
# ensure various updates take
@ -151,7 +151,7 @@ class UpdateTest(testtools.TestCase):
actions = update._process_project(
common.project_project, common.global_reqs, None, None, None,
False)
capture = StringIO.StringIO()
capture = six.StringIO()
project.write(
common.project_project, actions, capture, False, True)
expected = ('Version change for: greenlet, SQLAlchemy, eventlet, PasteDeploy, routes, WebOb, wsgiref, boto, kombu, pycrypto, python-swiftclient, lxml, jsonschema, python-keystoneclient\n' # noqa
@ -183,7 +183,7 @@ Updated %(project)s/test-requirements.txt:
actions = update._process_project(
common.project_project, common.global_reqs, None, None, None,
False)
capture = StringIO.StringIO()
capture = six.StringIO()
project.write(
common.project_project, actions, capture, True, True)
expected = ("""Syncing %(project)s/requirements.txt