INSTALL.py (2309B)
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 4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 7 """ 8 installation script for talos. This script: 9 - creates a virtualenv in the current directory 10 - sets up talos in development mode: `python setup.py develop` 11 - downloads pageloader and packages to talos/page_load_test/pageloader.xpi 12 """ 13 14 import os 15 import subprocess 16 import sys 17 import urllib.request 18 19 try: 20 from subprocess import check_call as call 21 except ImportError: 22 from subprocess import call 23 24 # globals 25 here = os.path.dirname(os.path.abspath(__file__)) 26 VIRTUALENV = "https://raw.github.com/pypa/virtualenv/1.10/virtualenv.py" 27 28 29 def which(binary, path=os.environ["PATH"]): 30 dirs = path.split(os.pathsep) 31 for dir in dirs: 32 if os.path.isfile(os.path.join(dir, path)): 33 return os.path.join(dir, path) 34 if os.path.isfile(os.path.join(dir, path + ".exe")): 35 return os.path.join(dir, path + ".exe") 36 37 38 def main(args=sys.argv[1:]): 39 # sanity check 40 # ensure setup.py exists 41 setup_py = os.path.join(here, "setup.py") 42 assert os.path.exists(setup_py), "setup.py not found" 43 44 # create a virtualenv 45 virtualenv = which("virtualenv") or which("virtualenv.py") 46 if virtualenv: 47 call([virtualenv, "--system-site-packages", here]) 48 else: 49 process = subprocess.Popen( 50 [sys.executable, "-", "--system-site-packages", here], stdin=subprocess.PIPE 51 ) 52 stdout, stderr = process.communicate( 53 input=urllib.request.urlopen(VIRTUALENV).read() 54 ) 55 56 # find the virtualenv's python 57 for i in ("bin", "Scripts"): 58 bindir = os.path.join(here, i) 59 if os.path.exists(bindir): 60 break 61 else: 62 raise AssertionError("virtualenv binary directory not found") 63 for i in ("python", "python.exe"): 64 virtualenv_python = os.path.join(bindir, i) 65 if os.path.exists(virtualenv_python): 66 break 67 else: 68 raise AssertionError("virtualenv python not found") 69 70 # install talos into the virtualenv 71 call([os.path.abspath(virtualenv_python), "setup.py", "develop"], cwd=here) 72 73 74 if __name__ == "__main__": 75 main()