Bug 1466211 - Detect if we are running in a virtual environment; r=chmanchester draft
authorDave Hunt <dhunt@mozilla.com>
Fri, 15 Jun 2018 18:05:20 -0700
changeset 809843 9a61219b66ef15e5d67c414524e5f5362118b8d9
parent 809842 e275ac2ada53270d641b45d9d57c92f85c300668
push id113827
push userbmo:dave.hunt@gmail.com
push dateSat, 23 Jun 2018 08:22:59 +0000
Bug 1466211 - Detect if we are running in a virtual environment; r=chmanchester When we're running using pipenv, we have more than one virtual environment. This means the current check to see if python matches the initial virtual environment gives a false positive when we're in a secondary virtual environment. This patch changes the condition to check if the current python path exists within the virtual environments root directory. MozReview-Commit-ID: AAONwLWsigL
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -225,20 +225,21 @@ def virtualenv_python(env_python, build_
             python = mozconfig['vars']['modified']['PYTHON'][1]
     with LineIO(lambda l: log.error(l)) as out:
     topsrcdir, topobjdir = build_env.topsrcdir, build_env.topobjdir
     if topobjdir.endswith('/js/src'):
         topobjdir = topobjdir[:-7]
+    virtualenvs_root = os.path.join(topobjdir, '_virtualenvs')
     with LineIO(lambda l: log.info(l), 'replace') as out:
         manager = VirtualenvManager(
             topsrcdir, topobjdir,
-            os.path.join(topobjdir, '_virtualenvs', 'init'), out,
+            os.path.join(virtualenvs_root, 'init'), out,
             os.path.join(topsrcdir, 'build', 'virtualenv_packages.txt'))
     if python:
         # If we're not in the virtualenv, we need the which module for
         # find_program.
         if normsep(sys.executable) != normsep(manager.python_path):
                 topsrcdir, 'third_party', 'python', 'which'))
@@ -251,17 +252,17 @@ def virtualenv_python(env_python, build_
         python = sys.executable
     if not manager.up_to_date(python):
         log.info('Creating Python environment')
     python = normsep(manager.python_path)
-    if python != normsep(sys.executable):
+    if not normsep(sys.executable).startswith(normsep(virtualenvs_root)):
         log.info('Reexecuting in the virtualenv')
         if env_python:
             del os.environ['PYTHON']
         # One would prefer to use os.execl, but that's completely borked on
         # Windows.
         sys.exit(subprocess.call([python] + sys.argv))
     # We are now in the virtualenv