-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix get_file_dirname for pyinstaller (fix #342) #345
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
Conversation
Do you know the reason why it is not working in this specific case? The workaround looks quite weird, but I'm also not very experienced in Python. |
Not sure, but this issue somewhat explains the problem |
@tumregels this looks good to me, but do you think we could replace the usage of this method with something more straightforward in |
@pavelfeldman there seems to be no solid solution to this problem, at least can't suggest any. This answer tries to cover the available options. And the recommended pkgutil is not an option for this case. |
What about removing the single occurrence in the source and moving it inline into the callee and moving the get_file_dirname function into the tests directory? |
@mxschmitt - based on the table here can suggest to change import importlib.resources as pkg_resources
def compute_driver_executable() -> Path:
_pkg = '.'.join(__name__.split(".")[:-1])
with pkg_resources.path(_pkg, "") as package_path:
assert package_path
platform = sys.platform
if platform == "win32":
return package_path / "driver" / "playwright-cli.exe"
return package_path / "driver" / "playwright-cli" where And this solution works with pyinstaller. |
Something as simple as below works for me: from importlib import resources
with resources.path("playwright", "driver") as driver_folder: Can we just use it in Another variation to try: import playwright
from importlib import resources
with resources.path(playwright, "driver") as driver_folder: |
just checked this one with pyinstaller - it works import playwright
from importlib import resources
def compute_driver_executable() -> Path:
with resources.path(playwright, "driver") as driver_folder:
assert driver_folder
platform = sys.platform
if platform == "win32":
return driver_folder / "playwright-cli.exe"
return driver_folder / "playwright-cli" we can also change |
@pavelfeldman: nice! do you want to update your PR with it? |
@pavelfeldman will update the PR today. |
Can we also move the get_file_dirname function to the tests utils.py file? |
@mxschmitt @pavelfeldman the proposed solution is wrong. |
So we should either add init.py into the folder or move the driver executable into the root folder? Either way should do... |
@pavelfeldman current implementation should work. import inspect
import playwright
def compute_driver_executable() -> Path:
package_path = Path(inspect.getfile(playwright)).parent
platform = sys.platform
if platform == "win32":
return package_path / "driver" / "playwright-cli.exe"
return package_path / "driver" / "playwright-cli" it's failing because regarding previous solution with |
fix get_file_dirname so that playwright can function when freezed with pyinstaller (fix #342).