Bug 1717051: Automatically create and activate Mach virtualenv r=ahal

Consolidate Mach virtualenv management to the front of the
Mach process. This obsoletes `./mach create-mach-environment`
and simplifies the `sh` portion of the top-level `./mach` script.

This helps ensure that the Mach virtualenv doesn't become
out-of-sync and simplifies the mental model of the Mach
virtualenv situation.

Differential Revision: https://phabricator.services.mozilla.com/D120401
This commit is contained in:
Mitchell Hentges
2021-11-24 20:06:33 +00:00
parent 917740f81e
commit 6706092fe6
9 changed files with 16 additions and 139 deletions

View File

@@ -179,38 +179,14 @@ def _activate_python_environment(topsrcdir, state_dir):
)
]
from mach.site import (
MachSiteManager,
VirtualenvOutOfDateException,
MozSiteMetadata,
MozSiteMetadataOutOfDateError,
)
from mach.site import MachSiteManager
try:
active_metadata = MozSiteMetadata.from_runtime()
if not active_metadata and os.path.basename(sys.prefix) == "mach":
# Until the new "MozVirtualenvMetadata" code has been live for long enough,
# there will be Mach virtualenvs without associated "metadata" files.
# Since "active_metadata" will be "None" in these cases, let's try
# to identify them with a dumb, but mostly correct, "parent directory name"
# check.
# If the check matches, then the virtualenv should be re-generated so it
# gets its metadata file.
raise MozSiteMetadataOutOfDateError(
"Mach virtualenv is missing metadata file."
)
mach_environment = MachSiteManager.from_environment(
topsrcdir,
# normpath state_dir to normalize msys-style slashes.
os.path.normpath(state_dir),
)
mach_environment.activate()
except (VirtualenvOutOfDateException, MozSiteMetadataOutOfDateError):
print(
'The "mach" virtualenv is not up-to-date, please run '
'"./mach create-mach-environment"'
)
sys.exit(1)
mach_environment = MachSiteManager.from_environment(
topsrcdir,
# normpath state_dir to normalize msys-style slashes.
os.path.normpath(state_dir),
)
mach_environment.activate()
def initialize(topsrcdir):
@@ -430,8 +406,8 @@ def _finalize_telemetry_glean(telemetry, is_bootstrap, success):
has_psutil, logical_cores, physical_cores, memory_total = get_psutil_stats()
if has_psutil:
# psutil may not be available (we allow `mach create-mach-environment`
# to fail to install it).
# psutil may not be available (we may not have been able to download
# a wheel or build it from source).
system_metrics.logical_cores.add(logical_cores)
system_metrics.physical_cores.add(physical_cores)
if memory_total is not None: