Backed out 10 changesets (bug 1712151, bug 1724279, bug 1730712, bug 1717051, bug 1723031, bug 1731145) for causing failures on test_yaml.py
Backed out changeset 7f64d538701b (bug1723031) Backed out changeset 394152994966 (bug1723031) Backed out changeset 9bfeb01bcc9a (bug1723031) Backed out changeset 3d283616a57d (bug 1730712) Backed out changeset bc677b409650 (bug 1724279) Backed out changeset 784c94c2f528 (bug1723031) Backed out changeset 6e1bde40e3b4 (bug1723031) Backed out changeset 7adf7e2136a3 (bug 1712151) Backed out changeset 2aef162b9a1b (bug 1717051) Backed out changeset 9beeb6d3d95b (bug 1731145)
This commit is contained in:
@@ -9,7 +9,6 @@ import os
|
||||
import platform
|
||||
import shutil
|
||||
import site
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
@@ -142,6 +141,35 @@ CATEGORIES = {
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def search_path(mozilla_dir, packages_txt):
|
||||
with open(os.path.join(mozilla_dir, packages_txt)) as f:
|
||||
packages = [
|
||||
line.strip().split(":", maxsplit=1)
|
||||
for line in f
|
||||
if not line.lstrip().startswith("#")
|
||||
]
|
||||
|
||||
def handle_package(action, package):
|
||||
if action == "packages.txt":
|
||||
for p in search_path(mozilla_dir, package):
|
||||
yield os.path.join(mozilla_dir, p)
|
||||
|
||||
if action == "pth":
|
||||
yield os.path.join(mozilla_dir, package)
|
||||
|
||||
for current_action, current_package in packages:
|
||||
for path in handle_package(current_action, current_package):
|
||||
yield path
|
||||
|
||||
|
||||
def mach_sys_path(mozilla_dir):
|
||||
return [
|
||||
os.path.join(mozilla_dir, path)
|
||||
for path in search_path(mozilla_dir, "build/mach_virtualenv_packages.txt")
|
||||
]
|
||||
|
||||
|
||||
INSTALL_PYTHON_GUIDANCE_LINUX = """
|
||||
See https://firefox-source-docs.mozilla.org/setup/linux_build.html#installingpython
|
||||
for guidance on how to install Python on your system.
|
||||
@@ -168,102 +196,6 @@ install a recent enough Python 3.
|
||||
""".strip()
|
||||
|
||||
|
||||
def _scrub_system_site_packages():
|
||||
site_paths = set(site.getsitepackages() + [site.getusersitepackages()])
|
||||
sys.path = [path for path in sys.path if path not in site_paths]
|
||||
|
||||
|
||||
def _activate_python_environment(topsrcdir):
|
||||
# We need the "mach" module to access the logic to parse virtualenv
|
||||
# requirements. Since that depends on "packaging" (and, transitively,
|
||||
# "pyparsing"), we add those to the path too.
|
||||
sys.path[0:0] = [
|
||||
os.path.join(topsrcdir, module)
|
||||
for module in (
|
||||
os.path.join("python", "mach"),
|
||||
os.path.join("third_party", "python", "packaging"),
|
||||
os.path.join("third_party", "python", "pyparsing"),
|
||||
)
|
||||
]
|
||||
|
||||
from mach.requirements import MachEnvRequirements
|
||||
|
||||
thunderbird_dir = os.path.join(topsrcdir, "comm")
|
||||
is_thunderbird = os.path.exists(thunderbird_dir) and bool(
|
||||
os.listdir(thunderbird_dir)
|
||||
)
|
||||
|
||||
requirements = MachEnvRequirements.from_requirements_definition(
|
||||
topsrcdir,
|
||||
is_thunderbird,
|
||||
True,
|
||||
os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
|
||||
)
|
||||
|
||||
if os.environ.get("MACH_USE_SYSTEM_PYTHON") or os.environ.get("MOZ_AUTOMATION"):
|
||||
env_var = (
|
||||
"MOZ_AUTOMATION"
|
||||
if os.environ.get("MOZ_AUTOMATION")
|
||||
else "MACH_USE_SYSTEM_PYTHON"
|
||||
)
|
||||
|
||||
has_pip = (
|
||||
subprocess.run(
|
||||
[sys.executable, "-c", "import pip"], stderr=subprocess.DEVNULL
|
||||
).returncode
|
||||
== 0
|
||||
)
|
||||
# There are environments in CI that aren't prepared to provide any Mach dependency
|
||||
# packages. Changing this is a nontrivial endeavour, so guard against having
|
||||
# non-optional Mach requirements.
|
||||
assert (
|
||||
not requirements.pypi_requirements
|
||||
), "Mach pip package requirements must be optional."
|
||||
if has_pip:
|
||||
pip = [sys.executable, "-m", "pip"]
|
||||
check_result = subprocess.run(
|
||||
pip + ["check"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
)
|
||||
if check_result.returncode:
|
||||
print(check_result.stdout, file=sys.stderr)
|
||||
subprocess.check_call(pip + ["list", "-v"], stdout=sys.stderr)
|
||||
raise Exception(
|
||||
'According to "pip check", the current Python '
|
||||
"environment has package-compatibility issues."
|
||||
)
|
||||
|
||||
package_result = requirements.validate_environment_packages(pip)
|
||||
if not package_result.has_all_packages:
|
||||
print(
|
||||
"Skipping automatic management of Python dependencies since "
|
||||
f"the '{env_var}' environment variable is set.\n"
|
||||
"The following issues were found while validating your Python "
|
||||
"environment:"
|
||||
)
|
||||
print(package_result.report())
|
||||
sys.exit(1)
|
||||
else:
|
||||
# Pip isn't installed to the system Python environment, so we can't use
|
||||
# it to verify compatibility with Mach. Remove the system site-packages
|
||||
# from the import scope so that Mach behaves as though all of its
|
||||
# (optional) dependencies are not installed.
|
||||
_scrub_system_site_packages()
|
||||
|
||||
elif sys.prefix == sys.base_prefix:
|
||||
# We're in an environment where we normally use the Mach virtualenv,
|
||||
# but we're running a "nativecmd" such as "create-mach-environment".
|
||||
# Remove global site packages from sys.path to improve isolation accordingly.
|
||||
_scrub_system_site_packages()
|
||||
|
||||
sys.path[0:0] = [
|
||||
os.path.join(topsrcdir, pth.path)
|
||||
for pth in requirements.pth_requirements + requirements.vendored_requirements
|
||||
]
|
||||
|
||||
|
||||
def initialize(topsrcdir):
|
||||
# Ensure we are running Python 3.6+. We run this check as soon as
|
||||
# possible to avoid a cryptic import/usage error.
|
||||
@@ -287,9 +219,15 @@ def initialize(topsrcdir):
|
||||
if os.path.exists(deleted_dir):
|
||||
shutil.rmtree(deleted_dir, ignore_errors=True)
|
||||
|
||||
state_dir = _create_state_dir()
|
||||
_activate_python_environment(topsrcdir)
|
||||
if sys.prefix == sys.base_prefix:
|
||||
# We are not in a virtualenv. Remove global site packages
|
||||
# from sys.path.
|
||||
site_paths = set(site.getsitepackages() + [site.getusersitepackages()])
|
||||
sys.path = [path for path in sys.path if path not in site_paths]
|
||||
|
||||
state_dir = _create_state_dir()
|
||||
|
||||
sys.path[0:0] = mach_sys_path(topsrcdir)
|
||||
import mach.base
|
||||
import mach.main
|
||||
from mach.util import setenv
|
||||
|
||||
Reference in New Issue
Block a user