|
14 | 14 |
|
15 | 15 | import asyncio
|
16 | 16 | import io
|
| 17 | +import os |
| 18 | +import stat |
17 | 19 | import subprocess
|
18 | 20 | import sys
|
| 21 | +from pathlib import Path |
19 | 22 | from typing import Any
|
20 | 23 |
|
21 | 24 | from greenlet import greenlet
|
|
30 | 33 | from playwright.sync_base import dispatcher_fiber, set_dispatcher_fiber
|
31 | 34 |
|
32 | 35 |
|
33 |
| -def compute_driver_name() -> str: |
| 36 | +def compute_driver_executable() -> Path: |
| 37 | + package_path = get_file_dirname() |
34 | 38 | platform = sys.platform
|
35 | 39 | if platform == "darwin":
|
36 |
| - result = "driver-macos" |
| 40 | + return package_path / "drivers" / "driver-darwin" |
37 | 41 | elif platform == "linux":
|
38 |
| - result = "driver-linux" |
| 42 | + return package_path / "drivers" / "driver-linux" |
39 | 43 | elif platform == "win32":
|
40 |
| - result = "driver-win.exe" |
41 |
| - return result |
| 44 | + result = package_path / "drivers" / "driver-win32-amd64.exe" |
| 45 | + if result.exists(): |
| 46 | + return result |
| 47 | + return package_path / "drivers" / "driver-win32.exe" |
| 48 | + return package_path / "drivers" / "driver-linux" |
42 | 49 |
|
43 | 50 |
|
44 | 51 | async def run_driver_async() -> Connection:
|
45 |
| - package_path = get_file_dirname() |
46 |
| - driver_name = compute_driver_name() |
47 |
| - driver_executable = package_path / "drivers" / driver_name |
| 52 | + driver_executable = compute_driver_executable() |
48 | 53 |
|
49 | 54 | # Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80
|
50 | 55 | def _get_stderr_fileno() -> int:
|
@@ -134,9 +139,12 @@ def main() -> None:
|
134 | 139 | if "install" not in sys.argv:
|
135 | 140 | print('Run "python -m playwright install" to complete installation')
|
136 | 141 | return
|
137 |
| - package_path = get_file_dirname() |
138 |
| - driver_name = compute_driver_name() |
139 |
| - driver_executable = package_path / "drivers" / driver_name |
| 142 | + driver_executable = compute_driver_executable() |
| 143 | + # Fix the executable bit during the installation. |
| 144 | + if not sys.platform == "win32": |
| 145 | + st = os.stat(driver_executable) |
| 146 | + if st.st_mode & stat.S_IEXEC == 0: |
| 147 | + os.chmod(driver_executable, st.st_mode | stat.S_IEXEC) |
140 | 148 | print("Installing the browsers...")
|
141 | 149 | subprocess.check_call(f"{driver_executable} install", shell=True)
|
142 | 150 |
|
|
0 commit comments