use importlib for buildinfo.txt
This commit is contained in:
parent
d9bff1e8ce
commit
d3805620df
@ -1,26 +1,12 @@
|
|||||||
# Copyright: Ankitects Pty Ltd and contributors
|
# Copyright: Ankitects Pty Ltd and contributors
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
import os
|
from importlib.resources import open_text
|
||||||
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")
|
|
||||||
|
|
||||||
|
|
||||||
def _get_build_info() -> dict[str, str]:
|
def _get_build_info() -> dict[str, str]:
|
||||||
info = {}
|
info = {}
|
||||||
with open(_build_info_path(), encoding="utf8") as file:
|
with open_text("anki", "buildinfo.txt") as file:
|
||||||
for line in file.readlines():
|
for line in file.readlines():
|
||||||
elems = line.split()
|
elems = line.split()
|
||||||
if len(elems) == 2:
|
if len(elems) == 2:
|
||||||
|
Loading…
Reference in New Issue
Block a user