Bug 1730712: Do simple "pip install" when preparing venv r=ahal

`install_pip_package()` does some logic around not running pip if a
package is already installed.

However, this is redundant, because when building a venv, no packages
are installed.

Additionally, this was the constraint forcing us to populate the
virtualenv in a separate process from the one building it.

Differential Revision: https://phabricator.services.mozilla.com/D129294
This commit is contained in:
Mitchell Hentges 2021-11-01 21:34:01 +00:00
parent c775c1f269
commit 1ae08fbcc5

View File

@ -325,13 +325,7 @@ class VirtualenvManager(VirtualenvHelper):
)
def populate(self):
"""Populate the virtualenv.
Note that the Python interpreter running this function should be the
one from the virtualenv. If it is the system Python or if the
environment is not configured properly, packages could be installed
into the wrong place. This is how virtualenv's work.
"""
"""Populate the virtualenv."""
import distutils.sysconfig
# We ignore environment variables that may have been altered by
@ -364,12 +358,17 @@ class VirtualenvManager(VirtualenvHelper):
# each other remain the same).
f.write("{}\n".format(os.path.relpath(path, python_lib)))
pip = [self.python_path, "-m", "pip"]
for pypi_requirement in env_requirements.pypi_requirements:
self.install_pip_package(str(pypi_requirement.requirement))
subprocess.check_call(
pip + ["install", str(pypi_requirement.requirement)]
)
for requirement in env_requirements.pypi_optional_requirements:
try:
self.install_pip_package(str(requirement.requirement))
subprocess.check_call(
pip + ["install", str(requirement.requirement)]
)
except subprocess.CalledProcessError:
print(
f"Could not install {requirement.requirement.name}, so "