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 MAKEFLAGS += --no-builtin-rules
RUNARGS := RUNARGS :=
.SUFFIXES: .SUFFIXES:
BLACKARGS := -t py36 anki tests --exclude='backend_pb2|buildhash' BLACKARGS := -t py36 anki tests --exclude='backend_pb2|buildinfo'
ISORTARGS := anki tests ISORTARGS := anki tests
$(shell mkdir -p .build ../dist) $(shell mkdir -p .build ../dist)
@ -28,7 +28,7 @@ PROTODEPS := $(wildcard ../proto/*.proto)
protoc --proto_path=../proto --python_out=anki --mypy_out=anki $(PROTODEPS) protoc --proto_path=../proto --python_out=anki --mypy_out=anki $(PROTODEPS)
@touch $@ @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 # Checking
###################### ######################
@ -48,7 +48,7 @@ clean:
# Checking python # Checking python
###################### ######################
CHECKDEPS := $(shell find anki tests -name '*.py' | grep -v buildhash.py) CHECKDEPS := $(shell find anki tests -name '*.py')
.build/mypy: $(CHECKDEPS) .build/mypy: $(CHECKDEPS)
mypy anki mypy anki
@ -78,10 +78,13 @@ CHECKDEPS := $(shell find anki tests -name '*.py' | grep -v buildhash.py)
.PHONY: build .PHONY: build
build: $(BUILD_STEPS) $(CHECKDEPS) build: $(BUILD_STEPS) $(CHECKDEPS)
rm -rf dist rm -rf dist
echo "build='$$(cat ../meta/buildhash)'" > anki/buildhash.py
python setup.py bdist_wheel python setup.py bdist_wheel
rsync -a dist/*.whl ../dist/ rsync -a dist/*.whl ../dist/
# prepare code for running in place # prepare code for running in place
.PHONY: develop .PHONY: develop
develop: $(BUILD_STEPS) 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 import sys
from anki.buildinfo import version
from anki.storage import Collection from anki.storage import Collection
if sys.version_info[0] < 3 or sys.version_info[1] < 5: 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"): if sys.getfilesystemencoding().lower() in ("ascii", "ansi_x3.4-1968"):
raise Exception("Anki requires a UTF-8 locale.") 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"] __all__ = ["Collection"]

View file

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

View file

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

View file

@ -6,7 +6,7 @@ MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules MAKEFLAGS += --no-builtin-rules
.SUFFIXES: .SUFFIXES:
BLACKARGS := -t py36 aqt tests --exclude=aqt/forms BLACKARGS := -t py36 aqt tests --exclude='aqt/forms|buildinfo'
ISORTARGS := aqt tests ISORTARGS := aqt tests
$(shell mkdir -p .build ../dist) $(shell mkdir -p .build ../dist)
@ -36,7 +36,7 @@ TSDEPS := $(wildcard ts/src/*.ts)
(cd ts && npm i && npm run build) (cd ts && npm i && npm run build)
@touch $@ @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 # Checking
###################### ######################
@ -107,3 +107,7 @@ build: $(BUILD_STEPS)
.PHONY: develop .PHONY: develop
develop: $(BUILD_STEPS) 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 import traceback
from typing import Any, Optional from typing import Any, Optional
import anki.buildinfo
import anki.lang import anki.lang
import aqt.buildinfo
from anki import version as _version from anki import version as _version
from anki.consts import HELP_SITE from anki.consts import HELP_SITE
from anki.utils import checksum, isLin, isMac from anki.utils import checksum, isLin, isMac
from aqt.qt import * from aqt.qt import *
from aqt.utils import locale_dir from aqt.utils import locale_dir
assert anki.buildinfo.buildhash == aqt.buildinfo.buildhash
appVersion = _version appVersion = _version
appWebsite = "http://ankisrs.net/" appWebsite = "http://ankisrs.net/"
appChanges = "http://ankisrs.net/docs/changes.html" appChanges = "http://ankisrs.net/docs/changes.html"

View file

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