From 16f898657c54ad10883ca96993034327f90005b5 Mon Sep 17 00:00:00 2001 From: criss Date: Thu, 30 Sep 2021 10:36:36 +0300 Subject: [PATCH] Backed out changeset 894fc83e19a0 (bug 1717051) for causing busting macth commands. a=backout --- build/docs/python.rst | 2 +- build/mach_initialize.py | 22 ++++------- build/moz.configure/init.configure | 4 +- python/mozboot/mozboot/util.py | 2 +- python/mozbuild/mozbuild/base.py | 2 +- python/mozbuild/mozbuild/mach_commands.py | 3 +- python/mozbuild/mozbuild/sphinx.py | 2 +- .../mozbuild/virtualenv.py} | 38 ++++++++++--------- 8 files changed, 36 insertions(+), 39 deletions(-) rename python/{mach/mach/virtualenv/__init__.py => mozbuild/mozbuild/virtualenv.py} (94%) diff --git a/build/docs/python.rst b/build/docs/python.rst index 80756fd60a12..dc8c8f2acfe7 100644 --- a/build/docs/python.rst +++ b/build/docs/python.rst @@ -73,7 +73,7 @@ to just keep them separate so there is no potential for conflicts. Very early in the build process, a virtualenv is created inside the :term:`object directory`. The virtualenv is configured such that it can find all the Python packages in the source tree. The code for this lives -in :py:mod:`mach.virtualenv`. +in :py:mod:`mozbuild.virtualenv`. Deficiencies ------------ diff --git a/build/mach_initialize.py b/build/mach_initialize.py index 9799707486d4..e4616d2847c3 100644 --- a/build/mach_initialize.py +++ b/build/mach_initialize.py @@ -187,7 +187,6 @@ def _activate_python_environment(topsrcdir): ] from mach.requirements import MachEnvRequirements - from mach.virtualenv import MozVirtualenvMetadata thunderbird_dir = os.path.join(topsrcdir, "comm") is_thunderbird = os.path.exists(thunderbird_dir) and bool( @@ -201,8 +200,6 @@ def _activate_python_environment(topsrcdir): os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"), ) - active_metadata = MozVirtualenvMetadata.from_runtime() - is_mach_virtualenv = active_metadata and active_metadata.virtualenv_name == "mach" if os.environ.get("MACH_USE_SYSTEM_PYTHON") or os.environ.get("MOZ_AUTOMATION"): env_var = ( "MOZ_AUTOMATION" @@ -255,21 +252,16 @@ def _activate_python_environment(topsrcdir): # (optional) dependencies are not installed. _scrub_system_site_packages() - sys.path[0:0] = [ - os.path.join(topsrcdir, pth.path) - for pth in requirements.pth_requirements - + requirements.vendored_requirements - ] - elif not is_mach_virtualenv: - # We're in an environment where we normally *would* use the Mach virtualenv, + 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 - ] + + sys.path[0:0] = [ + os.path.join(topsrcdir, pth.path) + for pth in requirements.pth_requirements + requirements.vendored_requirements + ] def initialize(topsrcdir): diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure index 04269fe83315..ad9b36633ef7 100644 --- a/build/moz.configure/init.configure +++ b/build/moz.configure/init.configure @@ -226,8 +226,8 @@ option(env="PYTHON3", nargs=1, help="Python 3 interpreter (3.6 or later)") @imports("subprocess") @imports("distutils.sysconfig") @imports(_from="mozbuild.configure.util", _import="LineIO") -@imports(_from="mach.virtualenv", _import="VirtualenvManager") -@imports(_from="mach.virtualenv", _import="verify_python_version") +@imports(_from="mozbuild.virtualenv", _import="VirtualenvManager") +@imports(_from="mozbuild.virtualenv", _import="verify_python_version") @imports(_from="mozbuild.pythonutil", _import="find_python3_executable") @imports(_from="mozbuild.pythonutil", _import="python_executable_version") @imports(_from="six", _import="ensure_text") diff --git a/python/mozboot/mozboot/util.py b/python/mozboot/mozboot/util.py index f20eaa0a0887..1c9b95aa3790 100644 --- a/python/mozboot/mozboot/util.py +++ b/python/mozboot/mozboot/util.py @@ -10,7 +10,7 @@ import platform import subprocess from subprocess import CalledProcessError -from mach.virtualenv import VirtualenvHelper +from mozbuild.virtualenv import VirtualenvHelper from mozfile import which diff --git a/python/mozbuild/mozbuild/base.py b/python/mozbuild/mozbuild/base.py index a8a2adc1de0c..f4f1522c98eb 100644 --- a/python/mozbuild/mozbuild/base.py +++ b/python/mozbuild/mozbuild/base.py @@ -289,7 +289,7 @@ class MozbuildObject(ProcessExecutionMixin): @property def virtualenv_manager(self): - from mach.virtualenv import VirtualenvManager + from .virtualenv import VirtualenvManager if self._virtualenv_manager is None: self._virtualenv_manager = VirtualenvManager( diff --git a/python/mozbuild/mozbuild/mach_commands.py b/python/mozbuild/mozbuild/mach_commands.py index 7c019f6dbe7f..00737e8b2c7f 100644 --- a/python/mozbuild/mozbuild/mach_commands.py +++ b/python/mozbuild/mozbuild/mach_commands.py @@ -2446,7 +2446,7 @@ def package_l10n(command_context, verbose=False, locales=[]): def create_mach_environment(command_context, force=False): """Create the mach virtualenv.""" from mozboot.util import get_mach_virtualenv_root - from mach.virtualenv import VirtualenvManager + from mozbuild.virtualenv import VirtualenvManager virtualenv_path = get_mach_virtualenv_root() if sys.executable.startswith(virtualenv_path): @@ -2461,6 +2461,7 @@ def create_mach_environment(command_context, force=False): command_context.topsrcdir, os.path.dirname(virtualenv_path), "mach", + populate_local_paths=False, ) if manager.up_to_date() and not force: diff --git a/python/mozbuild/mozbuild/sphinx.py b/python/mozbuild/mozbuild/sphinx.py index 1d271e58f6d8..ed0b76167db4 100644 --- a/python/mozbuild/mozbuild/sphinx.py +++ b/python/mozbuild/mozbuild/sphinx.py @@ -198,7 +198,7 @@ class MozbuildSymbols(Directive): def setup(app): - from mach.virtualenv import VirtualenvManager + from mozbuild.virtualenv import VirtualenvManager from moztreedocs import manager app.add_directive("mozbuildsymbols", MozbuildSymbols) diff --git a/python/mach/mach/virtualenv/__init__.py b/python/mozbuild/mozbuild/virtualenv.py similarity index 94% rename from python/mach/mach/virtualenv/__init__.py rename to python/mozbuild/mozbuild/virtualenv.py index 67a0a589704f..eb1da65828e3 100644 --- a/python/mach/mach/virtualenv/__init__.py +++ b/python/mozbuild/mozbuild/virtualenv.py @@ -55,10 +55,6 @@ class MozVirtualenvMetadata: and self.virtualenv_name == other.virtualenv_name ) - @classmethod - def from_runtime(cls): - return cls.from_path(os.path.join(sys.prefix, METADATA_FILENAME)) - @classmethod def from_path(cls, path): try: @@ -108,6 +104,7 @@ class VirtualenvManager(VirtualenvHelper): virtualenvs_dir, virtualenv_name, *, + populate_local_paths=True, log_handle=sys.stdout, base_python=sys.executable, manifest_path=None, @@ -133,6 +130,7 @@ class VirtualenvManager(VirtualenvHelper): self.exe_info_path = os.path.join(self.virtualenv_root, "python_exe.txt") self.log_handle = log_handle + self.populate_local_paths = populate_local_paths self._virtualenv_name = virtualenv_name self._manifest_path = manifest_path or os.path.join( topsrcdir, "build", f"{virtualenv_name}_virtualenv_packages.txt" @@ -207,7 +205,9 @@ class VirtualenvManager(VirtualenvHelper): if existing_metadata != self._metadata: return False - if env_requirements.pth_requirements or env_requirements.vendored_requirements: + if ( + env_requirements.pth_requirements or env_requirements.vendored_requirements + ) and self.populate_local_paths: try: with open( os.path.join(self._site_packages_dir(), PTH_FILENAME) @@ -350,18 +350,19 @@ class VirtualenvManager(VirtualenvHelper): del os.environ[k] env_requirements = self._requirements() - python_lib = distutils.sysconfig.get_python_lib() - with open(os.path.join(python_lib, PTH_FILENAME), "a") as f: - for pth_requirement in ( - env_requirements.pth_requirements - + env_requirements.vendored_requirements - ): - path = os.path.join(self.topsrcdir, pth_requirement.path) - # This path is relative to the .pth file. Using a - # relative path allows the srcdir/objdir combination - # to be moved around (as long as the paths relative to - # each other remain the same). - f.write("{}\n".format(os.path.relpath(path, python_lib))) + if self.populate_local_paths: + python_lib = distutils.sysconfig.get_python_lib() + with open(os.path.join(python_lib, PTH_FILENAME), "a") as f: + for pth_requirement in ( + env_requirements.pth_requirements + + env_requirements.vendored_requirements + ): + path = os.path.join(self.topsrcdir, pth_requirement.path) + # This path is relative to the .pth file. Using a + # relative path allows the srcdir/objdir combination + # to be moved around (as long as the paths relative to + # each other remain the same). + f.write("{}\n".format(os.path.relpath(path, python_lib))) for pypi_requirement in env_requirements.pypi_requirements: self.install_pip_package(str(pypi_requirement.requirement)) @@ -406,6 +407,8 @@ class VirtualenvManager(VirtualenvHelper): self._virtualenv_name, self._manifest_path, ] + if self.populate_local_paths: + args.append("--populate-local-paths") result = self._log_process_output(args, cwd=self.topsrcdir) @@ -603,6 +606,7 @@ if __name__ == "__main__": opts.topsrcdir, opts.virtualenvs_dir, opts.virtualenv_name, + populate_local_paths=opts.populate_local_paths, manifest_path=opts.manifest_path, )