OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # This Source Code Form is subject to the terms of the Mozilla Public |
| 3 # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 # You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 |
| 6 import os |
| 7 import shutil |
| 8 from subprocess import check_call |
| 9 import sys |
| 10 import urllib2 |
| 11 import zipfile |
| 12 |
| 13 # Link to the folder which contains the zip archives of virtualenv |
| 14 URL_VIRTUALENV = 'https://codeload.github.com/pypa/virtualenv/zip/' |
| 15 VERSION_VIRTUALENV = '1.9.1' |
| 16 |
| 17 DIR_BASE = os.path.abspath(os.path.dirname(__file__)) |
| 18 DIR_ENV = os.path.join(DIR_BASE, 'tmp', 'venv') |
| 19 DIR_TMP = os.path.join(DIR_BASE, 'tmp') |
| 20 |
| 21 REQ_TXT = os.path.join('tests', 'requirements.txt') |
| 22 |
| 23 |
| 24 def download(url, target): |
| 25 """Downloads the specified url to the given target.""" |
| 26 response = urllib2.urlopen(url) |
| 27 with open(target, 'wb') as f: |
| 28 f.write(response.read()) |
| 29 return target |
| 30 |
| 31 |
| 32 # see http://stackoverflow.com/questions/12332975/installing-python-module-withi
n-code |
| 33 def install(package, version): |
| 34 package_arg = "%s==%s" % (package, version) |
| 35 check_call(['pip', 'install', '--upgrade', package_arg]) |
| 36 |
| 37 |
| 38 def python(*args): |
| 39 pypath = [os.path.join(DIR_ENV, 'bin', 'python')] |
| 40 check_call(pypath + list(args)) |
| 41 |
| 42 |
| 43 try: |
| 44 # Remove potentially pre-existing tmp_dir |
| 45 shutil.rmtree(DIR_TMP, True) |
| 46 # Start out clean |
| 47 os.makedirs(DIR_TMP) |
| 48 |
| 49 print 'Downloading virtualenv %s' % VERSION_VIRTUALENV |
| 50 virtualenv_file = download(URL_VIRTUALENV + VERSION_VIRTUALENV, |
| 51 os.path.join(DIR_TMP, 'virtualenv.zip')) |
| 52 virtualenv_zip = zipfile.ZipFile(virtualenv_file) |
| 53 virtualenv_zip.extractall(DIR_TMP) |
| 54 virtualenv_zip.close() |
| 55 |
| 56 print 'Creating new virtual environment' |
| 57 virtualenv_script = os.path.join(DIR_TMP, |
| 58 'virtualenv-%s' % VERSION_VIRTUALENV, |
| 59 'virtualenv.py') |
| 60 check_call(['python', virtualenv_script, DIR_ENV]) |
| 61 |
| 62 print 'Activating virtual environment' |
| 63 # for more info see: |
| 64 # http://www.virtualenv.org/en/latest/#using-virtualenv-without-bin-python |
| 65 if sys.platform == 'win32': |
| 66 activate_this_file = os.path.join(DIR_ENV, 'Scripts', |
| 67 'activate_this.py') |
| 68 else: |
| 69 activate_this_file = os.path.join(DIR_ENV, 'bin', |
| 70 'activate_this.py') |
| 71 |
| 72 if not os.path.isfile(activate_this_file): |
| 73 # create venv |
| 74 check_call(['virtualenv', '--no-site-packages', DIR_ENV]) |
| 75 |
| 76 execfile(activate_this_file, dict(__file__=activate_this_file)) |
| 77 print "Virtual environment activated successfully." |
| 78 |
| 79 except: |
| 80 print "Could not activate virtual environment." |
| 81 print "Exiting." |
| 82 sys.exit(1) |
| 83 |
| 84 |
| 85 # Install dependent packages |
| 86 check_call(['pip', 'install', '--upgrade', '-r', REQ_TXT]) |
| 87 |
| 88 # Install mozdownload |
| 89 python('setup.py', 'develop') |
| 90 |
| 91 # run the tests |
| 92 python(os.path.join('tests', 'test.py')) |
| 93 |
| 94 # Clean up |
| 95 shutil.rmtree(DIR_TMP) |
OLD | NEW |