From 6e3f971ae1fc827f1a6d012453858d2662384701 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 10 Nov 2020 13:50:59 +1000 Subject: [PATCH] handle packaged pylib buildinfo.txt; drop aqt buildinfo --- pylib/anki/buildinfo.py | 31 +++++++++++++++++++++++++------ qt/aqt/BUILD.bazel | 7 ------- qt/aqt/__init__.py | 4 ---- qt/aqt/buildinfo.py | 14 -------------- qt/tests/run_format.py | 2 +- 5 files changed, 26 insertions(+), 32 deletions(-) delete mode 100644 qt/aqt/buildinfo.py diff --git a/pylib/anki/buildinfo.py b/pylib/anki/buildinfo.py index 965b8f183..6d6cd44fd 100644 --- a/pylib/anki/buildinfo.py +++ b/pylib/anki/buildinfo.py @@ -2,13 +2,32 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import os +import sys +from typing import Dict -_buildinfo = {} -for line in open(os.path.join(os.path.dirname(__file__), "buildinfo.txt")).readlines(): - elems = line.split() - if len(elems) == 2: - k, v = elems - _buildinfo[k] = v +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 = {} + for line in open(_build_info_path()).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"] diff --git a/qt/aqt/BUILD.bazel b/qt/aqt/BUILD.bazel index 524f41c3a..975cfd5cf 100644 --- a/qt/aqt/BUILD.bazel +++ b/qt/aqt/BUILD.bazel @@ -4,12 +4,6 @@ load("@py_deps//:requirements.bzl", "requirement") load("@rules_python//experimental/python:wheel.bzl", "py_package", "py_wheel") load("//:defs.bzl", "anki_version") -copy_file( - name = "buildinfo", - src = "//:buildinfo.txt", - out = "buildinfo.txt", -) - genrule( name = "hooks_gen", outs = ["hooks_gen.py"], @@ -37,7 +31,6 @@ aqt_srcs = glob([ ] aqt_core_data = [ - "buildinfo.txt", "colors.py", "py.typed", ":hooks_gen", diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 665b8bc96..e2dd14803 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -12,9 +12,7 @@ import tempfile import traceback from typing import Any, Callable, Dict, Optional, Union -import anki.buildinfo import anki.lang -import aqt.buildinfo from anki import version as _version from anki.consts import HELP_SITE from anki.rsbackend import RustBackend @@ -22,8 +20,6 @@ from anki.utils import checksum, isLin, isMac from aqt.qt import * from aqt.utils import locale_dir -assert anki.buildinfo.buildhash == aqt.buildinfo.buildhash - # we want to be able to print unicode debug info to console without # fear of a traceback on systems with the console set to ASCII try: diff --git a/qt/aqt/buildinfo.py b/qt/aqt/buildinfo.py deleted file mode 100644 index 965b8f183..000000000 --- a/qt/aqt/buildinfo.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright: Ankitects Pty Ltd and contributors -# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - -import os - -_buildinfo = {} -for line in open(os.path.join(os.path.dirname(__file__), "buildinfo.txt")).readlines(): - elems = line.split() - if len(elems) == 2: - k, v = elems - _buildinfo[k] = v - -buildhash=_buildinfo["STABLE_BUILDHASH"] -version=_buildinfo["STABLE_VERSION"] diff --git a/qt/tests/run_format.py b/qt/tests/run_format.py index 09ceb7f37..78ac7dbf3 100644 --- a/qt/tests/run_format.py +++ b/qt/tests/run_format.py @@ -22,7 +22,7 @@ if __name__ == "__main__": "black", "-t", "py36", - "--exclude=aqt/forms|buildinfo|colors", + "--exclude=aqt/forms|colors", "aqt", "tests", "tools",