From 5320ff9c1fbd6bc21e33aef54f00c9a2745900db Mon Sep 17 00:00:00 2001 From: Shiz Date: Tue, 17 Sep 2024 12:05:38 +0200 Subject: [PATCH] use __package__ to find package resources --- copyparty/__init__.py | 1 + copyparty/__main__.py | 1 + copyparty/util.py | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/copyparty/__init__.py b/copyparty/__init__.py index 641414e7..a66243e6 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -54,6 +54,7 @@ except: class EnvParams(object): def __init__(self) -> None: + self.pkg = "" self.t0 = time.time() self.mod = "" self.cfg = "" diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 992075f5..271fd49b 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -217,6 +217,7 @@ def init_E(EE: EnvParams) -> None: raise Exception("could not find a writable path for config") + E.pkg = __package__ E.mod = os.path.dirname(os.path.realpath(__file__)) if E.mod.endswith("__init__"): E.mod = os.path.dirname(E.mod) diff --git a/copyparty/util.py b/copyparty/util.py index f60d7a28..9f8b35ab 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -3576,7 +3576,7 @@ def stat_resource(E: EnvParams, name: str): def has_resource(E: EnvParams, name: str): if impresources: try: - resources = impresources.files("copyparty") + resources = impresources.files(E.pkg) except ImportError: pass else: @@ -3590,7 +3590,7 @@ def has_resource(E: EnvParams, name: str): def load_resource(E: EnvParams, name: str, mode="rb"): if impresources: try: - resources = impresources.files("copyparty") + resources = impresources.files(E.pkg) except ImportError: pass else: @@ -3618,7 +3618,7 @@ def walk_resources(E: EnvParams, name: str): if impresources: try: - resources = impresources.files("copyparty").joinpath(name) + resources = impresources.files(E.pkg).joinpath(name) except ImportError: resources = None else: