15
15
import glob
16
16
import os
17
17
import shutil
18
- import stat
19
18
import subprocess
20
19
import sys
20
+ import typing
21
21
import zipfile
22
22
23
23
import setuptools
24
24
from wheel .bdist_wheel import bdist_wheel as BDistWheelCommand
25
25
26
- driver_version = "0.170 .0-next.1608058598043 "
26
+ driver_version = "1.8 .0-next-1609895143000 "
27
27
28
28
29
29
with open ("README.md" , "r" , encoding = "utf-8" ) as fh :
30
30
long_description = fh .read ()
31
31
32
+ NoneType = type (None )
33
+
34
+
35
+ def extractall (zip : typing .Any , path : str ) -> NoneType :
36
+ for name in zip .namelist ():
37
+ member = zip .getinfo (name )
38
+ extracted_path = zip ._extract_member (member , path , None )
39
+ attr = member .external_attr >> 16
40
+ if attr != 0 :
41
+ os .chmod (extracted_path , attr )
42
+
32
43
33
44
class PlaywrightBDistWheelCommand (BDistWheelCommand ):
34
45
def run (self ) -> None :
@@ -42,9 +53,12 @@ def run(self) -> None:
42
53
os .makedirs ("driver" , exist_ok = True )
43
54
os .makedirs ("playwright/driver" , exist_ok = True )
44
55
for platform in ["mac" , "linux" , "win32" , "win32_x64" ]:
45
- zip_file = f"playwright-cli- { driver_version } -{ platform } .zip"
56
+ zip_file = f"playwright-{ driver_version } -{ platform } .zip"
46
57
if not os .path .exists ("driver/" + zip_file ):
47
- url = "https://playwright.azureedge.net/builds/cli/next/" + zip_file
58
+ url = "https://playwright.azureedge.net/builds/driver/"
59
+ if "-next" in driver_version :
60
+ url = url + "next/"
61
+ url = url + zip_file
48
62
print ("Fetching " , url )
49
63
subprocess .check_call (
50
64
["curl" , "--http1.1" , url , "-o" , "driver/" + zip_file ]
@@ -57,19 +71,12 @@ def run(self) -> None:
57
71
"win32" : "win32_x64" if sys .maxsize > 2 ** 32 else "win32" ,
58
72
}
59
73
for platform in ["mac" , "linux" , "win32" , "win32_x64" ]:
60
- zip_file = f"driver/playwright-cli- { driver_version } -{ platform } .zip"
74
+ zip_file = f"driver/playwright-{ driver_version } -{ platform } .zip"
61
75
with zipfile .ZipFile (zip_file , "r" ) as zip :
62
- zip . extractall (f"driver/{ platform } " )
76
+ extractall (zip , f"driver/{ platform } " )
63
77
if platform_map [sys .platform ] == platform :
64
78
with zipfile .ZipFile (zip_file , "r" ) as zip :
65
- zip .extractall ("playwright/driver" )
66
- for file in os .listdir ("playwright/driver" ):
67
- if file == "playwright-cli" or file .startswith ("ffmpeg" ):
68
- print (f"playwright/driver/{ file } " )
69
- os .chmod (
70
- f"playwright/driver/{ file } " ,
71
- os .stat (f"playwright/driver/{ file } " ).st_mode | stat .S_IEXEC ,
72
- )
79
+ extractall (zip , "playwright/driver" )
73
80
wheel = ""
74
81
if platform == "mac" :
75
82
wheel = "macosx_10_13_x86_64.whl"
@@ -82,14 +89,12 @@ def run(self) -> None:
82
89
wheel_location = without_platform + wheel
83
90
shutil .copy (base_wheel_location , wheel_location )
84
91
with zipfile .ZipFile (wheel_location , "a" ) as zip :
85
- for file in os .listdir (f"driver/{ platform } " ):
86
- from_location = f"driver/{ platform } /{ file } "
87
- to_location = f"playwright/driver/{ file } "
88
- if file == "playwright-cli" or file .startswith ("ffmpeg" ):
89
- os .chmod (
90
- from_location , os .stat (from_location ).st_mode | stat .S_IEXEC
91
- )
92
- zip .write (from_location , to_location )
92
+ driver_root = os .path .abspath (f"driver/{ platform } " )
93
+ for dir_path , dirs , files in os .walk (driver_root ):
94
+ for file in files :
95
+ from_path = os .path .join (dir_path , file )
96
+ to_path = os .path .relpath (from_path , driver_root )
97
+ zip .write (from_path , f"playwright/driver/{ to_path } " )
93
98
os .remove (base_wheel_location )
94
99
95
100
0 commit comments