From 9c9715c4314b33806ea3dd1f1fc216f61ef68816 Mon Sep 17 00:00:00 2001 From: KRRT7 <106575910+KRRT7@users.noreply.github.com> Date: Fri, 10 May 2024 15:26:00 +0000 Subject: [PATCH 1/3] prepare support for Nuitka --- playwright/_impl/_driver.py | 28 +++++++++++++++++++++++++++- playwright/_impl/_transport.py | 4 ++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/playwright/_impl/_driver.py b/playwright/_impl/_driver.py index 9e8cdc1e7..1108ff262 100644 --- a/playwright/_impl/_driver.py +++ b/playwright/_impl/_driver.py @@ -16,10 +16,36 @@ import os import sys from pathlib import Path -from typing import Tuple +from typing import Tuple, Union import playwright from playwright._repo_version import version +import pathlib + +def get_registry_directory() -> str: + env_defined = os.environ.get('PLAYWRIGHT_BROWSERS_PATH') + path_home = Path.home() + if env_defined == '0': + result = pathlib.Path(__file__).parent.parent.parent.joinpath('.local-browsers') + elif env_defined: + result = pathlib.Path(env_defined) + else: + cache_directory: Union[str, Path] = '' + if os.name == 'posix': + cache_directory = os.environ.get('XDG_CACHE_HOME', path_home / '.cache') + elif os.name == 'darwin': + cache_directory = path_home / 'Library' / 'Caches' + elif os.name == 'nt': + cache_directory = os.environ.get('LOCALAPPDATA', path_home / 'AppData' / 'Local') + else: + raise RuntimeError('Unsupported platform: ' + os.name) + result = pathlib.Path(cache_directory, 'ms-playwright') + + if not result.is_absolute(): + init_cwd = os.environ.get('INIT_CWD') or os.getcwd() + result = pathlib.Path(init_cwd).resolve().joinpath(result) + + return str(result) def compute_driver_executable() -> Tuple[str, str]: diff --git a/playwright/_impl/_transport.py b/playwright/_impl/_transport.py index f07d31dcd..f2f455c50 100644 --- a/playwright/_impl/_transport.py +++ b/playwright/_impl/_transport.py @@ -105,9 +105,9 @@ async def connect(self) -> None: self._stopped_future: asyncio.Future = asyncio.Future() try: - # For pyinstaller + # For pyinstaller and Nuitka env = get_driver_env() - if getattr(sys, "frozen", False): + if getattr(sys, "frozen", False) or globals().get("_compiled__"): env.setdefault("PLAYWRIGHT_BROWSERS_PATH", "0") startupinfo = None From 903b2cb9bca9b55fda4c56de216a27c52c0f413b Mon Sep 17 00:00:00 2001 From: KRRT7 <106575910+KRRT7@users.noreply.github.com> Date: Fri, 24 May 2024 13:43:52 +0000 Subject: [PATCH 2/3] remove get_registry_directory --- playwright/_impl/_driver.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/playwright/_impl/_driver.py b/playwright/_impl/_driver.py index 1108ff262..cf52d4283 100644 --- a/playwright/_impl/_driver.py +++ b/playwright/_impl/_driver.py @@ -22,31 +22,6 @@ from playwright._repo_version import version import pathlib -def get_registry_directory() -> str: - env_defined = os.environ.get('PLAYWRIGHT_BROWSERS_PATH') - path_home = Path.home() - if env_defined == '0': - result = pathlib.Path(__file__).parent.parent.parent.joinpath('.local-browsers') - elif env_defined: - result = pathlib.Path(env_defined) - else: - cache_directory: Union[str, Path] = '' - if os.name == 'posix': - cache_directory = os.environ.get('XDG_CACHE_HOME', path_home / '.cache') - elif os.name == 'darwin': - cache_directory = path_home / 'Library' / 'Caches' - elif os.name == 'nt': - cache_directory = os.environ.get('LOCALAPPDATA', path_home / 'AppData' / 'Local') - else: - raise RuntimeError('Unsupported platform: ' + os.name) - result = pathlib.Path(cache_directory, 'ms-playwright') - - if not result.is_absolute(): - init_cwd = os.environ.get('INIT_CWD') or os.getcwd() - result = pathlib.Path(init_cwd).resolve().joinpath(result) - - return str(result) - def compute_driver_executable() -> Tuple[str, str]: driver_path = Path(inspect.getfile(playwright)).parent / "driver" From f38835a82089885f9c87af83d90c1cb28a65eee2 Mon Sep 17 00:00:00 2001 From: KRRT7 <106575910+KRRT7@users.noreply.github.com> Date: Fri, 24 May 2024 13:46:42 +0000 Subject: [PATCH 3/3] remove unnecesary imports --- playwright/_impl/_driver.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/playwright/_impl/_driver.py b/playwright/_impl/_driver.py index cf52d4283..9e8cdc1e7 100644 --- a/playwright/_impl/_driver.py +++ b/playwright/_impl/_driver.py @@ -16,11 +16,10 @@ import os import sys from pathlib import Path -from typing import Tuple, Union +from typing import Tuple import playwright from playwright._repo_version import version -import pathlib def compute_driver_executable() -> Tuple[str, str]: