use importlib for buildinfo.txt

This commit is contained in:
Damien Elmes 2021-10-10 14:15:31 +10:00
parent d9bff1e8ce
commit d3805620df

View File

@ -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: