diff options
author | Florian Bruhin <me@the-compiler.org> | 2021-01-26 14:31:01 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2021-01-26 14:31:01 +0100 |
commit | eeb26a6aa8e9ddc7b48d656ea93dea987ee88c79 (patch) | |
tree | 0bd35e53a7ada85cadb628524e36fe0b91dfbc0d /qutebrowser | |
parent | 6bb2b082c94c96197daa3c161ec628fd18fd2041 (diff) | |
download | qutebrowser-eeb26a6aa8e9ddc7b48d656ea93dea987ee88c79.tar.gz qutebrowser-eeb26a6aa8e9ddc7b48d656ea93dea987ee88c79.zip |
Revert "Remove pkg_resources special casing for PyInstaller"
This reverts commit 6bb2b082c94c96197daa3c161ec628fd18fd2041.
I guess storing package data in qutebrowser/ would be the proper way,
but this doesn't actually work on macOS - there, the executable name is
already "qutebrowser"...
Diffstat (limited to 'qutebrowser')
-rw-r--r-- | qutebrowser/utils/utils.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 85d1612c7..4ae0c9cab 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -208,12 +208,24 @@ def read_file(filename: str, binary: bool = False) -> Any: if not binary and filename in _resource_cache: return _resource_cache[filename] - p = importlib_resources.files(qutebrowser) / filename + if hasattr(sys, 'frozen'): + # PyInstaller doesn't support pkg_resources :( + # https://github.com/pyinstaller/pyinstaller/wiki/FAQ#misc + fn = os.path.join(os.path.dirname(sys.executable), filename) + if binary: + f: IO + with open(fn, 'rb') as f: + return f.read() + else: + with open(fn, 'r', encoding='utf-8') as f: + return f.read() + else: + p = importlib_resources.files(qutebrowser) / filename - if binary: - return p.read_bytes() + if binary: + return p.read_bytes() - return p.read_text() + return p.read_text() def resource_filename(filename: str) -> str: |