@@ -26,12 +26,12 @@ def calculate_hash(url):
2626 return h .hexdigest ()
2727
2828
29- def get_chrome_milestone (channel = None ):
30- if channel is None :
31- parser = argparse . ArgumentParser ( )
32- parser .add_argument ( '--chrome_channel' , default = 'Stable' , help = 'Set the Chrome channel' )
33- args = parser . parse_args ()
34- channel = args . chrome_channel
29+ def get_chrome_milestone ():
30+ parser = argparse . ArgumentParser ()
31+ parser . add_argument ( '--chrome_channel' , default = 'Stable' , help = 'Set the Chrome channel' )
32+ args = parser .parse_args ( )
33+ channel = args . chrome_channel
34+
3535 r = http .request (
3636 "GET" , f"https://chromiumdash.appspot.com/fetch_releases?channel={ channel } &num=1&platform=Mac,Linux"
3737 )
@@ -48,15 +48,18 @@ def get_chrome_milestone(channel=None):
4848 )[- 1 ]
4949
5050
51- def chromedriver (selected_version , workspace_prefix = "" ):
51+ def chromedriver (selected_version ):
5252 content = ""
5353
5454 drivers = selected_version ["downloads" ]["chromedriver" ]
5555
5656 linux = [d ["url" ] for d in drivers if d ["platform" ] == "linux64" ][0 ]
5757 sha = calculate_hash (linux )
58- content = content + """ http_archive(
59- name = "linux_%schromedriver",
58+
59+ content = (
60+ content
61+ + """ http_archive(
62+ name = "linux_chromedriver",
6063 url = "%s",
6164 sha256 = "%s",
6265 strip_prefix = "chromedriver-linux64",
@@ -72,12 +75,17 @@ def chromedriver(selected_version, workspace_prefix=""):
7275)
7376\" \" \" ,
7477 )
75- """ % (workspace_prefix , linux , sha )
78+ """
79+ % (linux , sha )
80+ )
81+
7682 mac = [d ["url" ] for d in drivers if d ["platform" ] == "mac-x64" ][0 ]
7783 sha = calculate_hash (mac )
78- content = content + """
84+ content = (
85+ content
86+ + """
7987 http_archive(
80- name = "mac_%schromedriver ",
88+ name = "mac_chromedriver ",
8189 url = "%s",
8290 sha256 = "%s",
8391 strip_prefix = "chromedriver-mac-x64",
@@ -93,19 +101,22 @@ def chromedriver(selected_version, workspace_prefix=""):
93101)
94102\" \" \" ,
95103 )
96- """ % (workspace_prefix , mac , sha )
104+ """
105+ % (mac , sha )
106+ )
107+
97108 return content
98109
99110
100- def chrome (selected_version , workspace_prefix = "" ):
111+ def chrome (selected_version ):
101112 chrome_downloads = selected_version ["downloads" ]["chrome" ]
102113
103114 linux = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "linux64" ][0 ]
104115 sha = calculate_hash (linux )
105116
106117 content = """
107118 http_archive(
108- name = "linux_%schrome ",
119+ name = "linux_chrome ",
109120 url = "%s",
110121 sha256 = "%s",
111122 build_file_content = \" \" \"
@@ -126,11 +137,16 @@ def chrome(selected_version, workspace_prefix=""):
126137\" \" \" ,
127138 )
128139
129- """ % (workspace_prefix , linux , sha )
140+ """ % (
141+ linux ,
142+ sha ,
143+ )
144+
130145 mac = [d ["url" ] for d in chrome_downloads if d ["platform" ] == "mac-x64" ][0 ]
131146 sha = calculate_hash (mac )
147+
132148 content += """ http_archive(
133- name = "mac_%schrome ",
149+ name = "mac_chrome ",
134150 url = "%s",
135151 sha256 = "%s",
136152 strip_prefix = "chrome-mac-x64",
@@ -151,7 +167,11 @@ def chrome(selected_version, workspace_prefix=""):
151167\" \" \" ,
152168 )
153169
154- """ % (workspace_prefix , mac , sha )
170+ """ % (
171+ mac ,
172+ sha ,
173+ )
174+
155175 return content
156176
157177
@@ -217,7 +237,12 @@ def edge():
217237)
218238\" \" \" ,
219239 )
220- """ % (mac , mac_hash .lower (), mac_version )
240+ """ % (
241+ mac ,
242+ mac_hash .lower (),
243+ mac_version ,
244+ )
245+
221246 if linux and linux_hash :
222247 content += """
223248 deb_archive(
@@ -241,7 +266,11 @@ def edge():
241266)
242267\" \" \" ,
243268 )
244- """ % (linux , linux_hash .lower ())
269+ """ % (
270+ linux ,
271+ linux_hash .lower ()
272+ )
273+
245274 return content
246275
247276
@@ -256,7 +285,9 @@ def edgedriver():
256285
257286 linux = "https://msedgedriver.azureedge.net/%s/edgedriver_linux64.zip" % linux_version
258287 sha = calculate_hash (linux )
259- content = content + """
288+ content = (
289+ content
290+ + """
260291 http_archive(
261292 name = "linux_edgedriver",
262293 url = "%s",
@@ -273,12 +304,17 @@ def edgedriver():
273304)
274305\" \" \" ,
275306 )
276- """ % (linux , sha )
307+ """
308+ % (linux , sha )
309+ )
310+
277311 r = http .request ("GET" , f"https://msedgedriver.azureedge.net/LATEST_RELEASE_{ major_version } _MACOS" )
278312 macos_version = r .data .decode ("utf-16" ).strip ()
279313 mac = "https://msedgedriver.azureedge.net/%s/edgedriver_mac64.zip" % macos_version
280314 sha = calculate_hash (mac )
281- content = content + """
315+ content = (
316+ content
317+ + """
282318 http_archive(
283319 name = "mac_edgedriver",
284320 url = "%s",
@@ -295,7 +331,9 @@ def edgedriver():
295331)
296332\" \" \" ,
297333 )
298- """ % (mac , sha )
334+ """
335+ % (mac , sha )
336+ )
299337 return content
300338
301339
@@ -307,7 +345,9 @@ def geckodriver():
307345 if a ["name" ].endswith ("-linux64.tar.gz" ):
308346 url = a ["browser_download_url" ]
309347 sha = calculate_hash (url )
310- content = content + """ http_archive(
348+ content = (
349+ content
350+ + """ http_archive(
311351 name = "linux_geckodriver",
312352 url = "%s",
313353 sha256 = "%s",
@@ -323,11 +363,16 @@ def geckodriver():
323363)
324364\" \" \" ,
325365 )
326- """ % (url , sha )
366+ """
367+ % (url , sha )
368+ )
369+
327370 if a ["name" ].endswith ("-macos.tar.gz" ):
328371 url = a ["browser_download_url" ]
329372 sha = calculate_hash (url )
330- content = content + """
373+ content = (
374+ content
375+ + """
331376 http_archive(
332377 name = "mac_geckodriver",
333378 url = "%s",
@@ -344,7 +389,9 @@ def geckodriver():
344389)
345390\" \" \" ,
346391 )
347- """ % (url , sha )
392+ """
393+ % (url , sha )
394+ )
348395 return content
349396
350397
@@ -370,9 +417,11 @@ def firefox_version_data():
370417
371418def firefox_linux (version ):
372419 if int (version .split ("." )[0 ]) < 135 :
373- return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" % (version , version )
420+ return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.bz2" % (
421+ version , version )
374422 else :
375- return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.xz" % (version , version )
423+ return "https://ftp.mozilla.org/pub/firefox/releases/%s/linux-x86_64/en-US/firefox-%s.tar.xz" % (
424+ version , version )
376425
377426
378427def firefox_mac (version ):
@@ -381,7 +430,10 @@ def firefox_mac(version):
381430
382431def print_firefox (version , workspace_name , sha_linux , sha_mac ):
383432 content = ""
384- content = content + f""" http_archive(
433+
434+ content = (
435+ content
436+ + f""" http_archive(
385437 name = "linux_{ workspace_name } firefox",
386438 url = "{ firefox_linux (version )} ",
387439 sha256 = "{ sha_linux } ",
@@ -404,7 +456,11 @@ def print_firefox(version, workspace_name, sha_linux, sha_mac):
404456 )
405457
406458"""
407- content = content + f""" dmg_archive(
459+ )
460+
461+ content = (
462+ content
463+ + f""" dmg_archive(
408464 name = "mac_{ workspace_name } firefox",
409465 url = "{ firefox_mac (version )} ",
410466 sha256 = "{ sha_mac } ",
@@ -422,6 +478,8 @@ def print_firefox(version, workspace_name, sha_linux, sha_mac):
422478 )
423479
424480"""
481+ )
482+
425483 return content
426484
427485
@@ -442,13 +500,9 @@ def pin_browsers():
442500 content = content + geckodriver ()
443501 content = content + edge ()
444502 content = content + edgedriver ()
445- chrome_stable = get_chrome_milestone ("Stable" )
446- content = content + chrome (chrome_stable , "" )
447- content = content + chromedriver (chrome_stable , "" )
448- chrome_beta = get_chrome_milestone ("Beta" )
449- if chrome_beta ["version" ] != chrome_stable ["version" ]:
450- content = content + chrome (chrome_beta , "beta_" )
451- content = content + chromedriver (chrome_beta , "beta_" )
503+ chrome_milestone = get_chrome_milestone ()
504+ content = content + chrome (chrome_milestone )
505+ content = content + chromedriver (chrome_milestone )
452506 content += """
453507def _pin_browsers_extension_impl(_ctx):
454508 pin_browsers()
@@ -457,7 +511,9 @@ def _pin_browsers_extension_impl(_ctx):
457511 implementation = _pin_browsers_extension_impl,
458512)
459513"""
514+
460515 current_script_dir = Path (os .path .realpath (__file__ )).parent
461516 target_file_path = current_script_dir .parent / "common/repositories.bzl"
517+
462518 with open (target_file_path , "w" ) as file :
463519 file .write (content )
0 commit comments