Don't use pip internals

As of pip10 pip is no longer promising external stable apis (they never
really did anyways just failed to annotate the source as such). As a
result our use of direct pip internals breaks under pip10.

We replace this with a fork and exec of pip instead as the command line
is a stable api. We were already doing this anyways so shouldn't cause
anything to run slower and should be more reliable as an api.

Note that we also remove the import of pip as this does an unexpected
thing and uses pip outside of the virtualenv rather than pip inside the
virtualenv. Since we are only forking pip inside the virtualenv now we
don't need to check for external pip.

Change-Id: Ib2628003995530881d297782f044dfc8a1c72d08
This commit is contained in:
Clark Boylan 2018-04-16 09:03:02 -07:00
parent 39c90078d3
commit 139f12a371
1 changed files with 14 additions and 21 deletions

View File

@ -52,11 +52,6 @@ try:
except ImportError:
import ConfigParser as configparser
try:
import pip
except ImportError:
pip = None
import os
import subprocess
import tempfile
@ -105,14 +100,12 @@ def get_sibling_python_packages(projects, tox_python):
def get_installed_packages(tox_python):
if pip is None:
raise RuntimeError("pip python module is required")
with tempfile.NamedTemporaryFile(delete=False) as tmp_requirements:
tmp_requirements.write(subprocess.check_output(
[tox_python, '-m', 'pip', 'freeze']))
tmp_requirements.file.flush()
return pip.req.req_file.parse_requirements(
tmp_requirements.name, session=pip.download.PipSession())
# We use the output of pip freeze here as that is pip's stable public
# interface.
frozen_pkgs = subprocess.check_output(
[tox_python, '-m', 'pip', '-qqq', 'freeze']
)
return [x.split('==')[0] for x in frozen_pkgs.split('\n') if '==' in x]
def write_new_constraints_file(constraints, packages):
@ -182,25 +175,25 @@ def main():
for name, root in sibling_python_packages.items():
log.append("Sibling {name} at {root}".format(name=name, root=root))
found_sibling_packages = []
for package in get_installed_packages(tox_python):
for dep_name in get_installed_packages(tox_python):
log.append(
"Found {name} python package installed".format(
name=package.name))
if package.name == package_name:
name=dep_name))
if dep_name == package_name:
# We don't need to re-process ourself. We've filtered ourselves
# from the source dir list, but let's be sure nothing is weird.
log.append(
"Skipping {name} because it's us".format(
name=package.name))
name=dep_name))
continue
if package.name in sibling_python_packages:
if dep_name in sibling_python_packages:
log.append(
"Package {name} on system in {root}".format(
name=package.name,
root=sibling_python_packages[package.name]))
name=dep_name,
root=sibling_python_packages[dep_name]))
changed = True
found_sibling_packages.append(package.name)
found_sibling_packages.append(dep_name)
if constraints:
constraints_file = write_new_constraints_file(