]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Ensure our virtualenv's bin/ is in our PATH
authorZack Cerza <zack@redhat.com>
Fri, 22 May 2015 16:20:10 +0000 (10:20 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 1 Jun 2015 16:21:09 +0000 (10:21 -0600)
So that we can run commands we install via pip from inside teuthology

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/__init__.py

index 6d19e6de9bf02d27ad0c6faccb714007307ad04a..8144418c87b89c9329a436267caae9e77f7f50ef 100644 (file)
@@ -4,10 +4,20 @@ from .orchestra import monkey
 monkey.patch_all()
 
 import logging
+import os
+import sys
 
 
 __version__ = '0.1.0'
 
+
+# If we are running inside a virtualenv, ensure we have its 'bin' directory in
+# our PATH. This doesn't happen automatically if scripts are called without
+# first activating the virtualenv.
+exec_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
+if os.path.split(exec_dir)[-1] == 'bin' and exec_dir not in os.environ['PATH']:
+    os.environ['PATH'] = ':'.join((exec_dir, os.environ['PATH']))
+
 # We don't need to see log entries for each connection opened
 logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(
     logging.WARN)