Bug 1466211 - Detect if we are running in a virtual environment; r=chmanchester
authorDave Hunt <dhunt@mozilla.com>
Fri, 15 Jun 2018 18:05:20 -0700
changeset 423535 434d589d020d32b954aa060686bcccca01c15f0b
parent 423534 9b0a35f0572a9c809f1e6d12a40c5532cdf7428e
child 423536 1a541384e0d8d5b509caa58aa472d88ba22e2c9d
push id65490
push userdhunt@mozilla.com
push dateMon, 25 Jun 2018 15:29:04 +0000
treeherderautoland@434d589d020d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1466211
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
build/moz.configure/init.configure
--- 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:
         verify_python_version(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):
             sys.path.append(os.path.join(
                 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')
         manager.build(python)
 
     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