1313# limitations under the License.
1414
1515import asyncio
16- import gzip
17- import os
18- import shutil
19- import stat
2016import subprocess
2117import sys
2218from typing import Any
2521
2622from playwright .async_api import Playwright as AsyncPlaywright
2723from playwright .connection import Connection
28- from playwright .helper import Error , not_installed_error
24+ from playwright .helper import Error
2925from playwright .object_factory import create_remote_object
3026from playwright .path_utils import get_file_dirname
3127from playwright .playwright import Playwright
@@ -47,15 +43,7 @@ def compute_driver_name() -> str:
4743async def run_driver_async () -> Connection :
4844 package_path = get_file_dirname ()
4945 driver_name = compute_driver_name ()
50- driver_executable = package_path / driver_name
51- archive_name = package_path / "drivers" / (driver_name + ".gz" )
52-
53- if not driver_executable .exists () or os .path .getmtime (
54- driver_executable
55- ) < os .path .getmtime (archive_name ):
56- raise not_installed_error (
57- "Playwright requires additional post-installation step to be made."
58- )
46+ driver_executable = package_path / "drivers" / driver_name
5947
6048 proc = await asyncio .create_subprocess_exec (
6149 str (driver_executable ),
@@ -127,24 +115,8 @@ def main() -> None:
127115 return
128116 package_path = get_file_dirname ()
129117 driver_name = compute_driver_name ()
130- driver_executable = package_path / driver_name
131- archive_name = package_path / "drivers" / (driver_name + ".gz" )
132-
133- if not driver_executable .exists () or os .path .getmtime (
134- driver_executable
135- ) < os .path .getmtime (archive_name ):
136- print (f"Extracting { archive_name } into { driver_executable } ..." )
137- with gzip .open (archive_name , "rb" ) as f_in , open (
138- driver_executable , "wb"
139- ) as f_out :
140- shutil .copyfileobj (f_in , f_out )
141-
142- st = os .stat (driver_executable )
143- if st .st_mode & stat .S_IEXEC == 0 :
144- print (f"Making { driver_executable } executable..." )
145- os .chmod (driver_executable , st .st_mode | stat .S_IEXEC )
146-
118+ driver_executable = package_path / "drivers" / driver_name
147119 print ("Installing the browsers..." )
148- subprocess .run (f"{ driver_executable } install" , shell = True )
120+ subprocess .check_call (f"{ driver_executable } install" , shell = True )
149121
150122 print ("Playwright is now ready for use" )
0 commit comments