From 480dfb89edcd749d6a330628ca2b7a7aea1b44db Mon Sep 17 00:00:00 2001 From: Thomas Grainger <tagrain@gmail.com> Date: Sat, 18 Aug 2012 01:11:57 +0200 Subject: [PATCH] use pkg_resources to check without import --- automation-tests/run.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/automation-tests/run.py b/automation-tests/run.py index 0d20e010f..fea0a6077 100755 --- a/automation-tests/run.py +++ b/automation-tests/run.py @@ -5,6 +5,7 @@ import os import platform import subprocess import sys +import pkg_resources def main(): @@ -48,17 +49,9 @@ def main(): # 2. check that virtualenv and pip exist. if not, bail. try: - import pip - except ImportError: - sys.stderr.write('pip must be installed; do "easy_install pip", ' + - ' then try again\n') - exit(1) - - try: - import virtualenv - except ImportError: - sys.stderr.write('virtualenv must be installed; do "pip install ' + - 'virtualenv", then try again\n') + pkg_resources.WorkingSet().require('pip', 'virtualenv') + except pkg_resources.DistributionNotFound as e: + sys.stderr.write('{package} must be installed\n'.format(package=e.message) exit(1) # 3. create the virtualenv if they asked you to install it or it's missing -- GitLab