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 810232 02207cd0c73975ae7f2f8f04bcf038b2702bd35a
parent 810231 5a145bd992606304e9362878f258701e8120982a
push id113931
push userbmo:dave.hunt@gmail.com
push dateMon, 25 Jun 2018 15:20:29 +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