@@ -37,6 +37,15 @@ def extractall(zip: zipfile.ZipFile, path: str) -> None:
3737
3838
3939class PlaywrightBDistWheelCommand (BDistWheelCommand ):
40+ user_options = BDistWheelCommand .user_options + [
41+ ("all" , "a" , "create wheels for all platforms" )
42+ ]
43+ boolean_options = BDistWheelCommand .boolean_options + ["all" ]
44+
45+ def initialize_options (self ) -> None :
46+ super ().initialize_options ()
47+ self .all = False
48+
4049 def run (self ) -> None :
4150 if os .path .exists ("build" ):
4251 shutil .rmtree ("build" )
@@ -47,7 +56,16 @@ def run(self) -> None:
4756 super ().run ()
4857 os .makedirs ("driver" , exist_ok = True )
4958 os .makedirs ("playwright/driver" , exist_ok = True )
50- for platform in ["mac" , "linux" , "win32" , "win32_x64" ]:
59+ platform_map = {
60+ "darwin" : "mac" ,
61+ "linux" : "linux" ,
62+ "win32" : "win32_x64" if sys .maxsize > 2 ** 32 else "win32" ,
63+ }
64+ if self .all :
65+ platforms = ["mac" , "linux" , "win32" , "win32_x64" ]
66+ else :
67+ platforms = [platform_map [sys .platform ]]
68+ for platform in platforms :
5169 zip_file = f"playwright-{ driver_version } -{ platform } .zip"
5270 if not os .path .exists ("driver/" + zip_file ):
5371 url = "https://playwright.azureedge.net/builds/driver/"
@@ -56,14 +74,10 @@ def run(self) -> None:
5674 print ("Fetching " , url )
5775 # Don't replace this with urllib - Python won't have certificates to do SSL on all platforms.
5876 subprocess .check_call (["curl" , url , "-o" , "driver/" + zip_file ])
59- base_wheel_location = glob .glob ("dist/ *.whl" )[0 ]
77+ base_wheel_location = glob .glob (os . path . join ( self . dist_dir , " *.whl") )[0 ]
6078 without_platform = base_wheel_location [:- 7 ]
61- platform_map = {
62- "darwin" : "mac" ,
63- "linux" : "linux" ,
64- "win32" : "win32_x64" if sys .maxsize > 2 ** 32 else "win32" ,
65- }
66- for platform in ["mac" , "linux" , "win32" , "win32_x64" ]:
79+
80+ for platform in platforms :
6781 zip_file = f"driver/playwright-{ driver_version } -{ platform } .zip"
6882 with zipfile .ZipFile (zip_file , "r" ) as zip :
6983 extractall (zip , f"driver/{ platform } " )
@@ -88,26 +102,25 @@ def run(self) -> None:
88102 from_path = os .path .join (dir_path , file )
89103 to_path = os .path .relpath (from_path , driver_root )
90104 zip .write (from_path , f"playwright/driver/{ to_path } " )
91- if platform == "mac" :
105+ if platform == "mac" and self . all :
92106 # Ship mac both as 10_13 as and 11_0 universal to work across Macs.
93107 universal_location = without_platform + "macosx_11_0_universal2.whl"
94108 shutil .copyfile (wheel_location , universal_location )
95109 with zipfile .ZipFile (universal_location , "a" ) as zip :
96110 zip .writestr ("playwright/driver/README.md" , "Universal Mac package" )
97111
98112 os .remove (base_wheel_location )
99- for whlfile in glob .glob ("dist/*.whl" ):
100-
113+ for whlfile in glob .glob (os .path .join (self .dist_dir , "*.whl" )):
101114 os .makedirs ("wheelhouse" , exist_ok = True )
102115 with InWheel (
103116 in_wheel = whlfile ,
104117 out_wheel = os .path .join ("wheelhouse" , os .path .basename (whlfile )),
105118 ret_self = True ,
106119 ):
107120 print ("Updating RECORD file of %s" % whlfile )
108- shutil .rmtree ("dist" )
121+ shutil .rmtree (self . dist_dir )
109122 print ("Copying new wheels" )
110- shutil .move ("wheelhouse" , "dist" )
123+ shutil .move ("wheelhouse" , self . dist_dir )
111124
112125
113126setuptools .setup (
0 commit comments