Bug 1747837: Attempt to reinstall optional dependencies during bootstrap r=ahal

Currently, developers don't have a way to have the Mach virtualenv
re-attempt to install optional dependencies (such as `glean`).

As part of `./mach bootstrap` (the general catch-all "re-create my dev
environment" command), we should retry installing optional dependencies.

This also matches the "glean isn't installed" error message
recommendation.

Note: This doesn't address the case in which command virtualenvs
need their optional dependencies attempted to be reinstalled.
However, since we don't have any such cases yet, I'm satisfied with
deferring that work.

Differential Revision: https://phabricator.services.mozilla.com/D123242
This commit is contained in:
Mitchell Hentges 2022-01-25 22:19:10 +00:00
parent 57da66db7e
commit f25a47724b
2 changed files with 28 additions and 11 deletions

View File

@ -315,6 +315,14 @@ class MachSiteManager:
self._build()
return up_to_date
def attempt_populate_optional_packages(self):
if self._site_packages_source != SitePackagesSource.VENV:
pass
self._virtualenv().install_optional_packages(
self._requirements.pypi_optional_requirements
)
def activate(self):
assert not MozSiteMetadata.current
@ -778,6 +786,16 @@ class PythonVirtualenv:
stderr=subprocess.STDOUT,
)
def install_optional_packages(self, optional_requirements):
for requirement in optional_requirements:
try:
self.pip_install_with_constraints([str(requirement.requirement)])
except subprocess.CalledProcessError:
print(
f"Could not install {requirement.requirement.name}, so "
f"{requirement.repercussion}. Continuing."
)
def _resolve_installed_packages(self):
return _resolve_installed_packages(self.python_path)
@ -1081,15 +1099,7 @@ def _create_venv_with_pthfile(
if site_packages_source == SitePackagesSource.VENV:
for requirement in requirements.pypi_requirements:
target_venv.pip_install([str(requirement.requirement)])
for requirement in requirements.pypi_optional_requirements:
try:
target_venv.pip_install_with_constraints([str(requirement.requirement)])
except subprocess.CalledProcessError:
print(
f"Could not install {requirement.requirement.name}, so "
f"{requirement.repercussion}. Continuing."
)
target_venv.install_optional_packages(requirements.pypi_optional_requirements)
os.utime(target_venv.activate_path, None)
metadata.write(is_finalized=True)

View File

@ -23,6 +23,7 @@ from mach.util import (
win_to_msys_path,
)
from mach.telemetry import initialize_telemetry_setting
from mach.site import MachSiteManager
from mozboot.base import MODERN_RUST_VERSION
from mozboot.centosfedora import CentOSFedoraBootstrapper
from mozboot.opensuse import OpenSUSEBootstrapper
@ -325,7 +326,7 @@ class Bootstrapper(object):
)
self.instance.srcdir = checkout_root
self.instance.validate_environment()
self._validate_python_environment()
self._validate_python_environment(checkout_root)
if self.instance.no_system_changes:
self.maybe_install_private_packages_or_exit(application)
@ -416,7 +417,7 @@ class Bootstrapper(object):
)
print(suggestion, end="")
def _validate_python_environment(self):
def _validate_python_environment(self, topsrcdir):
valid = True
try:
# distutils is singled out here because some distros (namely Ubuntu)
@ -449,6 +450,12 @@ class Bootstrapper(object):
)
sys.exit(1)
mach_site = MachSiteManager.from_environment(
topsrcdir,
lambda: os.path.normpath(get_state_dir(True, topsrcdir=topsrcdir)),
)
mach_site.attempt_populate_optional_packages()
def update_vct(hg: Path, root_state_dir: Path):
"""Ensure version-control-tools in the state directory is up to date."""