OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 DESCRIPTION = '''\ | 6 DESCRIPTION = '''\ |
7 Downloads numpy via pip, packages it as a zip, and updates \ | 7 Downloads numpy via pip, packages it as a zip, and updates \ |
8 binary_dependencies.json and Cloud Storage with the result.''' | 8 binary_dependencies.json and Cloud Storage with the result.''' |
9 | 9 |
10 import argparse | 10 import argparse |
11 import glob | 11 import glob |
12 import os | 12 import os |
13 import shutil | 13 import shutil |
14 import sys | 14 import sys |
15 import virtualenv | 15 import virtualenv |
16 | 16 |
17 # Catapult imports | 17 # Catapult imports |
18 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | 18 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
19 CATAPULT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..')) | 19 CATAPULT_ROOT = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..')) |
20 sys.path.append(os.path.join(CATAPULT_ROOT, 'common', 'py_utils')) | 20 sys.path.append(os.path.join(CATAPULT_ROOT, 'common', 'py_utils')) |
21 from py_utils import shell_util as sh | 21 from py_utils import shell_util as sh |
22 sys.path.append(os.path.join(CATAPULT_ROOT, 'telemetry')) | 22 sys.path.append(os.path.join(CATAPULT_ROOT, 'telemetry')) |
23 from telemetry.core import platform as platform_module | 23 from telemetry.core import platform as platform_module |
24 sys.path.append(os.path.join(CATAPULT_ROOT, 'dependency_manager')) | 24 sys.path.append(os.path.join(CATAPULT_ROOT, 'dependency_manager')) |
25 from dependency_manager import base_config | 25 from dependency_manager import base_config |
26 | 26 |
| 27 class RollError(Exception): |
| 28 pass |
| 29 |
27 # Dependency update helper | 30 # Dependency update helper |
28 def update_dependency(dependency, path, version): | 31 def update_dependency(dependency, path, version): |
29 config = os.path.join(CATAPULT_ROOT, 'telemetry', 'telemetry', 'internal', | 32 config = os.path.join(CATAPULT_ROOT, 'telemetry', 'telemetry', 'internal', |
30 'binary_dependencies.json') | 33 'binary_dependencies.json') |
31 | 34 |
32 os_name = platform_module.GetHostPlatform().GetOSName() | 35 os_name = platform_module.GetHostPlatform().GetOSName() |
33 arch_name = platform_module.GetHostPlatform().GetArchName() | 36 arch_name = platform_module.GetHostPlatform().GetArchName() |
34 platform = "{}_{}".format(os_name, arch_name) | 37 platform = "{}_{}".format(os_name, arch_name) |
35 | 38 |
36 c = base_config.BaseConfig(config, writable=True) | 39 c = base_config.BaseConfig(config, writable=True) |
37 c.AddCloudStorageDependencyUpdateJob( | 40 try: |
38 dependency, platform, path, version=version, execute_job=True) | 41 old_version = c.GetVersion(dependency, platform) |
| 42 print 'Updating from version: {}'.format(old_version) |
| 43 except ValueError: |
| 44 raise RollError( |
| 45 ('binary_dependencies.json entry for {} missing or invalid; please add ' |
| 46 'it first! (need download_path and path_within_archive)') |
| 47 .format(platform)) |
| 48 |
| 49 if path: |
| 50 c.AddCloudStorageDependencyUpdateJob( |
| 51 dependency, platform, path, version=version, execute_job=True) |
| 52 |
| 53 def verify_dependency_entry(dependency): |
| 54 update_dependency(dependency, None, None) |
39 | 55 |
40 # Main | 56 # Main |
41 def main(version): | 57 def main(version): |
| 58 verify_dependency_entry('numpy') |
| 59 |
42 outdir = os.path.join(SCRIPT_DIR, 'lib') | 60 outdir = os.path.join(SCRIPT_DIR, 'lib') |
43 if os.path.exists(outdir): | 61 if os.path.exists(outdir): |
44 shutil.rmtree(outdir) | 62 shutil.rmtree(outdir) |
45 os.mkdir(outdir) | 63 os.mkdir(outdir) |
46 | 64 |
47 zip_full_base = os.path.join(outdir, 'numpy') | 65 zip_full_base = os.path.join(outdir, 'numpy') |
48 zip_result = None | 66 zip_result = None |
49 | 67 |
50 with sh.ScopedTempDir(): | 68 with sh.ScopedTempDir(): |
51 virtualenv.create_environment('env') | 69 virtualenv.create_environment('env', site_packages=False) |
52 with sh.ScopedChangeDir('env'): | 70 with sh.ScopedChangeDir('env'): |
53 sh.CallProgram(['bin', 'pip'], 'install', 'numpy=={}'.format(version)) | 71 if os.path.isdir('bin'): # Linux/Mac |
54 root_dir = glob.glob(os.path.join('lib', 'python2.*', 'site-packages')) | 72 bin_dir = 'bin' |
| 73 root_dir = glob.glob(os.path.join('lib', 'python2.*', 'site-packages')) |
| 74 elif os.path.isdir('Scripts'): # Windows |
| 75 bin_dir = 'Scripts' |
| 76 root_dir = glob.glob(os.path.join('Lib', 'site-packages')) |
| 77 else: |
| 78 raise RollError("Can't find the bin directory at bin/ or Scripts/") |
| 79 |
| 80 activate_this = os.path.join(bin_dir, 'activate_this.py') |
| 81 execfile(activate_this, dict(__file__=activate_this)) |
| 82 |
| 83 sh.CallProgram(['pip'], 'install', 'numpy=={}'.format(version)) |
55 if len(root_dir) != 1: | 84 if len(root_dir) != 1: |
56 raise Exception('Expected one glob match, found ' + len(root_dir)) | 85 raise RollError( |
| 86 'Expected one glob match, found {}'.format(len(root_dir))) |
57 root_dir = root_dir[0] | 87 root_dir = root_dir[0] |
58 print 'Zipping result...' | 88 print 'Zipping result...' |
59 zip_result = shutil.make_archive( | 89 zip_result = shutil.make_archive( |
60 base_name=zip_full_base, | 90 base_name=zip_full_base, |
61 format='zip', | 91 format='zip', |
62 root_dir=root_dir, | 92 root_dir=root_dir, |
63 base_dir='numpy') | 93 base_dir='numpy') |
64 print 'Uploading zip...' | 94 print 'Uploading zip...' |
65 update_dependency('numpy', zip_result, version) | 95 update_dependency('numpy', zip_result, version) |
66 | 96 |
67 print '''\ | 97 print '''\ |
68 Don't forget to run: | 98 Don't forget to run: |
69 $ GYP_DEFINES=fetch_telemetry_dependencies=1 \ | 99 $ GYP_DEFINES=fetch_telemetry_dependencies=1 \ |
70 bin/fetch_telemetry_binary_dependencies | 100 bin/fetch_telemetry_binary_dependencies |
71 if you want to use the new dependency version locally!''' | 101 if you want to use the new dependency version locally!''' |
72 | 102 |
73 if __name__ == '__main__': | 103 if __name__ == '__main__': |
74 VERSION_HELP = '''\ | 104 VERSION_HELP = '''\ |
75 Numpy package version, e.g. 1.11.3. For a release list, see \ | 105 Numpy package version, e.g. 1.11.3. For a release list, see \ |
76 <https://github.com/numpy/numpy/tree/master/doc/release>. \ | 106 <https://github.com/numpy/numpy/tree/master/doc/release>. \ |
77 For version support, see \ | 107 For version support, see \ |
78 `telemetry/telemetry/internal/util/external_modules.py`.''' | 108 `telemetry/telemetry/internal/util/external_modules.py`.''' |
79 | 109 |
80 try: | 110 try: |
81 parser = argparse.ArgumentParser(description=DESCRIPTION) | 111 parser = argparse.ArgumentParser(description=DESCRIPTION) |
82 parser.add_argument('version', help=VERSION_HELP) | 112 parser.add_argument('version', help=VERSION_HELP) |
83 args = parser.parse_args() | 113 args = parser.parse_args() |
84 | 114 |
85 os.chdir(SCRIPT_DIR) | 115 os.chdir(SCRIPT_DIR) |
86 main(args.version) | 116 main(args.version) |
87 except Exception as e: | 117 except RollError as e: |
88 print '{}: {}'.format(type(e).__name__, e.message) | 118 print '{}: {}'.format(type(e).__name__, e.message) |
89 sys.exit(1) | 119 sys.exit(1) |
OLD | NEW |