Skip to content

Commit 09f529a

Browse files
authored
fix: get rid of driver wrapper (#2367)
1 parent 88a82b4 commit 09f529a

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

playwright/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020

2121
def main() -> None:
22-
driver_executable = compute_driver_executable()
22+
driver_executable, driver_cli = compute_driver_executable()
2323
completed_process = subprocess.run(
24-
[str(driver_executable), *sys.argv[1:]], env=get_driver_env()
24+
[driver_executable, driver_cli, *sys.argv[1:]], env=get_driver_env()
2525
)
2626
sys.exit(completed_process.returncode)
2727

playwright/_impl/_driver.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
import os
1717
import sys
1818
from pathlib import Path
19+
from typing import Tuple
1920

2021
import playwright
2122
from playwright._repo_version import version
2223

2324

24-
def compute_driver_executable() -> Path:
25-
package_path = Path(inspect.getfile(playwright)).parent
26-
platform = sys.platform
27-
if platform == "win32":
28-
return package_path / "driver" / "playwright.cmd"
29-
return package_path / "driver" / "playwright.sh"
25+
def compute_driver_executable() -> Tuple[str, str]:
26+
driver_path = Path(inspect.getfile(playwright)).parent / "driver"
27+
cli_path = str(driver_path / "package" / "cli.js")
28+
if sys.platform == "win32":
29+
return (str(driver_path / "node.exe"), cli_path)
30+
return (os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node")), cli_path)
3031

3132

3233
def get_driver_env() -> dict:

playwright/_impl/_transport.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import subprocess
2020
import sys
2121
from abc import ABC, abstractmethod
22-
from pathlib import Path
2322
from typing import Callable, Dict, Optional, Union
2423

25-
from playwright._impl._driver import get_driver_env
24+
from playwright._impl._driver import compute_driver_executable, get_driver_env
2625
from playwright._impl._helper import ParsedMessagePayload
2726

2827

@@ -90,12 +89,9 @@ def deserialize_message(self, data: Union[str, bytes]) -> ParsedMessagePayload:
9089

9190

9291
class PipeTransport(Transport):
93-
def __init__(
94-
self, loop: asyncio.AbstractEventLoop, driver_executable: Path
95-
) -> None:
92+
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
9693
super().__init__(loop)
9794
self._stopped = False
98-
self._driver_executable = driver_executable
9995

10096
def request_stop(self) -> None:
10197
assert self._output
@@ -120,8 +116,10 @@ async def connect(self) -> None:
120116
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
121117
startupinfo.wShowWindow = subprocess.SW_HIDE
122118

119+
executable_path, entrypoint_path = compute_driver_executable()
123120
self._proc = await asyncio.create_subprocess_exec(
124-
str(self._driver_executable),
121+
executable_path,
122+
entrypoint_path,
125123
"run-driver",
126124
stdin=asyncio.subprocess.PIPE,
127125
stdout=asyncio.subprocess.PIPE,

playwright/async_api/_context_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from typing import Any
1717

1818
from playwright._impl._connection import Connection
19-
from playwright._impl._driver import compute_driver_executable
2019
from playwright._impl._object_factory import create_remote_object
2120
from playwright._impl._transport import PipeTransport
2221
from playwright.async_api._generated import Playwright as AsyncPlaywright
@@ -32,7 +31,7 @@ async def __aenter__(self) -> AsyncPlaywright:
3231
self._connection = Connection(
3332
None,
3433
create_remote_object,
35-
PipeTransport(loop, compute_driver_executable()),
34+
PipeTransport(loop),
3635
loop,
3736
)
3837
loop.create_task(self._connection.run())

playwright/sync_api/_context_manager.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from greenlet import greenlet
1919

2020
from playwright._impl._connection import ChannelOwner, Connection
21-
from playwright._impl._driver import compute_driver_executable
2221
from playwright._impl._errors import Error
2322
from playwright._impl._greenlets import MainGreenlet
2423
from playwright._impl._object_factory import create_remote_object
@@ -61,7 +60,7 @@ def greenlet_main() -> None:
6160
self._connection = Connection(
6261
dispatcher_fiber,
6362
create_remote_object,
64-
PipeTransport(self._loop, compute_driver_executable()),
63+
PipeTransport(self._loop),
6564
self._loop,
6665
)
6766

0 commit comments

Comments
 (0)