1919import subprocess
2020import sys
2121import zipfile
22- from pathlib import Path
2322from typing import Dict , List
2423
2524from setuptools import setup
26-
2725try :
2826 from auditwheel .wheeltools import InWheel
2927except ImportError :
@@ -60,132 +58,123 @@ def download_driver(zip_name: str) -> None:
6058
6159
6260class PlaywrightBDistWheelCommand (BDistWheelCommand ):
63- user_options = BDistWheelCommand .user_options + [
64- ("all" , "a" , "create wheels for all platforms" )
61+ base_wheel_bundles : List [Dict [str , str ]] = [
62+ {
63+ "wheel" : "macosx_10_13_x86_64.whl" ,
64+ "machine" : "x86_64" ,
65+ "platform" : "darwin" ,
66+ "zip_name" : "mac" ,
67+ },
68+ {
69+ "wheel" : "macosx_11_0_universal2.whl" ,
70+ "machine" : "x86_64" ,
71+ "platform" : "darwin" ,
72+ "zip_name" : "mac" ,
73+ },
74+ {
75+ "wheel" : "macosx_11_0_arm64.whl" ,
76+ "machine" : "arm64" ,
77+ "platform" : "darwin" ,
78+ "zip_name" : "mac-arm64" ,
79+ },
80+ {
81+ "wheel" : "manylinux1_x86_64.whl" ,
82+ "machine" : "x86_64" ,
83+ "platform" : "linux" ,
84+ "zip_name" : "linux" ,
85+ },
86+ {
87+ "wheel" : "manylinux_2_17_aarch64.manylinux2014_aarch64.whl" ,
88+ "machine" : "aarch64" ,
89+ "platform" : "linux" ,
90+ "zip_name" : "linux-arm64" ,
91+ },
92+ {
93+ "wheel" : "win32.whl" ,
94+ "machine" : "i386" ,
95+ "platform" : "win32" ,
96+ "zip_name" : "win32_x64" ,
97+ },
98+ {
99+ "wheel" : "win_amd64.whl" ,
100+ "machine" : "amd64" ,
101+ "platform" : "win32" ,
102+ "zip_name" : "win32_x64" ,
103+ },
65104 ]
66- boolean_options = BDistWheelCommand .boolean_options + ["all" ]
67-
68- def initialize_options (self ) -> None :
69- super ().initialize_options ()
70- self .all = False
71105
72106 def run (self ) -> None :
73- shutil .rmtree ("build" , ignore_errors = True )
74- shutil .rmtree ("dist" , ignore_errors = True )
75- shutil .rmtree ("playwright.egg-info" , ignore_errors = True )
76107 super ().run ()
77108 os .makedirs ("driver" , exist_ok = True )
78109 os .makedirs ("playwright/driver" , exist_ok = True )
79- base_wheel_bundles : List [Dict [str , str ]] = [
80- {
81- "wheel" : "macosx_10_13_x86_64.whl" ,
82- "machine" : "x86_64" ,
83- "platform" : "darwin" ,
84- "zip_name" : "mac" ,
85- },
86- {
87- "wheel" : "macosx_11_0_universal2.whl" ,
88- "machine" : "x86_64" ,
89- "platform" : "darwin" ,
90- "zip_name" : "mac" ,
91- },
92- {
93- "wheel" : "macosx_11_0_arm64.whl" ,
94- "machine" : "arm64" ,
95- "platform" : "darwin" ,
96- "zip_name" : "mac-arm64" ,
97- },
98- {
99- "wheel" : "manylinux1_x86_64.whl" ,
100- "machine" : "x86_64" ,
101- "platform" : "linux" ,
102- "zip_name" : "linux" ,
103- },
104- {
105- "wheel" : "manylinux_2_17_aarch64.manylinux2014_aarch64.whl" ,
106- "machine" : "aarch64" ,
107- "platform" : "linux" ,
108- "zip_name" : "linux-arm64" ,
109- },
110- {
111- "wheel" : "win32.whl" ,
112- "machine" : "i386" ,
113- "platform" : "win32" ,
114- "zip_name" : "win32_x64" ,
115- },
116- {
117- "wheel" : "win_amd64.whl" ,
118- "machine" : "amd64" ,
119- "platform" : "win32" ,
120- "zip_name" : "win32_x64" ,
121- },
122- ]
123- self ._download_and_extract_local_driver (base_wheel_bundles )
124-
125- wheels = base_wheel_bundles
126- if not self .all :
127- # Limit to 1, since for MacOS e.g. we have multiple wheels for the same platform and architecture and Conda expects 1.
128- wheels = list (
110+ self ._download_and_extract_local_driver ()
111+
112+ wheel = None
113+ if os .getenv ("PLAYWRIGHT_TARGET_WHEEL" , None ):
114+ wheel = list (
115+ filter (
116+ lambda wheel : wheel ["wheel" ]
117+ == os .getenv ("PLAYWRIGHT_TARGET_WHEEL" ),
118+ self .base_wheel_bundles ,
119+ )
120+ )[0 ]
121+ else :
122+ wheel = list (
129123 filter (
130124 lambda wheel : wheel ["platform" ] == sys .platform
131125 and wheel ["machine" ] == platform .machine ().lower (),
132- base_wheel_bundles ,
126+ self . base_wheel_bundles ,
133127 )
134- )[:1 ]
135- self ._build_wheels (wheels )
128+ )[0 ]
129+ assert wheel
130+ self ._build_wheel (wheel )
136131
137- def _build_wheels (
132+ def _build_wheel (
138133 self ,
139- wheels : List [ Dict [str , str ] ],
134+ wheel_bundle : Dict [str , str ],
140135 ) -> None :
136+ assert self .dist_dir
141137 base_wheel_location : str = glob .glob (os .path .join (self .dist_dir , "*.whl" ))[0 ]
142138 without_platform = base_wheel_location [:- 7 ]
143- for wheel_bundle in wheels :
144- download_driver (wheel_bundle ["zip_name" ])
145- zip_file = (
146- f"driver/playwright-{ driver_version } -{ wheel_bundle ['zip_name' ]} .zip"
139+ download_driver (wheel_bundle ["zip_name" ])
140+ zip_file = f"driver/playwright-{ driver_version } -{ wheel_bundle ['zip_name' ]} .zip"
141+ with zipfile .ZipFile (zip_file , "r" ) as zip :
142+ extractall (zip , f"driver/{ wheel_bundle ['zip_name' ]} " )
143+ wheel_location = without_platform + wheel_bundle ["wheel" ]
144+ shutil .copy (base_wheel_location , wheel_location )
145+ with zipfile .ZipFile (wheel_location , "a" ) as zip :
146+ driver_root = os .path .abspath (f"driver/{ wheel_bundle ['zip_name' ]} " )
147+ for dir_path , _ , files in os .walk (driver_root ):
148+ for file in files :
149+ from_path = os .path .join (dir_path , file )
150+ to_path = os .path .relpath (from_path , driver_root )
151+ zip .write (from_path , f"playwright/driver/{ to_path } " )
152+ zip .writestr (
153+ "playwright/driver/README.md" ,
154+ f"{ wheel_bundle ['wheel' ]} driver package" ,
147155 )
148- with zipfile .ZipFile (zip_file , "r" ) as zip :
149- extractall (zip , f"driver/{ wheel_bundle ['zip_name' ]} " )
150- wheel_location = without_platform + wheel_bundle ["wheel" ]
151- shutil .copy (base_wheel_location , wheel_location )
152- with zipfile .ZipFile (wheel_location , "a" ) as zip :
153- driver_root = os .path .abspath (f"driver/{ wheel_bundle ['zip_name' ]} " )
154- for dir_path , _ , files in os .walk (driver_root ):
155- for file in files :
156- from_path = os .path .join (dir_path , file )
157- to_path = os .path .relpath (from_path , driver_root )
158- zip .write (from_path , f"playwright/driver/{ to_path } " )
159- zip .writestr (
160- "playwright/driver/README.md" ,
161- f"{ wheel_bundle ['wheel' ]} driver package" ,
162- )
163156 os .remove (base_wheel_location )
164- if InWheel :
165- for whlfile in glob . glob ( os .path . join ( self . dist_dir , "*.whl" )):
166- os . makedirs ( "wheelhouse" , exist_ok = True )
157+ for whlfile in glob . glob ( os . path . join ( self . dist_dir , "*.whl" )) :
158+ os .makedirs ( "wheelhouse" , exist_ok = True )
159+ if InWheel :
167160 with InWheel (
168161 in_wheel = whlfile ,
169162 out_wheel = os .path .join ("wheelhouse" , os .path .basename (whlfile )),
170163 ):
171164 print (f"Updating RECORD file of { whlfile } " )
172- shutil .rmtree (self .dist_dir )
173- print ("Copying new wheels" )
174- shutil .move ("wheelhouse" , self .dist_dir )
175- else :
176- print ("auditwheel not installed, not updating RECORD file" )
165+ print ("Copying new wheels" )
166+ shutil .move ("wheelhouse" , self .dist_dir )
177167
178168 def _download_and_extract_local_driver (
179169 self ,
180- wheels : List [Dict [str , str ]],
181170 ) -> None :
182171 zip_names_for_current_system = set (
183172 map (
184173 lambda wheel : wheel ["zip_name" ],
185174 filter (
186175 lambda wheel : wheel ["machine" ] == platform .machine ().lower ()
187176 and wheel ["platform" ] == sys .platform ,
188- wheels ,
177+ self . base_wheel_bundles ,
189178 ),
190179 )
191180 )
@@ -197,51 +186,11 @@ def _download_and_extract_local_driver(
197186 extractall (zip , "playwright/driver" )
198187
199188
189+ if len (sys .argv ) == 2 and sys .argv [1 ] == "--list-wheels" :
190+ for bundle in PlaywrightBDistWheelCommand .base_wheel_bundles :
191+ print (bundle ["wheel" ])
192+ exit (0 )
193+
200194setup (
201- name = "playwright" ,
202- author = "Microsoft Corporation" ,
203- author_email = "" ,
204- description = "A high-level API to automate web browsers" ,
205- long_description = Path ("README.md" ).read_text (encoding = "utf-8" ),
206- long_description_content_type = "text/markdown" ,
207- license = "Apache-2.0" ,
208- url = "https://github.com/Microsoft/playwright-python" ,
209- project_urls = {
210- "Release notes" : "https://github.com/microsoft/playwright-python/releases" ,
211- },
212- packages = [
213- "playwright" ,
214- "playwright.async_api" ,
215- "playwright.sync_api" ,
216- "playwright._impl" ,
217- "playwright._impl.__pyinstaller" ,
218- ],
219- include_package_data = True ,
220- install_requires = [
221- "greenlet==3.1.1" ,
222- "pyee==12.0.0" ,
223- ],
224- # TODO: Can be removed once we migrate to pypa/build or pypa/installer.
225- setup_requires = ["setuptools-scm==8.1.0" , "wheel==0.45.0" ],
226- classifiers = [
227- "Topic :: Software Development :: Testing" ,
228- "Topic :: Internet :: WWW/HTTP :: Browsers" ,
229- "Intended Audience :: Developers" ,
230- "Programming Language :: Python :: 3" ,
231- "Programming Language :: Python :: 3.9" ,
232- "Programming Language :: Python :: 3.10" ,
233- "Programming Language :: Python :: 3.11" ,
234- "Programming Language :: Python :: 3.12" ,
235- "Programming Language :: Python :: 3.13" ,
236- "License :: OSI Approved :: Apache Software License" ,
237- "Operating System :: OS Independent" ,
238- ],
239- python_requires = ">=3.9" ,
240195 cmdclass = {"bdist_wheel" : PlaywrightBDistWheelCommand },
241- entry_points = {
242- "console_scripts" : [
243- "playwright=playwright.__main__:main" ,
244- ],
245- "pyinstaller40" : ["hook-dirs=playwright._impl.__pyinstaller:get_hook_dirs" ],
246- },
247196)
0 commit comments