Anki/pylib/anki/buildinfo.py
Damien Elmes b9251290ca run pyupgrade over codebase [python upgrade required]
This adds Python 3.9 and 3.10 typing syntax to files that import
attributions from __future___. Python 3.9 should be able to cope with
the 3.10 syntax, but Python 3.8 will no longer work.

On Windows/Mac, install the latest Python 3.9 version from python.org.
There are currently no orjson wheels for Python 3.10 on Windows/Mac,
which will break the build unless you have Rust installed separately.

On Linux, modern distros should have Python 3.9 available already. If
you're on an older distro, you'll need to build Python from source first.
2021-10-04 15:05:48 +10:00

35 lines
902 B
Python

# 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")
def _get_build_info() -> dict[str, str]:
info = {}
with open(_build_info_path(), encoding="utf8") as file:
for line in file.readlines():
elems = line.split()
if len(elems) == 2:
k, v = elems
info[k] = v
return info
_buildinfo = _get_build_info()
buildhash = _buildinfo["STABLE_BUILDHASH"]
version = _buildinfo["STABLE_VERSION"]