Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get rid of driver wrapper #2367

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions playwright/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@


def main() -> None:
driver_executable = compute_driver_executable()
driver_executable, driver_cli = compute_driver_executable()
completed_process = subprocess.run(
[str(driver_executable), *sys.argv[1:]], env=get_driver_env()
[driver_executable, driver_cli, *sys.argv[1:]], env=get_driver_env()
)
sys.exit(completed_process.returncode)

Expand Down
13 changes: 7 additions & 6 deletions playwright/_impl/_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
import os
import sys
from pathlib import Path
from typing import Tuple

import playwright
from playwright._repo_version import version


def compute_driver_executable() -> Path:
package_path = Path(inspect.getfile(playwright)).parent
platform = sys.platform
if platform == "win32":
return package_path / "driver" / "playwright.cmd"
return package_path / "driver" / "playwright.sh"
def compute_driver_executable() -> Tuple[str, str]:
driver_path = Path(inspect.getfile(playwright)).parent / "driver"
cli_path = str(driver_path / "package" / "cli.js")
if sys.platform == "win32":
return (str(driver_path / "node.exe"), cli_path)
return (os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node")), cli_path)
dgozman marked this conversation as resolved.
Show resolved Hide resolved


def get_driver_env() -> dict:
Expand Down
12 changes: 5 additions & 7 deletions playwright/_impl/_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import subprocess
import sys
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Callable, Dict, Optional, Union

from playwright._impl._driver import get_driver_env
from playwright._impl._driver import compute_driver_executable, get_driver_env
from playwright._impl._helper import ParsedMessagePayload


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


class PipeTransport(Transport):
def __init__(
self, loop: asyncio.AbstractEventLoop, driver_executable: Path
) -> None:
def __init__(self, loop: asyncio.AbstractEventLoop) -> None:
super().__init__(loop)
self._stopped = False
self._driver_executable = driver_executable

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

executable_path, entrypoint_path = compute_driver_executable()
self._proc = await asyncio.create_subprocess_exec(
str(self._driver_executable),
executable_path,
entrypoint_path,
"run-driver",
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
Expand Down
3 changes: 1 addition & 2 deletions playwright/async_api/_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from typing import Any

from playwright._impl._connection import Connection
from playwright._impl._driver import compute_driver_executable
from playwright._impl._object_factory import create_remote_object
from playwright._impl._transport import PipeTransport
from playwright.async_api._generated import Playwright as AsyncPlaywright
Expand All @@ -32,7 +31,7 @@ async def __aenter__(self) -> AsyncPlaywright:
self._connection = Connection(
None,
create_remote_object,
PipeTransport(loop, compute_driver_executable()),
PipeTransport(loop),
loop,
)
loop.create_task(self._connection.run())
Expand Down
3 changes: 1 addition & 2 deletions playwright/sync_api/_context_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from greenlet import greenlet

from playwright._impl._connection import ChannelOwner, Connection
from playwright._impl._driver import compute_driver_executable
from playwright._impl._errors import Error
from playwright._impl._greenlets import MainGreenlet
from playwright._impl._object_factory import create_remote_object
Expand Down Expand Up @@ -61,7 +60,7 @@ def greenlet_main() -> None:
self._connection = Connection(
dispatcher_fiber,
create_remote_object,
PipeTransport(self._loop, compute_driver_executable()),
PipeTransport(self._loop),
self._loop,
)

Expand Down
Loading