OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The LUCI Authors. All rights reserved. | 2 # Copyright 2016 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 import contextlib | 7 import contextlib |
8 import glob | 8 import glob |
9 import logging | 9 import logging |
10 import os | 10 import os |
11 import re | 11 import re |
12 import shutil | 12 import shutil |
13 import subprocess | 13 import subprocess |
14 import sys | 14 import sys |
15 import tempfile | 15 import tempfile |
16 | 16 |
17 from util import STORAGE_URL, OBJECT_URL, LOCAL_STORAGE_PATH, LOCAL_OBJECT_URL | 17 from util import STORAGE_URL, OBJECT_URL, LOCAL_STORAGE_PATH, LOCAL_OBJECT_URL |
18 from util import read_deps, merge_deps, print_deps, platform_tag | 18 from util import read_deps, merge_deps, print_deps, platform_tag |
19 | 19 |
20 LOGGER = logging.getLogger(__name__) | 20 LOGGER = logging.getLogger(__name__) |
21 | 21 |
22 # /path/to/recipes-py | 22 # /path/to/recipes-py |
23 ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 23 ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
24 | 24 |
25 PYTHON_BAT_WIN = '@%~dp0\\..\\Scripts\\python.exe %*' | 25 PYTHON_BAT_WIN = '@%~dp0\\..\\Scripts\\python.exe %*' |
26 | 26 |
| 27 IS_WINDOWS = sys.platform.startswith('win') |
| 28 |
| 29 EXE_SUFFIX = '.exe' if IS_WINDOWS else '' |
| 30 |
27 | 31 |
28 class NoWheelException(Exception): | 32 class NoWheelException(Exception): |
29 def __init__(self, name, version, build, source_sha): | 33 def __init__(self, name, version, build, source_sha): |
30 super(NoWheelException, self).__init__( | 34 super(NoWheelException, self).__init__( |
31 'No matching wheel found for (%s==%s (build %s_%s))' % | 35 'No matching wheel found for (%s==%s (build %s_%s))' % |
32 (name, version, build, source_sha)) | 36 (name, version, build, source_sha)) |
33 | 37 |
34 | 38 |
35 def check_pydistutils(): | 39 def check_pydistutils(): |
36 if os.path.exists(os.path.expanduser('~/.pydistutils.cfg')): | 40 if os.path.exists(os.path.expanduser('~/.pydistutils.cfg')): |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 72 |
69 | 73 |
70 def sha_for(deps_entry): | 74 def sha_for(deps_entry): |
71 if 'rev' in deps_entry: | 75 if 'rev' in deps_entry: |
72 return deps_entry['rev'] | 76 return deps_entry['rev'] |
73 else: | 77 else: |
74 return deps_entry['gs'].split('.')[0] | 78 return deps_entry['gs'].split('.')[0] |
75 | 79 |
76 | 80 |
77 def install(deps, cache_root): | 81 def install(deps, cache_root): |
78 bin_dir = 'Scripts' if sys.platform.startswith('win') else 'bin' | 82 bin_dir = 'Scripts' if IS_WINDOWS else 'bin' |
| 83 python = os.path.join(sys.prefix, bin_dir, 'python%s' % (EXE_SUFFIX,)) |
79 pip = os.path.join(sys.prefix, bin_dir, 'pip') | 84 pip = os.path.join(sys.prefix, bin_dir, 'pip') |
80 | 85 |
81 requirements = [] | 86 requirements = [] |
82 # TODO(iannucci): Do this as a requirements.txt | 87 # TODO(iannucci): Do this as a requirements.txt |
83 for name, deps_entry in deps.iteritems(): | 88 for name, deps_entry in deps.iteritems(): |
84 if not deps_entry.get('implicit'): | 89 if not deps_entry.get('implicit'): |
85 requirements.append('%s==%s' % (name, deps_entry['version'])) | 90 requirements.append('%s==%s' % (name, deps_entry['version'])) |
86 | 91 |
87 if not cache_root: | 92 if not cache_root: |
88 cache_root = os.path.join(ROOT, '.bootstrap_cache') | 93 cache_root = os.path.join(ROOT, '.bootstrap_cache') |
89 wheel_cache_dir = os.path.join(cache_root, 'wheels') | 94 wheel_cache_dir = os.path.join(cache_root, 'wheels') |
90 download_cache_dir = os.path.join(cache_root, 'download_cache') | 95 download_cache_dir = os.path.join(cache_root, 'download_cache') |
91 | 96 |
92 for path in (wheel_cache_dir, download_cache_dir): | 97 for path in (wheel_cache_dir, download_cache_dir): |
93 if not os.path.exists(path): | 98 if not os.path.exists(path): |
94 os.makedirs(path) | 99 os.makedirs(path) |
95 | 100 |
96 env = os.environ.copy() | 101 env = os.environ.copy() |
97 env['PIP_CACHE_DIR'] = download_cache_dir | 102 env['PIP_CACHE_DIR'] = download_cache_dir |
98 | 103 |
99 # Download the package into our cache directory. | 104 # Download the package into our cache directory. |
100 subprocess.check_call([ | 105 subprocess.check_call([ |
101 pip, 'download', | 106 python, pip, 'download', |
102 '--find-links', 'file://' + wheel_cache_dir, | 107 '--find-links', 'file://' + wheel_cache_dir, |
103 '--dest', wheel_cache_dir, | 108 '--dest', wheel_cache_dir, |
104 ] + requirements, | 109 ] + requirements, |
105 env=env) | 110 env=env) |
106 | 111 |
107 # Install the downloaded packages. | 112 # Install the downloaded packages. |
108 subprocess.check_call([ | 113 subprocess.check_call([ |
109 pip, 'install', | 114 python, pip, 'install', |
110 '--find-links', 'file://' + wheel_cache_dir, | 115 '--find-links', 'file://' + wheel_cache_dir, |
111 '--no-index', | 116 '--no-index', |
112 ] + requirements, | 117 ] + requirements, |
113 env=env) | 118 env=env) |
114 | 119 |
115 | 120 |
116 def activate_env(env, deps, quiet=False, cache_root=None): | 121 def activate_env(env, deps, quiet=False, cache_root=None): |
117 if hasattr(sys, 'real_prefix'): | 122 if hasattr(sys, 'real_prefix'): |
118 LOGGER.error('Already activated environment!') | 123 LOGGER.error('Already activated environment!') |
119 return | 124 return |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 216 |
212 deps = merge_deps(map(os.path.abspath, opts.deps_file)) | 217 deps = merge_deps(map(os.path.abspath, opts.deps_file)) |
213 activate_env(os.path.abspath(opts.env_path), deps, opts.quiet, | 218 activate_env(os.path.abspath(opts.env_path), deps, opts.quiet, |
214 cache_root=os.path.abspath(opts.cache_root)) | 219 cache_root=os.path.abspath(opts.cache_root)) |
215 | 220 |
216 | 221 |
217 if __name__ == '__main__': | 222 if __name__ == '__main__': |
218 logging.basicConfig() | 223 logging.basicConfig() |
219 LOGGER.setLevel(logging.DEBUG) | 224 LOGGER.setLevel(logging.DEBUG) |
220 sys.exit(main(sys.argv[1:])) | 225 sys.exit(main(sys.argv[1:])) |
OLD | NEW |