Merge "Revert "show commands and output together""

This commit is contained in:
Zuul 2018-04-21 04:22:05 +00:00 committed by Gerrit Code Review
commit 25fc00b8c4
1 changed files with 10 additions and 16 deletions

View File

@ -45,16 +45,6 @@ def _parse_freeze(text):
return result
def _do_cmd(cmd, return_output=False, **kwds):
print(' '.join(cmd))
if return_output:
out = subprocess.check_output(cmd, **kwds).decode('utf-8')
print(out)
return out
else:
subprocess.check_call(cmd)
def _freeze(requirements, python):
"""Generate a frozen install from requirements.
@ -77,16 +67,20 @@ def _freeze(requirements, python):
:param python: A Python binary to use. E.g. /usr/bin/python3
:return: A tuple (python_version, list of (package, version)'s)
"""
version_out = _do_cmd([python, "--version"], return_output=True,
stderr=subprocess.STDOUT)
version_out = subprocess.check_output(
[python, "--version"], stderr=subprocess.STDOUT).decode('utf-8')
version_all = version_out.split()[1]
version = '.'.join(version_all.split('.')[:2])
with fixtures.TempDir() as temp:
_do_cmd(['virtualenv', '-p', python, temp.path])
subprocess.check_call(
['virtualenv', '-p', python, temp.path])
pip_bin = os.path.join(temp.path, 'bin', 'pip')
_do_cmd([pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel'])
_do_cmd([pip_bin, 'install', '-r', requirements])
freeze = _do_cmd([pip_bin, 'freeze'], return_output=True)
subprocess.check_call(
[pip_bin, 'install', '-U', 'pip', 'setuptools', 'wheel'])
subprocess.check_call(
[pip_bin, 'install', '-r', requirements])
freeze = subprocess.check_output(
[pip_bin, 'freeze']).decode('utf-8')
return (version, _parse_freeze(freeze))