From d3805620dfe84daef5ddf71038edca6bd87208dc Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 10 Oct 2021 14:15:31 +1000 Subject: [PATCH] use importlib for buildinfo.txt --- pylib/anki/buildinfo.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/pylib/anki/buildinfo.py b/pylib/anki/buildinfo.py index bb388d5be..b7f377e1c 100644 --- a/pylib/anki/buildinfo.py +++ b/pylib/anki/buildinfo.py @@ -1,26 +1,12 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import os -import sys - - -def _build_info_path() -> str: - path = os.path.join(os.path.dirname(__file__), "buildinfo.txt") - # running in place? - if os.path.exists(path): - return path - # packaged build? - path = os.path.join(sys.prefix, "buildinfo.txt") - if os.path.exists(path): - return path - - raise Exception("missing buildinfo.txt") +from importlib.resources import open_text def _get_build_info() -> dict[str, str]: info = {} - with open(_build_info_path(), encoding="utf8") as file: + with open_text("anki", "buildinfo.txt") as file: for line in file.readlines(): elems = line.split() if len(elems) == 2: