summaryrefslogtreecommitdiff
path: root/qutebrowser/utils/utils.py
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-01-26 17:06:23 +0100
committerFlorian Bruhin <me@the-compiler.org>2021-01-26 17:47:38 +0100
commit579585d55423914dc6b120b5a454000573ce67d7 (patch)
tree862fcf48a2b9b6d98aa5ce483160dae05186100d /qutebrowser/utils/utils.py
parente773cc970b8b866e082b1bbce85c7ec5ffed9de6 (diff)
downloadqutebrowser-579585d55423914dc6b120b5a454000573ce67d7.tar.gz
qutebrowser-579585d55423914dc6b120b5a454000573ce67d7.zip
Get rid of utils.resource_filename
See #4467
Diffstat (limited to 'qutebrowser/utils/utils.py')
-rw-r--r--qutebrowser/utils/utils.py23
1 files changed, 4 insertions, 19 deletions
diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py
index bb70ee99c..bd22101de 100644
--- a/qutebrowser/utils/utils.py
+++ b/qutebrowser/utils/utils.py
@@ -32,7 +32,6 @@ import functools
import contextlib
import posixpath
import shlex
-import glob
import mimetypes
import ctypes
import ctypes.util
@@ -56,7 +55,6 @@ if sys.version_info >= (3, 9):
import importlib.resources as importlib_resources
else: # pragma: no cover
import importlib_resources
-import pkg_resources
import yaml
try:
from yaml import (CSafeLoader as YamlLoader,
@@ -183,10 +181,11 @@ def compact_text(text: str, elidelength: int = None) -> str:
def preload_resources() -> None:
"""Load resource files into the cache."""
+ resource_path = importlib_resources.files(qutebrowser)
for subdir, pattern in [('html', '*.html'), ('javascript', '*.js')]:
- path = resource_filename(subdir)
- for full_path in glob.glob(os.path.join(path, pattern)):
- sub_path = '/'.join([subdir, os.path.basename(full_path)])
+ path = resource_path / subdir
+ for full_path in path.glob(pattern):
+ sub_path = str(full_path.relative_to(resource_path))
_resource_cache[sub_path] = read_file(sub_path)
@@ -228,20 +227,6 @@ def read_file(filename: str, binary: bool = False) -> Any:
return p.read_text()
-def resource_filename(filename: str) -> str:
- """Get the absolute filename of a file contained with qutebrowser.
-
- Args:
- filename: The filename.
-
- Return:
- The absolute filename.
- """
- if hasattr(sys, 'frozen'):
- return os.path.join(os.path.dirname(sys.executable), filename)
- return pkg_resources.resource_filename(qutebrowser.__name__, filename)
-
-
def parse_version(version: str) -> VersionNumber:
"""Parse a version string."""
v_q, _suffix = QVersionNumber.fromString(version)