@@ -51,67 +51,72 @@ def initialize_options(self) -> None:
51
51
self .all = False
52
52
53
53
def run (self ) -> None :
54
- if os .path .exists ("build" ):
55
- shutil .rmtree ("build" )
56
- if os .path .exists ("dist" ):
57
- shutil .rmtree ("dist" )
58
- if os .path .exists ("playwright.egg-info" ):
59
- shutil .rmtree ("playwright.egg-info" )
54
+ shutil .rmtree ("build" , ignore_errors = True )
55
+ shutil .rmtree ("dist" , ignore_errors = True )
56
+ shutil .rmtree ("playwright.egg-info" , ignore_errors = True )
60
57
super ().run ()
61
58
os .makedirs ("driver" , exist_ok = True )
62
59
os .makedirs ("playwright/driver" , exist_ok = True )
63
- platform_map = {
64
- "darwin" : "mac" ,
65
- "linux" : "linux" ,
66
- "win32" : "win32_x64" if sys .maxsize > 2 ** 32 else "win32" ,
67
- }
68
60
if self .all :
69
- platforms = ["mac" , "linux" , "win32" , "win32_x64" ]
61
+ # If building for all platforms
62
+ platform_map = {
63
+ "darwin" : {
64
+ "zip_name" : "mac" ,
65
+ "wheels" : ["macosx_10_13_x86_64.whl" , "macosx_11_0_universal2.whl" ],
66
+ },
67
+ "linux" : {"zip_name" : "linux" , "wheels" : ["manylinux1_x86_64.whl" ]},
68
+ "win32" : {
69
+ "zip_name" : "win32_x64" ,
70
+ "wheels" : ["win32.whl" , "win_amd64.whl" ],
71
+ },
72
+ }
73
+ platforms = [* platform_map .values ()]
70
74
else :
75
+ # If building for only current platform
76
+ platform_map = {
77
+ "darwin" : {
78
+ "zip_name" : "mac" ,
79
+ "wheels" : ["macosx_10_13_x86_64.whl" ],
80
+ },
81
+ "linux" : {"zip_name" : "linux" , "wheels" : ["manylinux1_x86_64.whl" ]},
82
+ "win32" : {
83
+ "zip_name" : "win32_x64" ,
84
+ "wheels" : ["win_amd64.whl" ],
85
+ },
86
+ }
71
87
platforms = [platform_map [sys .platform ]]
72
88
for platform in platforms :
73
- zip_file = f"playwright-{ driver_version } -{ platform } .zip"
89
+ zip_file = f"playwright-{ driver_version } -{ platform [ 'zip_name' ] } .zip"
74
90
if not os .path .exists ("driver/" + zip_file ):
75
91
url = "https://playwright.azureedge.net/builds/driver/"
76
- url = url + "next/"
77
- url = url + zip_file
78
- print ("Fetching " , url )
92
+ url += "next/"
93
+ url += zip_file
94
+ print (f "Fetching { url } " )
79
95
# Don't replace this with urllib - Python won't have certificates to do SSL on all platforms.
80
96
subprocess .check_call (["curl" , url , "-o" , "driver/" + zip_file ])
81
97
base_wheel_location = glob .glob (os .path .join (self .dist_dir , "*.whl" ))[0 ]
82
98
without_platform = base_wheel_location [:- 7 ]
83
99
84
100
for platform in platforms :
85
- zip_file = f"driver/playwright-{ driver_version } -{ platform } .zip"
101
+ zip_file = f"driver/playwright-{ driver_version } -{ platform [ 'zip_name' ] } .zip"
86
102
with zipfile .ZipFile (zip_file , "r" ) as zip :
87
- extractall (zip , f"driver/{ platform } " )
88
- if platform_map [sys .platform ] == platform :
103
+ extractall (zip , f"driver/{ platform [ 'zip_name' ] } " )
104
+ if platform_map [sys .platform ] in platforms :
89
105
with zipfile .ZipFile (zip_file , "r" ) as zip :
90
106
extractall (zip , "playwright/driver" )
91
- wheel = ""
92
- if platform == "mac" :
93
- wheel = "macosx_10_13_x86_64.whl"
94
- if platform == "linux" :
95
- wheel = "manylinux1_x86_64.whl"
96
- if platform == "win32" :
97
- wheel = "win32.whl"
98
- if platform == "win32_x64" :
99
- wheel = "win_amd64.whl"
100
- wheel_location = without_platform + wheel
101
- shutil .copy (base_wheel_location , wheel_location )
102
- with zipfile .ZipFile (wheel_location , "a" ) as zip :
103
- driver_root = os .path .abspath (f"driver/{ platform } " )
104
- for dir_path , _ , files in os .walk (driver_root ):
105
- for file in files :
106
- from_path = os .path .join (dir_path , file )
107
- to_path = os .path .relpath (from_path , driver_root )
108
- zip .write (from_path , f"playwright/driver/{ to_path } " )
109
- if platform == "mac" and self .all :
110
- # Ship mac both as 10_13 as and 11_0 universal to work across Macs.
111
- universal_location = without_platform + "macosx_11_0_universal2.whl"
112
- shutil .copyfile (wheel_location , universal_location )
113
- with zipfile .ZipFile (universal_location , "a" ) as zip :
114
- zip .writestr ("playwright/driver/README.md" , "Universal Mac package" )
107
+ for wheel in platform ["wheels" ]:
108
+ wheel_location = without_platform + wheel
109
+ shutil .copy (base_wheel_location , wheel_location )
110
+ with zipfile .ZipFile (wheel_location , "a" ) as zip :
111
+ driver_root = os .path .abspath (f"driver/{ platform ['zip_name' ]} " )
112
+ for dir_path , _ , files in os .walk (driver_root ):
113
+ for file in files :
114
+ from_path = os .path .join (dir_path , file )
115
+ to_path = os .path .relpath (from_path , driver_root )
116
+ zip .write (from_path , f"playwright/driver/{ to_path } " )
117
+ zip .writestr (
118
+ "playwright/driver/README.md" , f"{ wheel } driver package"
119
+ )
115
120
116
121
os .remove (base_wheel_location )
117
122
if InWheel :
@@ -121,7 +126,7 @@ def run(self) -> None:
121
126
in_wheel = whlfile ,
122
127
out_wheel = os .path .join ("wheelhouse" , os .path .basename (whlfile )),
123
128
):
124
- print ("Updating RECORD file of %s" % whlfile )
129
+ print (f "Updating RECORD file of { whlfile } " )
125
130
shutil .rmtree (self .dist_dir )
126
131
print ("Copying new wheels" )
127
132
shutil .move ("wheelhouse" , self .dist_dir )
0 commit comments