Bug 1738848: Handle virtualenv case where metadata file is missing r=ahal
At Mach initialization time, it needs to know if it's not running from the Mach virtualenv so it can decide to insulate itself from the external sys.path. However, the current mechanism of detecting the Mach virtualenv struggles if the venv is old, and therefore missing its metadata file. In such a case, it's recognized as "not the Mach venv" rather than "an out-of-date Mach venv". As part of this, I'm realizing that simply using the metadata file as a "virtualenv has finished building" marker is insufficient, because it will cause similar confusion here. This is solved with a "finalization" key in in the metadata. Differential Revision: https://phabricator.services.mozilla.com/D130794
This commit is contained in:
@@ -182,10 +182,23 @@ def _activate_python_environment(topsrcdir, state_dir):
|
||||
from mach.site import (
|
||||
MachSiteManager,
|
||||
VirtualenvOutOfDateException,
|
||||
MozSiteMetadata,
|
||||
MozSiteMetadataOutOfDateError,
|
||||
)
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user