testing: utility function to find path to Mercurial (
bug 1363509); r?glob
Without this, this code attempts to look for `hg` in the global
virtualenv. This path may not exist if the global virtualenv isn't
being used. We use the `hg` from the activated virtualenv first then
fall back to the global virtualenv.
This may still fail in some cases. But it is better than it was before.
MozReview-Commit-ID: HxxzRYUZz8u
--- a/testing/vcttesting/docker.py
+++ b/testing/vcttesting/docker.py
@@ -42,16 +42,17 @@ from coverage.data import CoverageData
from .util import (
limited_threadpoolexecutor,
wait_for_amqp,
wait_for_http,
wait_for_ssh,
)
from .vctutil import (
get_and_write_vct_node,
+ hg_executable,
)
HERE = os.path.abspath(os.path.dirname(__file__))
DOCKER_DIR = os.path.normpath(os.path.join(HERE, '..', 'docker'))
ROOT = os.path.normpath(os.path.join(HERE, '..', '..'))
@@ -255,20 +256,19 @@ class Docker(object):
except requests.exceptions.RequestException:
return False
def _get_vct_files(self):
"""Obtain all the files in the version-control-tools repo.
Returns a dict of relpath to full path.
"""
- hg = os.path.join(ROOT, 'venv', 'bin', 'hg')
env = dict(os.environ)
env['HGRCPATH'] = '/dev/null'
- args = [hg, '-R', '.', 'locate']
+ args = [hg_executable(), '-R', '.', 'locate']
with open(os.devnull, 'wb') as null:
files = subprocess.check_output(
args, env=env, cwd=ROOT, stderr=null).splitlines()
# Add files from the nested reviewboard-fork repo.
fork_path = os.path.join(ROOT, 'reviewboard-fork')
if os.path.exists(fork_path):
with open(os.devnull, 'wb') as null:
--- a/testing/vcttesting/vctutil.py
+++ b/testing/vcttesting/vctutil.py
@@ -1,26 +1,41 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, unicode_literals
import os
import subprocess
+import sys
HERE = os.path.abspath(os.path.dirname(__file__))
ROOT = os.path.normpath(os.path.join(HERE, '..', '..'))
+def hg_executable():
+ if 'VIRTUAL_ENV' in os.environ:
+ venv = os.environ['VIRTUAL_ENV']
+ # Virtualenv activated by Python itself, not from shell.
+ elif hasattr(sys, 'real_prefix'):
+ venv = sys.prefix
+ else:
+ venv = os.path.join(ROOT, 'venv')
+
+ if os.name == 'nt':
+ return os.path.join(venv, 'Scripts', 'hg.exe')
+ else:
+ return os.path.join(venv, 'bin', 'hg')
+
+
def get_and_write_vct_node():
- hg = os.path.join(os.environ['VIRTUAL_ENV'], 'bin', 'hg')
env = dict(os.environ)
env['HGRCPATH'] = '/dev/null'
- args = [hg, '-R', ROOT, 'log', '-r', '.', '-T', '{node|short}']
+ args = [hg_executable(), '-R', ROOT, 'log', '-r', '.', '-T', '{node|short}']
with open(os.devnull, 'wb') as null:
node = subprocess.check_output(args, env=env, cwd='/', stderr=null)
with open(os.path.join(ROOT, '.vctnode'), 'wb') as fh:
fh.write(node)
return node