forked from openai/retro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis.py
118 lines (95 loc) · 4.23 KB
/
travis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import subprocess
import os
import shlex
import json
import glob
import sys
class Fold:
def __init__(self, name, description=None):
self.fold_name = name
self.description = description or name
def __enter__(self):
print('travis_fold:start:%s\033[33;1m%s\033[0m' % (self.fold_name, self.description), flush=True)
def __exit__(self, exc_type, exc_value, traceback):
print('\ntravis_fold:end:%s\r' % self.fold_name, end='', flush=True)
def call(cmd):
print(' '.join(shlex.quote(p) for p in cmd), flush=True)
subprocess.check_call(cmd)
def get_bucket():
from google.oauth2 import service_account
from google.cloud import storage
credentials_info = json.loads(os.environ['GOOGLE_APPLICATION_CREDENTIALS_DATA'])
credentials = service_account.Credentials.from_service_account_info(credentials_info)
client = storage.Client(credentials=credentials, project=credentials_info['project_id'])
return client.get_bucket('gym-retro')
def upload_to_gcs(patterns, dest):
bucket = get_bucket()
for pattern in patterns:
print('uploading %s to %s' % (pattern, dest), flush=True)
for filepath in glob.glob(pattern):
blob_name = '%s/%s' % (dest, os.path.basename(filepath))
blob = bucket.blob(blob_name)
blob.upload_from_filename(filename=filepath)
blob.make_public()
print('uploaded ', blob.public_url.replace('%2F', '/')) # public_url escapes slashes but that breaks pip install
def test():
import pytest
import retro.testing as testdata
args = []
if os.environ['TRAVIS_BRANCH'] != 'master' or os.environ['TRAVIS_PULL_REQUEST'] != 'false':
check = testdata.branch_new('origin/master')
if check:
args.extend(['-k', ' or '.join(check)])
pytest.main(args)
return not testdata.errors
def main():
os_name = os.environ['TRAVIS_OS_NAME']
cross = os.environ.get('CROSS')
bdist_options = []
with Fold('script.deps', 'Installing dependencies'):
if os_name != 'osx':
os.environ['PATH'] = '/usr/lib/ccache:' + os.environ['PATH']
if os_name == 'osx':
# update brew first, which should install the correct version of ruby
# and avoid the error "Homebrew must be run under Ruby 2.3"
call(['brew', 'update'])
call(['brew', 'install', '[email protected]', 'ccache'])
cmake_options = []
elif os_name == 'linux':
cmake_options = ['-DBUILD_MANYLINUX=ON',
'-DPYTHON_INCLUDE_DIR=%s/include/python%sm' % (sys.base_prefix, os.environ['PYVER'])]
if cross in ('win32', 'win64'):
cmake_options = ['-DCMAKE_TOOLCHAIN_FILE=docker/cmake/%s.cmake' % cross]
if cross == 'win32':
bdist_options = ['--plat-name', 'win32']
if cross == 'win64':
bdist_options = ['--plat-name', 'win_amd64']
else:
raise Exception('unrecognized os name')
with Fold('script.build', 'Building'):
call(['cmake', '.', '-DBUILD_TESTS=ON'] + cmake_options)
call(['python', 'setup.py', '-q', 'build_ext', '-i', '-j3'])
if cross not in ('win64', 'win32'):
call(['pip', 'install', '-e', '.'])
call(['make', '-j3'])
if os.environ['TRAVIS_PULL_REQUEST'] == 'false':
with Fold('script.package', 'Packaging binaries'):
call(['python', 'setup.py', '-q', 'bdist_wheel'] + bdist_options)
if os.environ['TRAVIS_BRANCH'] == 'master':
upload_dir = 'builds'
else:
upload_dir = 'builds/%s' % os.environ['TRAVIS_BRANCH']
if not cross and os_name == 'linux':
call(['auditwheel', 'repair', '-w', 'dist'] + glob.glob('dist/*.whl'))
upload_to_gcs(['dist/*.whl'], upload_dir)
if cross not in ('win64', 'win32'):
with Fold('script.test', 'Running tests'):
call(['ctest', '--verbose', '-E', '\.test']) # Exclude libzip tests
if os_name == 'linux' and not cross:
try:
passed = test()
assert passed
except ImportError:
pass
if __name__ == '__main__':
main()