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:
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