add buildhash to rspy and aqt, and check all three modules match

This commit is contained in:
Damien Elmes 2020-01-03 15:15:18 +10:00
parent c25e106f88
commit 0aa01605d7
9 changed files with 32 additions and 15 deletions

View file

@ -6,7 +6,7 @@ MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
RUNARGS :=
.SUFFIXES:
BLACKARGS := -t py36 anki tests --exclude='backend_pb2|buildhash'
BLACKARGS := -t py36 anki tests --exclude='backend_pb2|buildinfo'
ISORTARGS := anki tests
$(shell mkdir -p .build ../dist)
@ -28,7 +28,7 @@ PROTODEPS := $(wildcard ../proto/*.proto)
protoc --proto_path=../proto --python_out=anki --mypy_out=anki $(PROTODEPS)
@touch $@
BUILD_STEPS := .build/run-deps .build/dev-deps .build/py-proto
BUILD_STEPS := .build/run-deps .build/dev-deps .build/py-proto anki/buildinfo.py
# Checking
######################
@ -48,7 +48,7 @@ clean:
# Checking python
######################
CHECKDEPS := $(shell find anki tests -name '*.py' | grep -v buildhash.py)
CHECKDEPS := $(shell find anki tests -name '*.py')
.build/mypy: $(CHECKDEPS)
mypy anki
@ -78,10 +78,13 @@ CHECKDEPS := $(shell find anki tests -name '*.py' | grep -v buildhash.py)
.PHONY: build
build: $(BUILD_STEPS) $(CHECKDEPS)
rm -rf dist
echo "build='$$(cat ../meta/buildhash)'" > anki/buildhash.py
python setup.py bdist_wheel
rsync -a dist/*.whl ../dist/
# prepare code for running in place
.PHONY: develop
develop: $(BUILD_STEPS)
anki/buildinfo.py: ../meta/version ../meta/buildhash
echo "buildhash='$$(cat ../meta/buildhash)'" > $@
echo "version='$$(cat ../meta/version)'" >> $@

1
pylib/anki/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
buildinfo.py

View file

@ -3,6 +3,7 @@
import sys
from anki.buildinfo import version
from anki.storage import Collection
if sys.version_info[0] < 3 or sys.version_info[1] < 5:
@ -11,8 +12,5 @@ if sys.version_info[0] < 3 or sys.version_info[1] < 5:
if sys.getfilesystemencoding().lower() in ("ascii", "ansi_x3.4-1968"):
raise Exception("Anki requires a UTF-8 locale.")
# fmt: off
version="2.1.17" # build scripts grep this line, so preserve formatting
# fmt: on
__all__ = ["Collection"]

View file

@ -5,9 +5,12 @@ from typing import Dict, List
import ankirspy # pytype: disable=import-error
import anki.backend_pb2 as pb
import anki.buildinfo
from .types import AllTemplateReqs
assert ankirspy.buildhash() == anki.buildinfo.buildhash
SchedTimingToday = pb.SchedTimingTodayOut

View file

@ -494,10 +494,6 @@ class TimedLog:
def versionWithBuild() -> str:
from anki import version
from anki.buildinfo import version, buildhash
try:
from anki.buildhash import build # type: ignore # pylint: disable=import-error,no-name-in-module
except:
build = "dev"
return "%s (%s)" % (version, build)
return "%s (%s)" % (version, buildhash)

View file

@ -6,7 +6,7 @@ MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
BLACKARGS := -t py36 aqt tests --exclude=aqt/forms
BLACKARGS := -t py36 aqt tests --exclude='aqt/forms|buildinfo'
ISORTARGS := aqt tests
$(shell mkdir -p .build ../dist)
@ -36,7 +36,7 @@ TSDEPS := $(wildcard ts/src/*.ts)
(cd ts && npm i && npm run build)
@touch $@
BUILD_STEPS := .build/run-deps .build/dev-deps .build/js .build/ui .build/i18n
BUILD_STEPS := .build/run-deps .build/dev-deps .build/js .build/ui .build/i18n aqt/buildinfo.py
# Checking
######################
@ -107,3 +107,7 @@ build: $(BUILD_STEPS)
.PHONY: develop
develop: $(BUILD_STEPS)
aqt/buildinfo.py: ../meta/version ../meta/buildhash
echo "buildhash='$$(cat ../meta/buildhash)'" > $@
echo "version='$$(cat ../meta/version)'" >> $@

1
qt/aqt/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
buildinfo.py

View file

@ -12,13 +12,17 @@ import tempfile
import traceback
from typing import Any, Optional
import anki.buildinfo
import anki.lang
import aqt.buildinfo
from anki import version as _version
from anki.consts import HELP_SITE
from anki.utils import checksum, isLin, isMac
from aqt.qt import *
from aqt.utils import locale_dir
assert anki.buildinfo.buildhash == aqt.buildinfo.buildhash
appVersion = _version
appWebsite = "http://ankisrs.net/"
appChanges = "http://ankisrs.net/docs/changes.html"

View file

@ -1,12 +1,18 @@
use anki::backend::Backend as RustBackend;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use pyo3::wrap_pyfunction;
#[pyclass]
struct Backend {
backend: RustBackend,
}
#[pyfunction]
fn buildhash() -> &'static str {
include_str!("../../meta/buildhash").trim()
}
#[pymethods]
impl Backend {
#[new]
@ -28,6 +34,7 @@ impl Backend {
#[pymodule]
fn ankirspy(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<Backend>()?;
m.add_wrapped(wrap_pyfunction!(buildhash)).unwrap();
Ok(())
}