1
1
import platform
2
- from urllib .request import urlretrieve
3
2
import os
4
- import subprocess as sp
5
- import fnmatch
6
3
7
- import blobfile as bf
8
-
9
- from .common import run , GCS_BUCKET
4
+ from .common import run
10
5
11
6
12
7
SCRIPT_DIR = os .path .dirname (os .path .abspath (__file__ ))
13
8
14
9
15
- # https://stackoverflow.com/a/50135504
16
- def init_vsvars ():
17
- print ("Initializing environment for Visual Studio" )
18
-
19
- vcvars_path = "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Auxiliary/Build/vcvars64.bat"
20
-
21
- env_bat_file_path = "setup_build_environment_temp.bat"
22
- env_txt_file_path = "build_environment_temp.txt"
23
- with open (env_bat_file_path , "w" ) as env_bat_file :
24
- env_bat_file .write ('call "%s"\n ' % vcvars_path )
25
- env_bat_file .write ("set > %s\n " % env_txt_file_path )
26
-
27
- os .system (env_bat_file_path )
28
- with open (env_txt_file_path , "r" ) as env_txt_file :
29
- lines = env_txt_file .read ().splitlines ()
30
-
31
- os .remove (env_bat_file_path )
32
- os .remove (env_txt_file_path )
33
- for line in lines :
34
- if "=" not in line :
35
- print (f"invalid line { repr (line )} " )
36
- continue
37
- k , v = line .split ("=" , 1 )
38
- os .environ [k ] = v
39
-
40
-
41
- def get_var (pattern ):
42
- for key , value in os .environ :
43
- if fnmatch .fnmatch (key , pattern ):
44
- return os .environ [key ]
45
- return None
46
-
47
-
48
- def setup_google_credentials ():
49
- # brew install travis
50
- # travis login --org
51
- # gcloud iam service-accounts create procgen-travis-ci --project <project>
52
- # gcloud iam service-accounts keys create /tmp/key.json --iam-account procgen-travis-ci@<project>.iam.gserviceaccount.com
53
- # gsutil iam ch serviceAccount:procgen-travis-ci@<project>.iam.gserviceaccount.com:objectAdmin gs://{GCS_BUCKET}
54
- # travis encrypt-file --org /tmp/key.json
55
- input_path = os .path .join (SCRIPT_DIR , "key.json.enc" )
56
- output_path = os .path .join (os .getcwd (), "key.json" )
57
- for h in ["d853b3b05b79" , "41b34d34b52c" ]:
58
- key = os .environ .get (f"encrypted_{ h } _key" )
59
- iv = os .environ .get (f"encrypted_{ h } _iv" )
60
- if key is not None :
61
- break
62
- if key is None :
63
- # being compiled on a fork
64
- return False
65
- sp .run (["openssl" , "aes-256-cbc" , "-K" , key , "-iv" , iv , "-in" , input_path , "-out" , output_path , "-d" ], check = True )
66
- os .environ ["GOOGLE_APPLICATION_CREDENTIALS" ] = output_path
67
- return True
68
-
69
-
70
10
def main ():
71
- have_credentials = setup_google_credentials ()
72
-
73
11
os .environ .update (
74
12
{
75
- "CIBW_BUILD" : "cp36 -macosx_x86_64 cp37 -macosx_x86_64 cp38 -macosx_x86_64 cp36-manylinux_x86_64 cp37-manylinux_x86_64 cp38-manylinux_x86_64 cp36-win_amd64 cp37-win_amd64 cp38-win_amd64" ,
76
- "CIBW_BEFORE_BUILD" : "pip install -e procgen-build && python -u -m procgen_build.build_qt --output-dir /tmp/qt5" ,
13
+ "CIBW_BUILD" : "cp37 -macosx_x86_64 cp38 -macosx_x86_64 cp39 -macosx_x86_64 cp310-macosx_x86_64 cp37-manylinux_x86_64 cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64 cp37-win_amd64 cp38-win_amd64 cp39-win_amd64 cp310 -win_amd64" ,
14
+ "CIBW_BEFORE_BUILD" : "pip install -r procgen-build/requirements.txt && pip install - e procgen-build && python -u -m procgen_build.build_qt --output-dir /tmp/qt5" ,
77
15
"CIBW_TEST_EXTRAS" : "test" ,
16
+ "CIBW_BEFORE_TEST" : "pip install -r procgen-build/requirements.txt" ,
78
17
# the --pyargs option causes pytest to use the installed procgen wheel
79
18
"CIBW_TEST_COMMAND" : "pytest --verbose --benchmark-disable --durations=16 --pyargs procgen" ,
80
19
# this is where build-qt.py will put the files
@@ -83,44 +22,23 @@ def main():
83
22
# "CIBW_BUILD_VERBOSITY": "3",
84
23
}
85
24
)
86
- if platform .system () == "Darwin" :
87
- # cibuildwheel's python copy on mac os x sometimes fails with this error:
88
- # [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)
89
- urlretrieve (
90
- "https://curl.haxx.se/ca/cacert.pem" ,
91
- os .environ ["TRAVIS_BUILD_DIR" ] + "/cacert.pem" ,
92
- )
93
- os .environ ["SSL_CERT_FILE" ] = os .environ ["TRAVIS_BUILD_DIR" ] + "/cacert.pem"
94
- elif platform .system () == "Linux" :
95
- # since we're inside a docker container, adjust the credentials path to point at the mounted location
96
- if have_credentials :
97
- os .environ ["CIBW_ENVIRONMENT" ] = (
98
- os .environ ["CIBW_ENVIRONMENT" ]
99
- + " GOOGLE_APPLICATION_CREDENTIALS=/host"
100
- + os .environ ["GOOGLE_APPLICATION_CREDENTIALS" ]
101
- )
25
+ if platform .system () == "Linux" :
102
26
if "TRAVIS_TAG" in os .environ :
103
27
# pass TRAVIS_TAG to the container so that it can build wheels with the correct version number
104
28
os .environ ["CIBW_ENVIRONMENT" ] = (
105
29
os .environ ["CIBW_ENVIRONMENT" ]
106
30
+ " TRAVIS_TAG=" + os .environ ["TRAVIS_TAG" ]
107
31
)
108
- elif platform .system () == "Windows" :
109
- init_vsvars ()
32
+ os .environ ["CIBW_ENVIRONMENT" ] = (
33
+ os .environ ["CIBW_ENVIRONMENT" ]
34
+ + f" CACHE_DIR=/host{ os .getcwd ()} /cache"
35
+ )
36
+ else :
37
+ os .environ ["CACHE_DIR" ] = os .path .join (os .getcwd (), "cache" )
110
38
111
- run ("pip install cibuildwheel==1.4 .1" )
39
+ run ("pip install cibuildwheel==2.3 .1" )
112
40
run ("cibuildwheel --output-dir wheelhouse" )
113
41
114
- if have_credentials :
115
- print ("upload wheels" , platform .system ())
116
- input_dir = "wheelhouse"
117
- output_dir = f"gs://{ GCS_BUCKET } /builds/"
118
- for filename in bf .listdir (input_dir ):
119
- src = bf .join (input_dir , filename )
120
- dst = bf .join (output_dir , filename )
121
- print (src , "=>" , dst )
122
- bf .copy (src , dst , overwrite = True )
123
-
124
42
125
43
if __name__ == "__main__" :
126
44
main ()
0 commit comments