1414https://github.com/pytorch/vision/pull/1321#issuecomment-531033978
1515"""
1616
17+ import os .path
18+
1719import jinja2
18- from jinja2 import select_autoescape
1920import yaml
20- import os . path
21+ from jinja2 import select_autoescape
2122
2223
2324PYTHON_VERSIONS = ["3.6" , "3.7" , "3.8" , "3.9" ]
2425
2526RC_PATTERN = r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
2627
2728
28- def build_workflows (prefix = '' , filter_branch = None , upload = False , indentation = 6 , windows_latest_only = False ):
29+ def build_workflows (prefix = "" , filter_branch = None , upload = False , indentation = 6 , windows_latest_only = False ):
2930 w = []
3031 for btype in ["wheel" , "conda" ]:
3132 for os_type in ["linux" , "macos" , "win" ]:
3233 python_versions = PYTHON_VERSIONS
33- cu_versions_dict = {"linux" : ["cpu" , "cu102" , "cu111" , "cu113" , "rocm4.1" , "rocm4.2" ],
34- "win" : ["cpu" , "cu102" , "cu111" , "cu113" ],
35- "macos" : ["cpu" ]}
34+ cu_versions_dict = {
35+ "linux" : ["cpu" , "cu102" , "cu111" , "cu113" , "rocm4.1" , "rocm4.2" ],
36+ "win" : ["cpu" , "cu102" , "cu111" , "cu113" ],
37+ "macos" : ["cpu" ],
38+ }
3639 cu_versions = cu_versions_dict [os_type ]
3740 for python_version in python_versions :
3841 for cu_version in cu_versions :
3942 # ROCm conda packages not yet supported
40- if cu_version .startswith (' rocm' ) and btype == "conda" :
43+ if cu_version .startswith (" rocm" ) and btype == "conda" :
4144 continue
4245 for unicode in [False ]:
4346 fb = filter_branch
44- if windows_latest_only and os_type == "win" and filter_branch is None and \
45- (python_version != python_versions [- 1 ] or
46- (cu_version not in [cu_versions [0 ], cu_versions [- 1 ]])):
47+ if (
48+ windows_latest_only
49+ and os_type == "win"
50+ and filter_branch is None
51+ and (
52+ python_version != python_versions [- 1 ]
53+ or (cu_version not in [cu_versions [0 ], cu_versions [- 1 ]])
54+ )
55+ ):
4756 fb = "main"
48- if not fb and (os_type == 'linux' and
49- cu_version == 'cpu' and
50- btype == 'wheel' and
51- python_version == '3.7' ):
57+ if not fb and (
58+ os_type == "linux" and cu_version == "cpu" and btype == "wheel" and python_version == "3.7"
59+ ):
5260 # the fields must match the build_docs "requires" dependency
5361 fb = "/.*/"
5462 w += workflow_pair (
55- btype , os_type , python_version , cu_version ,
56- unicode , prefix , upload , filter_branch = fb )
63+ btype , os_type , python_version , cu_version , unicode , prefix , upload , filter_branch = fb
64+ )
5765
5866 if not filter_branch :
5967 # Build on every pull request, but upload only on nightly and tags
60- w += build_doc_job (' /.*/' )
61- w += upload_doc_job (' nightly' )
68+ w += build_doc_job (" /.*/" )
69+ w += upload_doc_job (" nightly" )
6270 return indent (indentation , w )
6371
6472
65- def workflow_pair (btype , os_type , python_version , cu_version , unicode , prefix = '' , upload = False , * , filter_branch = None ):
73+ def workflow_pair (btype , os_type , python_version , cu_version , unicode , prefix = "" , upload = False , * , filter_branch = None ):
6674
6775 w = []
6876 unicode_suffix = "u" if unicode else ""
6977 base_workflow_name = f"{ prefix } binary_{ os_type } _{ btype } _py{ python_version } { unicode_suffix } _{ cu_version } "
7078
71- w .append (generate_base_workflow (
72- base_workflow_name , python_version , cu_version ,
73- unicode , os_type , btype , filter_branch = filter_branch ))
79+ w .append (
80+ generate_base_workflow (
81+ base_workflow_name , python_version , cu_version , unicode , os_type , btype , filter_branch = filter_branch
82+ )
83+ )
7484
7585 if upload :
7686 w .append (generate_upload_workflow (base_workflow_name , os_type , btype , cu_version , filter_branch = filter_branch ))
77- if filter_branch == ' nightly' and os_type in [' linux' , ' win' ]:
78- pydistro = ' pip' if btype == ' wheel' else ' conda'
87+ if filter_branch == " nightly" and os_type in [" linux" , " win" ]:
88+ pydistro = " pip" if btype == " wheel" else " conda"
7989 w .append (generate_smoketest_workflow (pydistro , base_workflow_name , filter_branch , python_version , os_type ))
8090
8191 return w
@@ -85,12 +95,13 @@ def build_doc_job(filter_branch):
8595 job = {
8696 "name" : "build_docs" ,
8797 "python_version" : "3.7" ,
88- "requires" : ["binary_linux_wheel_py3.7_cpu" , ],
98+ "requires" : [
99+ "binary_linux_wheel_py3.7_cpu" ,
100+ ],
89101 }
90102
91103 if filter_branch :
92- job ["filters" ] = gen_filter_branch_tree (filter_branch ,
93- tags_list = RC_PATTERN )
104+ job ["filters" ] = gen_filter_branch_tree (filter_branch , tags_list = RC_PATTERN )
94105 return [{"build_docs" : job }]
95106
96107
@@ -99,12 +110,13 @@ def upload_doc_job(filter_branch):
99110 "name" : "upload_docs" ,
100111 "context" : "org-member" ,
101112 "python_version" : "3.7" ,
102- "requires" : ["build_docs" , ],
113+ "requires" : [
114+ "build_docs" ,
115+ ],
103116 }
104117
105118 if filter_branch :
106- job ["filters" ] = gen_filter_branch_tree (filter_branch ,
107- tags_list = RC_PATTERN )
119+ job ["filters" ] = gen_filter_branch_tree (filter_branch , tags_list = RC_PATTERN )
108120 return [{"upload_docs" : job }]
109121
110122
@@ -122,24 +134,25 @@ def upload_doc_job(filter_branch):
122134def get_manylinux_image (cu_version ):
123135 if cu_version == "cpu" :
124136 return "pytorch/manylinux-cuda102"
125- elif cu_version .startswith ('cu' ):
126- cu_suffix = cu_version [len ('cu' ) :]
137+ elif cu_version .startswith ("cu" ):
138+ cu_suffix = cu_version [len ("cu" ) :]
127139 return f"pytorch/manylinux-cuda{ cu_suffix } "
128- elif cu_version .startswith (' rocm' ):
129- rocm_suffix = cu_version [len (' rocm' ) :]
140+ elif cu_version .startswith (" rocm" ):
141+ rocm_suffix = cu_version [len (" rocm" ) :]
130142 return f"pytorch/manylinux-rocm:{ rocm_suffix } "
131143
132144
133145def get_conda_image (cu_version ):
134146 if cu_version == "cpu" :
135147 return "pytorch/conda-builder:cpu"
136- elif cu_version .startswith ('cu' ):
137- cu_suffix = cu_version [len ('cu' ) :]
148+ elif cu_version .startswith ("cu" ):
149+ cu_suffix = cu_version [len ("cu" ) :]
138150 return f"pytorch/conda-builder:cuda{ cu_suffix } "
139151
140152
141- def generate_base_workflow (base_workflow_name , python_version , cu_version ,
142- unicode , os_type , btype , * , filter_branch = None ):
153+ def generate_base_workflow (
154+ base_workflow_name , python_version , cu_version , unicode , os_type , btype , * , filter_branch = None
155+ ):
143156
144157 d = {
145158 "name" : base_workflow_name ,
@@ -148,7 +161,7 @@ def generate_base_workflow(base_workflow_name, python_version, cu_version,
148161 }
149162
150163 if os_type != "win" and unicode :
151- d ["unicode_abi" ] = '1'
164+ d ["unicode_abi" ] = "1"
152165
153166 if os_type != "win" :
154167 d ["wheel_docker_image" ] = get_manylinux_image (cu_version )
@@ -158,14 +171,12 @@ def generate_base_workflow(base_workflow_name, python_version, cu_version,
158171
159172 if filter_branch is not None :
160173 d ["filters" ] = {
161- "branches" : {
162- "only" : filter_branch
163- },
174+ "branches" : {"only" : filter_branch },
164175 "tags" : {
165176 # Using a raw string here to avoid having to escape
166177 # anything
167178 "only" : r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
168- }
179+ },
169180 }
170181
171182 w = f"binary_{ os_type } _{ btype } "
@@ -186,19 +197,17 @@ def generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, *,
186197 "requires" : [base_workflow_name ],
187198 }
188199
189- if btype == ' wheel' :
190- d ["subfolder" ] = "" if os_type == ' macos' else cu_version + "/"
200+ if btype == " wheel" :
201+ d ["subfolder" ] = "" if os_type == " macos" else cu_version + "/"
191202
192203 if filter_branch is not None :
193204 d ["filters" ] = {
194- "branches" : {
195- "only" : filter_branch
196- },
205+ "branches" : {"only" : filter_branch },
197206 "tags" : {
198207 # Using a raw string here to avoid having to escape
199208 # anything
200209 "only" : r"/v[0-9]+(\.[0-9]+)*-rc[0-9]+/"
201- }
210+ },
202211 }
203212
204213 return {f"binary_{ btype } _upload" : d }
@@ -223,8 +232,7 @@ def generate_smoketest_workflow(pydistro, base_workflow_name, filter_branch, pyt
223232
224233
225234def indent (indentation , data_list ):
226- return ("\n " + " " * indentation ).join (
227- yaml .dump (data_list , default_flow_style = False ).splitlines ())
235+ return ("\n " + " " * indentation ).join (yaml .dump (data_list , default_flow_style = False ).splitlines ())
228236
229237
230238def unittest_workflows (indentation = 6 ):
@@ -239,12 +247,12 @@ def unittest_workflows(indentation=6):
239247 "python_version" : python_version ,
240248 }
241249
242- if device_type == ' gpu' :
250+ if device_type == " gpu" :
243251 if python_version != "3.8" :
244- job [' filters' ] = gen_filter_branch_tree (' main' , ' nightly' )
245- job [' cu_version' ] = ' cu102'
252+ job [" filters" ] = gen_filter_branch_tree (" main" , " nightly" )
253+ job [" cu_version" ] = " cu102"
246254 else :
247- job [' cu_version' ] = ' cpu'
255+ job [" cu_version" ] = " cpu"
248256
249257 jobs .append ({f"unittest_{ os_type } _{ device_type } " : job })
250258
@@ -253,20 +261,17 @@ def unittest_workflows(indentation=6):
253261
254262def cmake_workflows (indentation = 6 ):
255263 jobs = []
256- python_version = ' 3.8'
257- for os_type in [' linux' , ' windows' , ' macos' ]:
264+ python_version = " 3.8"
265+ for os_type in [" linux" , " windows" , " macos" ]:
258266 # Skip OSX CUDA
259- device_types = [' cpu' , ' gpu' ] if os_type != ' macos' else [' cpu' ]
267+ device_types = [" cpu" , " gpu" ] if os_type != " macos" else [" cpu" ]
260268 for device in device_types :
261- job = {
262- 'name' : f'cmake_{ os_type } _{ device } ' ,
263- 'python_version' : python_version
264- }
269+ job = {"name" : f"cmake_{ os_type } _{ device } " , "python_version" : python_version }
265270
266- job [' cu_version' ] = ' cu102' if device == ' gpu' else ' cpu'
267- if device == ' gpu' and os_type == ' linux' :
268- job [' wheel_docker_image' ] = ' pytorch/manylinux-cuda102'
269- jobs .append ({f' cmake_{ os_type } _{ device } ' : job })
271+ job [" cu_version" ] = " cu102" if device == " gpu" else " cpu"
272+ if device == " gpu" and os_type == " linux" :
273+ job [" wheel_docker_image" ] = " pytorch/manylinux-cuda102"
274+ jobs .append ({f" cmake_{ os_type } _{ device } " : job })
270275 return indent (indentation , jobs )
271276
272277
@@ -275,27 +280,27 @@ def ios_workflows(indentation=6, nightly=False):
275280 build_job_names = []
276281 name_prefix = "nightly_" if nightly else ""
277282 env_prefix = "nightly-" if nightly else ""
278- for arch , platform in [(' x86_64' , ' SIMULATOR' ), (' arm64' , 'OS' )]:
279- name = f' { name_prefix } binary_libtorchvision_ops_ios_12.0.0_{ arch } '
283+ for arch , platform in [(" x86_64" , " SIMULATOR" ), (" arm64" , "OS" )]:
284+ name = f" { name_prefix } binary_libtorchvision_ops_ios_12.0.0_{ arch } "
280285 build_job_names .append (name )
281286 build_job = {
282- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-ios-12.0.0-{ arch } ' ,
283- ' ios_arch' : arch ,
284- ' ios_platform' : platform ,
285- ' name' : name ,
287+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-ios-12.0.0-{ arch } " ,
288+ " ios_arch" : arch ,
289+ " ios_platform" : platform ,
290+ " name" : name ,
286291 }
287292 if nightly :
288- build_job [' filters' ] = gen_filter_branch_tree (' nightly' )
289- jobs .append ({' binary_ios_build' : build_job })
293+ build_job [" filters" ] = gen_filter_branch_tree (" nightly" )
294+ jobs .append ({" binary_ios_build" : build_job })
290295
291296 if nightly :
292297 upload_job = {
293- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-ios-12.0.0-upload' ,
294- ' context' : ' org-member' ,
295- ' filters' : gen_filter_branch_tree (' nightly' ),
296- ' requires' : build_job_names ,
298+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-ios-12.0.0-upload" ,
299+ " context" : " org-member" ,
300+ " filters" : gen_filter_branch_tree (" nightly" ),
301+ " requires" : build_job_names ,
297302 }
298- jobs .append ({' binary_ios_upload' : upload_job })
303+ jobs .append ({" binary_ios_upload" : upload_job })
299304 return indent (indentation , jobs )
300305
301306
@@ -305,23 +310,23 @@ def android_workflows(indentation=6, nightly=False):
305310 name_prefix = "nightly_" if nightly else ""
306311 env_prefix = "nightly-" if nightly else ""
307312
308- name = f' { name_prefix } binary_libtorchvision_ops_android'
313+ name = f" { name_prefix } binary_libtorchvision_ops_android"
309314 build_job_names .append (name )
310315 build_job = {
311- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-android' ,
312- ' name' : name ,
316+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-android" ,
317+ " name" : name ,
313318 }
314319
315320 if nightly :
316321 upload_job = {
317- ' build_environment' : f' { env_prefix } binary-libtorchvision_ops-android-upload' ,
318- ' context' : ' org-member' ,
319- ' filters' : gen_filter_branch_tree (' nightly' ),
320- ' name' : f' { name_prefix } binary_libtorchvision_ops_android_upload'
322+ " build_environment" : f" { env_prefix } binary-libtorchvision_ops-android-upload" ,
323+ " context" : " org-member" ,
324+ " filters" : gen_filter_branch_tree (" nightly" ),
325+ " name" : f" { name_prefix } binary_libtorchvision_ops_android_upload" ,
321326 }
322- jobs .append ({' binary_android_upload' : upload_job })
327+ jobs .append ({" binary_android_upload" : upload_job })
323328 else :
324- jobs .append ({' binary_android_build' : build_job })
329+ jobs .append ({" binary_android_build" : build_job })
325330 return indent (indentation , jobs )
326331
327332
@@ -330,15 +335,17 @@ def android_workflows(indentation=6, nightly=False):
330335 env = jinja2 .Environment (
331336 loader = jinja2 .FileSystemLoader (d ),
332337 lstrip_blocks = True ,
333- autoescape = select_autoescape (enabled_extensions = (' html' , ' xml' )),
338+ autoescape = select_autoescape (enabled_extensions = (" html" , " xml" )),
334339 keep_trailing_newline = True ,
335340 )
336341
337- with open (os .path .join (d , 'config.yml' ), 'w' ) as f :
338- f .write (env .get_template ('config.yml.in' ).render (
339- build_workflows = build_workflows ,
340- unittest_workflows = unittest_workflows ,
341- cmake_workflows = cmake_workflows ,
342- ios_workflows = ios_workflows ,
343- android_workflows = android_workflows ,
344- ))
342+ with open (os .path .join (d , "config.yml" ), "w" ) as f :
343+ f .write (
344+ env .get_template ("config.yml.in" ).render (
345+ build_workflows = build_workflows ,
346+ unittest_workflows = unittest_workflows ,
347+ cmake_workflows = cmake_workflows ,
348+ ios_workflows = ios_workflows ,
349+ android_workflows = android_workflows ,
350+ )
351+ )
0 commit comments