From 70adc76b3c629260d4a2c6bdd2253fec4d65aad6 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 19 Jul 2021 13:40:49 +0530 Subject: [PATCH 1/3] feat: added hooks for pyinstaller --- playwright/_impl/__pyinstaller/__init__.py | 20 +++++++++++++++++++ .../hook-playwright.async_api.py | 17 ++++++++++++++++ .../__pyinstaller/hook-playwright.sync_api.py | 17 ++++++++++++++++ setup.py | 1 + 4 files changed, 55 insertions(+) create mode 100644 playwright/_impl/__pyinstaller/__init__.py create mode 100644 playwright/_impl/__pyinstaller/hook-playwright.async_api.py create mode 100644 playwright/_impl/__pyinstaller/hook-playwright.sync_api.py diff --git a/playwright/_impl/__pyinstaller/__init__.py b/playwright/_impl/__pyinstaller/__init__.py new file mode 100644 index 000000000..a6f9feba7 --- /dev/null +++ b/playwright/_impl/__pyinstaller/__init__.py @@ -0,0 +1,20 @@ +# Copyright (c) Microsoft Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +from typing import List + + +def get_hook_dirs() -> List[str]: + return [os.path.dirname(__file__)] diff --git a/playwright/_impl/__pyinstaller/hook-playwright.async_api.py b/playwright/_impl/__pyinstaller/hook-playwright.async_api.py new file mode 100644 index 000000000..cfb75c532 --- /dev/null +++ b/playwright/_impl/__pyinstaller/hook-playwright.async_api.py @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from PyInstaller.utils.hooks import collect_data_files + +datas = collect_data_files("playwright") diff --git a/playwright/_impl/__pyinstaller/hook-playwright.sync_api.py b/playwright/_impl/__pyinstaller/hook-playwright.sync_api.py new file mode 100644 index 000000000..cfb75c532 --- /dev/null +++ b/playwright/_impl/__pyinstaller/hook-playwright.sync_api.py @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from PyInstaller.utils.hooks import collect_data_files + +datas = collect_data_files("playwright") diff --git a/setup.py b/setup.py index 6aef80b99..be66049f2 100644 --- a/setup.py +++ b/setup.py @@ -168,5 +168,6 @@ def run(self) -> None: "console_scripts": [ "playwright=playwright.__main__:main", ], + "pyinstaller40": ["hook-dirs=playwright._impl.__pyinstaller:get_hook_dirs"], }, ) From 60d9bc91c30e38015fc709ddd435f6728eed7159 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Wed, 21 Jul 2021 13:02:14 +0530 Subject: [PATCH 2/3] chore: auto detect pyinstaller --- playwright/_impl/_transport.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/playwright/_impl/_transport.py b/playwright/_impl/_transport.py index b75883041..e805ed31a 100644 --- a/playwright/_impl/_transport.py +++ b/playwright/_impl/_transport.py @@ -105,6 +105,10 @@ async def run(self) -> None: creationflags = subprocess.CREATE_NO_WINDOW try: + env = os.environ.copy() + if getattr(sys, "frozen", False): + env["PLAYWRIGHT_BROWSERS_PATH"] = "0" + self._proc = proc = await asyncio.create_subprocess_exec( str(self._driver_executable), "run-driver", @@ -113,6 +117,7 @@ async def run(self) -> None: stderr=_get_stderr_fileno(), limit=32768, creationflags=creationflags, + env=env, ) except Exception as exc: self.on_error_future.set_exception(exc) From bfae4a29c0516139ddc742b8aa65bd81949eaa20 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Wed, 21 Jul 2021 13:20:14 +0530 Subject: [PATCH 3/3] Update playwright/_impl/_transport.py --- playwright/_impl/_transport.py | 1 + 1 file changed, 1 insertion(+) diff --git a/playwright/_impl/_transport.py b/playwright/_impl/_transport.py index e805ed31a..cf0a8e800 100644 --- a/playwright/_impl/_transport.py +++ b/playwright/_impl/_transport.py @@ -105,6 +105,7 @@ async def run(self) -> None: creationflags = subprocess.CREATE_NO_WINDOW try: + # For pyinstaller env = os.environ.copy() if getattr(sys, "frozen", False): env["PLAYWRIGHT_BROWSERS_PATH"] = "0"