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/playwright/_impl/_transport.py b/playwright/_impl/_transport.py index b75883041..cf0a8e800 100644 --- a/playwright/_impl/_transport.py +++ b/playwright/_impl/_transport.py @@ -105,6 +105,11 @@ 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" + self._proc = proc = await asyncio.create_subprocess_exec( str(self._driver_executable), "run-driver", @@ -113,6 +118,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) 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"], }, )