Compare commits

..

No commits in common. "main" and "25.06b1" have entirely different histories.

526 changed files with 15331 additions and 16027 deletions

View file

@ -5,11 +5,7 @@ DESCRIPTORS_BIN = { value = "out/rslib/proto/descriptors.bin", relative = true }
# build script will append .exe if necessary
PROTOC = { value = "out/extracted/protoc/bin/protoc", relative = true }
PYO3_NO_PYTHON = "1"
MACOSX_DEPLOYMENT_TARGET = "11"
PYTHONDONTWRITEBYTECODE = "1" # prevent junk files on Windows
MACOSX_DEPLOYMENT_TARGET = "10.13.4"
[term]
color = "always"
[target.'cfg(all(target_env = "msvc", target_os = "windows"))']
rustflags = ["-C", "target-feature=+crt-static"]

View file

@ -5,6 +5,9 @@
db-path = "~/.cargo/advisory-db"
db-urls = ["https://github.com/rustsec/advisory-db"]
ignore = [
# pyoxidizer is stuck on an old ring version
"RUSTSEC-2025-0009",
"RUSTSEC-2025-0010",
# burn depends on an unmaintained package 'paste'
"RUSTSEC-2024-0436",
]
@ -14,11 +17,12 @@ allow = [
"MIT",
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"CDLA-Permissive-2.0",
"ISC",
"MPL-2.0",
"Unicode-DFS-2016",
"BSD-2-Clause",
"BSD-3-Clause",
"OpenSSL",
"CC0-1.0",
"Unlicense",
"Zlib",

View file

@ -20,6 +20,7 @@
"ftl/usage",
"licenses.json",
".dmypy.json",
"qt/bundle/PyOxidizer",
"target",
".mypy_cache",
"extra",

2
.gitignore vendored
View file

@ -18,5 +18,3 @@ node_modules
yarn-error.log
ts/.svelte-kit
.yarn
.claude/settings.local.json
.claude/user.md

6
.gitmodules vendored
View file

@ -6,3 +6,9 @@
path = ftl/qt-repo
url = https://github.com/ankitects/anki-desktop-ftl.git
shallow = true
[submodule "qt/bundle/PyOxidizer"]
path = qt/bundle/PyOxidizer
url = https://github.com/ankitects/PyOxidizer.git
shallow = true
update = none

5
.isort.cfg Normal file
View file

@ -0,0 +1,5 @@
[settings]
py_version=39
known_first_party=anki,aqt,tests
profile=black
extend_skip=qt/bundle

View file

@ -18,7 +18,7 @@ mypy_path =
ftl,
pylib/tools,
python
exclude = (pylib/anki/_vendor)
exclude = (qt/bundle/PyOxidizer|pylib/anki/_vendor)
[mypy-anki.*]
disallow_untyped_defs = True
@ -165,5 +165,3 @@ ignore_missing_imports = True
ignore_missing_imports = True
[mypy-pip_system_certs.*]
ignore_missing_imports = True
[mypy-anki_audio]
ignore_missing_imports = True

48
.pylintrc Normal file
View file

@ -0,0 +1,48 @@
[MASTER]
ignore-patterns=.*_pb2.*
persistent = no
extension-pkg-whitelist=orjson,PyQt6
init-hook="import sys; sys.path.extend(['pylib/anki/_vendor', 'out/qt'])"
[REPORTS]
output-format=colorized
[MESSAGES CONTROL]
disable=
R,
line-too-long,
too-many-lines,
missing-function-docstring,
missing-module-docstring,
missing-class-docstring,
import-outside-toplevel,
wrong-import-position,
wrong-import-order,
fixme,
unused-wildcard-import,
attribute-defined-outside-init,
redefined-builtin,
wildcard-import,
broad-except,
bare-except,
unused-argument,
unused-variable,
redefined-outer-name,
global-statement,
protected-access,
arguments-differ,
arguments-renamed,
consider-using-f-string,
invalid-name,
broad-exception-raised
[BASIC]
good-names =
id,
tr,
db,
ok,
ip,
[IMPORTS]
ignored-modules = anki.*_pb2, anki.sync_pb2, win32file,pywintypes,socket,win32pipe,pyaudio,anki.scheduler_pb2,anki.notetypes_pb2

View file

@ -1 +0,0 @@
3.13.5

View file

@ -1,91 +1,2 @@
lint.select = [
"E", # pycodestyle errors
"F", # Pyflakes errors
"PL", # Pylint rules
"I", # Isort rules
"ARG",
# "UP", # pyupgrade
# "B", # flake8-bugbear
# "SIM", # flake8-simplify
]
extend-exclude = ["*_pb2.py", "*_pb2.pyi"]
lint.ignore = [
# Docstring rules (missing-*-docstring in pylint)
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D103", # Missing docstring in public function
# Import rules (wrong-import-* in pylint)
"E402", # Module level import not at top of file
"E501", # Line too long
# pycodestyle rules
"E741", # ambiguous-variable-name
# Comment rules (fixme in pylint)
"FIX002", # Line contains TODO
# Pyflakes rules
"F402", # import-shadowed-by-loop-var
"F403", # undefined-local-with-import-star
"F405", # undefined-local-with-import-star-usage
# Naming rules (invalid-name in pylint)
"N801", # Class name should use CapWords convention
"N802", # Function name should be lowercase
"N803", # Argument name should be lowercase
"N806", # Variable in function should be lowercase
"N811", # Constant imported as non-constant
"N812", # Lowercase imported as non-lowercase
"N813", # Camelcase imported as lowercase
"N814", # Camelcase imported as constant
"N815", # Variable in class scope should not be mixedCase
"N816", # Variable in global scope should not be mixedCase
"N817", # CamelCase imported as acronym
"N818", # Error suffix in exception names
# Pylint rules
"PLW0603", # global-statement
"PLW2901", # redefined-loop-name
"PLC0415", # import-outside-top-level
"PLR2004", # magic-value-comparison
# Exception handling (broad-except, bare-except in pylint)
"BLE001", # Do not catch blind exception
# Argument rules (unused-argument in pylint)
"ARG001", # Unused function argument
"ARG002", # Unused method argument
"ARG005", # Unused lambda argument
# Access rules (protected-access in pylint)
"SLF001", # Private member accessed
# String formatting (consider-using-f-string in pylint)
"UP032", # Use f-string instead of format call
# Exception rules (broad-exception-raised in pylint)
"TRY301", # Abstract raise to an inner function
# Builtin shadowing (redefined-builtin in pylint)
"A001", # Variable shadows a Python builtin
"A002", # Argument shadows a Python builtin
"A003", # Class attribute shadows a Python builtin
]
[lint.per-file-ignores]
"**/anki/*_pb2.py" = ["ALL"]
[lint.pep8-naming]
ignore-names = ["id", "tr", "db", "ok", "ip"]
[lint.pylint]
max-args = 12
max-returns = 10
max-branches = 35
max-statements = 125
[lint.isort]
known-first-party = ["anki", "aqt", "tests"]
target-version = "py39"
extend-exclude = ["qt/bundle"]

View file

@ -1 +1 @@
25.09.2
25.06

View file

@ -2,7 +2,7 @@
"recommendations": [
"dprint.dprint",
"ms-python.python",
"charliermarsh.ruff",
"ms-python.black-formatter",
"rust-lang.rust-analyzer",
"svelte.svelte-vscode",
"zxh404.vscode-proto3",

View file

@ -18,7 +18,7 @@
"out/qt",
"qt"
],
"python.formatting.provider": "charliermarsh.ruff",
"python.formatting.provider": "black",
"python.linting.mypyEnabled": false,
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingModuleSource": "none"
@ -31,13 +31,11 @@
"rust-analyzer.rustfmt.extraArgs": ["+nightly"],
"search.exclude": {
"**/node_modules": true,
".bazel/**": true
".bazel/**": true,
"qt/bundle/PyOxidizer": true
},
"rust-analyzer.cargo.buildScripts.enable": true,
"python.analysis.typeCheckingMode": "off",
"python.analysis.exclude": [
"out/launcher/**"
],
"terminal.integrated.env.windows": {
"PATH": "c:\\msys64\\usr\\bin;${env:Path}"
}

View file

@ -1,2 +1 @@
nodeLinker: node-modules
enableScripts: false

View file

@ -1,86 +0,0 @@
# Claude Code Configuration
## Project Overview
Anki is a spaced repetition flashcard program with a multi-layered architecture. Main components:
- Web frontend: Svelte/TypeScript in ts/
- PyQt GUI, which embeds the web components in aqt/
- Python library which wraps our rust Layer (pylib/, with Rust module in pylib/rsbridge)
- Core Rust layer in rslib/
- Protobuf definitions in proto/ that are used by the different layers to
talk to each other.
## Building/checking
./check (check.bat) will format the code and run the main build & checks.
Please do this as a final step before marking a task as completed.
## Quick iteration
During development, you can build/check subsections of our code:
- Rust: 'cargo check'
- Python: './tools/dmypy', and if wheel-related, './ninja wheels'
- TypeScript/Svelte: './ninja check:svelte'
Be mindful that some changes (such as modifications to .proto files) may
need a full build with './check' first.
## Build tooling
'./check' and './ninja' invoke our build system, which is implemented in build/. It takes care of downloading required deps and invoking our build
steps.
## Translations
ftl/ contains our Fluent translation files. We have scripts in rslib/i18n
to auto-generate an API for Rust, TypeScript and Python so that our code can
access the translations in a type-safe manner. Changes should be made to
ftl/core or ftl/qt. Except for features specific to our Qt interface, prefer
the core module. When adding new strings, confirm the appropriate ftl file
first, and try to match the existing style.
## Protobuf and IPC
Our build scripts use the .proto files to define our Rust library's
non-Rust API. pylib/rsbridge exposes that API, and _backend.py exposes
snake_case methods for each protobuf RPC that call into the API.
Similar tooling creates a @generated/backend TypeScript module for
communicating with the Rust backend (which happens over POST requests).
## Fixing errors
When dealing with build errors or failing tests, invoke 'check' or one
of the quick iteration commands regularly. This helps verify your changes
are correct. To locate other instances of a problem, run the check again -
don't attempt to grep the codebase.
## Ignores
The files in out/ are auto-generated. Mostly you should ignore that folder,
though you may sometimes find it useful to view out/{pylib/anki,qt/_aqt,ts/lib/generated} when dealing with cross-language communication or our other generated sourcecode.
## Launcher/installer
The code for our launcher is in qt/launcher, with separate code for each
platform.
## Rust dependencies
Prefer adding to the root workspace, and using dep.workspace = true in the individual Rust project.
## Rust utilities
rslib/{process,io} contain some helpers for file and process operations,
which provide better error messages/context and some ergonomics. Use them
when possible.
## Rust error handling
in rslib, use error/mod.rs's AnkiError/Result and snafu. In our other Rust modules, prefer anyhow + additional context where appropriate. Unwrapping
in build scripts/tests is fine.
## Individual preferences
See @.claude/user.md

View file

@ -49,7 +49,6 @@ Sander Santema <github.com/sandersantema/>
Thomas Brownback <https://github.com/brownbat/>
Andrew Gaul <andrew@gaul.org>
kenden
Emil Hamrin <github.com/e-hamrin>
Nickolay Yudin <kelciour@gmail.com>
neitrinoweb <github.com/neitrinoweb/>
Andreas Reis <github.com/nwwt>
@ -64,7 +63,6 @@ Jakub Kaczmarzyk <jakub.kaczmarzyk@gmail.com>
Akshara Balachandra <akshara.bala.18@gmail.com>
lukkea <github.com/lukkea/>
David Allison <davidallisongithub@gmail.com>
David Allison <62114487+david-allison@users.noreply.github.com>
Tsung-Han Yu <johan456789@gmail.com>
Piotr Kubowicz <piotr.kubowicz@gmail.com>
RumovZ <gp5glkw78@relay.firefox.com>
@ -150,7 +148,7 @@ user1823 <92206575+user1823@users.noreply.github.com>
Gustaf Carefall <https://github.com/Gustaf-C>
virinci <github.com/virinci>
snowtimeglass <snowtimeglass@gmail.com>
brishtibheja <136738526+brishtibheja@users.noreply.github.com>
brishtibheja <sorata225yume@gmail.com>
Ben Olson <github.com/grepgrok>
Akash Reddy <akashreddy2003@gmail.com>
Lucio Sauer <watermanpaint@posteo.net>
@ -232,18 +230,7 @@ KolbyML <https://github.com/KolbyML>
Adnane Taghi <dev@soleuniverse.me>
Spiritual Father <https://github.com/spiritualfather>
Emmanuel Ferdman <https://github.com/emmanuel-ferdman>
Sunong2008 <https://github.com/Sunrongguo2008>
Marvin Kopf <marvinkopf@outlook.com>
Kevin Nakamura <grinkers@grinkers.net>
Bradley Szoke <bradleyszoke@gmail.com>
jcznk <https://github.com/jcznk>
Thomas Rixen <thomas.rixen@student.uclouvain.be>
Siyuan Mattuwu Yan <syan4@ualberta.ca>
Lee Doughty <32392044+leedoughty@users.noreply.github.com>
memchr <memchr@proton.me>
Max Romanowski <maxr777@proton.me>
Aldlss <ayaldlss@gmail.com>
********************
The text of the 3 clause BSD license follows:

2640
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,8 @@ members = [
"build/runner",
"ftl",
"pylib/rsbridge",
"qt/launcher",
"qt/bundle/mac",
"qt/bundle/win",
"rslib",
"rslib/i18n",
"rslib/io",
@ -22,6 +23,7 @@ members = [
"rslib/sync",
"tools/minilints",
]
exclude = ["qt/bundle"]
resolver = "2"
[workspace.dependencies.percent-encoding-iri]
@ -33,8 +35,9 @@ git = "https://github.com/ankitects/linkcheck.git"
rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca"
[workspace.dependencies.fsrs]
version = "5.1.0"
# git = "https://github.com/open-spaced-repetition/fsrs-rs.git"
# version = "3.0.0"
git = "https://github.com/open-spaced-repetition/fsrs-rs.git"
rev = "a7f7efc10f0a26b14ee348cc7402155685f2a24f"
# path = "../open-spaced-repetition/fsrs-rs"
[workspace.dependencies]
@ -51,101 +54,99 @@ ninja_gen = { "path" = "build/ninja_gen" }
unicase = "=2.6.0" # any changes could invalidate sqlite indexes
# normal
ammonia = "4.1.0"
anyhow = "1.0.98"
async-compression = { version = "0.4.24", features = ["zstd", "tokio"] }
ammonia = "4.0.0"
anyhow = "1.0.90"
apple-bundles = "0.17.0"
async-compression = { version = "0.4.17", features = ["zstd", "tokio"] }
async-stream = "0.3.6"
async-trait = "0.1.88"
axum = { version = "0.8.4", features = ["multipart", "macros"] }
axum-client-ip = "1.1.3"
axum-extra = { version = "0.10.1", features = ["typed-header"] }
bitflags = "2.9.1"
blake3 = "1.8.2"
bytes = "1.10.1"
camino = "1.1.10"
chrono = { version = "0.4.41", default-features = false, features = ["std", "clock"] }
clap = { version = "4.5.40", features = ["derive"] }
coarsetime = "0.1.36"
convert_case = "0.8.0"
criterion = { version = "0.6.0" }
csv = "1.3.1"
data-encoding = "2.9.0"
async-trait = "0.1.83"
axum = { version = "0.7", features = ["multipart", "macros"] }
axum-client-ip = "0.6"
axum-extra = { version = "0.9.4", features = ["typed-header"] }
blake3 = "1.5.4"
bytes = "1.7.2"
camino = "1.1.9"
chrono = { version = "0.4.38", default-features = false, features = ["std", "clock"] }
clap = { version = "4.5.20", features = ["derive"] }
coarsetime = "0.1.34"
convert_case = "0.6.0"
criterion = { version = "0.5.1" }
csv = "1.3.0"
data-encoding = "2.6.0"
difflib = "0.4.0"
dirs = "6.0.0"
dirs = "5.0.1"
dunce = "1.0.5"
embed-resource = "3.0.4"
envy = "0.4.2"
flate2 = "1.1.2"
fluent = "0.17.0"
fluent-bundle = "0.16.0"
fluent-syntax = "0.12.0"
flate2 = "1.0.34"
fluent = "0.16.1"
fluent-bundle = "0.15.3"
fluent-syntax = "0.11.1"
fnv = "1.0.7"
futures = "0.3.31"
globset = "0.4.16"
glob = "0.3.1"
globset = "0.4.15"
hex = "0.4.3"
htmlescape = "0.3.1"
hyper = "1"
id_tree = "1.8.0"
inflections = "1.1.1"
intl-memoizer = "0.5.3"
itertools = "0.14.0"
intl-memoizer = "0.5.2"
itertools = "0.13.0"
junction = "1.2.0"
libc = "0.2"
libc-stdhandle = "0.1"
lazy_static = "1.5.0"
maplit = "1.0.2"
nom = "8.0.0"
nom = "7.1.3"
num-format = "0.4.4"
num_cpus = "1.17.0"
num_cpus = "1.16.0"
num_enum = "0.7.3"
once_cell = "1.21.3"
once_cell = "1.20.2"
pbkdf2 = { version = "0.12", features = ["simple"] }
phf = { version = "0.11.3", features = ["macros"] }
pin-project = "1.1.10"
prettyplease = "0.2.34"
phf = { version = "0.11.2", features = ["macros"] }
pin-project = "1.1.6"
plist = "1.7.0"
prettyplease = "0.2.24"
prost = "0.13"
prost-build = "0.13"
prost-reflect = "0.14.7"
prost-reflect = "0.14"
prost-types = "0.13"
pulldown-cmark = "0.13.0"
pyo3 = { version = "0.25.1", features = ["extension-module", "abi3", "abi3-py39"] }
rand = "0.9.1"
rayon = "1.10.0"
regex = "1.11.1"
reqwest = { version = "0.12.20", default-features = false, features = ["json", "socks", "stream", "multipart"] }
rusqlite = { version = "0.36.0", features = ["trace", "functions", "collation", "bundled"] }
pulldown-cmark = "0.9.6"
pyo3 = { version = "0.24", features = ["extension-module", "abi3", "abi3-py39"] }
rand = "0.8.5"
regex = "1.11.0"
reqwest = { version = "0.12.8", default-features = false, features = ["json", "socks", "stream", "multipart"] }
rusqlite = { version = "0.30.0", features = ["trace", "functions", "collation", "bundled"] }
rustls-pemfile = "2.2.0"
scopeguard = "1.2.0"
serde = { version = "1.0.219", features = ["derive"] }
serde-aux = "4.7.0"
serde_json = "1.0.140"
serde_repr = "0.1.20"
serde_tuple = "1.1.0"
serde = { version = "1.0.210", features = ["derive"] }
serde-aux = "4.5.0"
serde_json = "1.0.132"
serde_repr = "0.1.19"
serde_tuple = "0.5.0"
sha1 = "0.10.6"
sha2 = { version = "0.10.9" }
sha2 = { version = "0.10.8" }
simple-file-manifest = "0.11.0"
snafu = { version = "0.8.6", features = ["rust_1_61"] }
strum = { version = "0.27.1", features = ["derive"] }
syn = { version = "2.0.103", features = ["parsing", "printing"] }
tar = "0.4.44"
tempfile = "3.20.0"
strum = { version = "0.26.3", features = ["derive"] }
syn = { version = "2.0.82", features = ["parsing", "printing"] }
tar = "0.4.42"
tempfile = "3.13.0"
termcolor = "1.4.1"
tokio = { version = "1.45", features = ["fs", "rt-multi-thread", "macros", "signal"] }
tokio-util = { version = "0.7.15", features = ["io"] }
tower-http = { version = "0.6.6", features = ["trace"] }
tracing = { version = "0.1.41", features = ["max_level_trace", "release_max_level_debug"] }
tokio = { version = "1.40", features = ["fs", "rt-multi-thread", "macros", "signal"] }
tokio-util = { version = "0.7.12", features = ["io"] }
tower-http = { version = "0.5", features = ["trace"] }
tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_debug"] }
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.20", features = ["fmt", "env-filter"] }
unic-langid = { version = "0.9.6", features = ["macros"] }
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
tugger-windows-codesign = "0.10.0"
unic-langid = { version = "0.9.5", features = ["macros"] }
unic-ucd-category = "0.9.0"
unicode-normalization = "0.1.24"
walkdir = "2.5.0"
which = "8.0.0"
widestring = "1.1.0"
winapi = { version = "0.3", features = ["wincon", "winreg"] }
windows = { version = "0.61.3", features = ["Media_SpeechSynthesis", "Media_Core", "Foundation_Collections", "Storage_Streams", "Win32_System_Console", "Win32_System_Registry", "Win32_System_SystemInformation", "Win32_Foundation", "Win32_UI_Shell", "Wdk_System_SystemServices"] }
wiremock = "0.6.3"
which = "5.0.0"
wiremock = "0.6.2"
xz2 = "0.1.7"
zip = { version = "4.1.0", default-features = false, features = ["deflate", "time"] }
zstd = { version = "0.13.3", features = ["zstdmt"] }
zip = { version = "0.6.6", default-features = false, features = ["deflate", "time"] }
zstd = { version = "0.13.2", features = ["zstdmt"] }
# Apply mild optimizations to our dependencies in dev mode, which among other things
# improves sha2 performance by about 21x. Opt 1 chosen due to

View file

@ -6,6 +6,8 @@ The following included source code items use a license other than AGPL3:
In the pylib folder:
* The SuperMemo importer: GPL3 and 0BSD.
* The Pauker importer: BSD-3.
* statsbg.py: CC BY 4.0.
In the qt folder:

View file

@ -1,4 +1,4 @@
# Anki®
# Anki
[![Build status](https://badge.buildkite.com/c9edf020a4aec976f9835e54751cc5409d843adbb66d043bd3.svg?branch=main)](https://buildkite.com/ankitects/anki-ci)

View file

@ -27,6 +27,7 @@ pub fn build_and_check_aqt(build: &mut Build) -> Result<()> {
build_forms(build)?;
build_generated_sources(build)?;
build_data_folder(build)?;
build_macos_helper(build)?;
build_wheel(build)?;
check_python(build)?;
Ok(())
@ -38,6 +39,7 @@ fn build_forms(build: &mut Build) -> Result<()> {
let mut py_files = vec![];
for path in ui_files.resolve() {
let outpath = outdir.join(path.file_name().unwrap()).into_string();
py_files.push(outpath.replace(".ui", "_qt5.py"));
py_files.push(outpath.replace(".ui", "_qt6.py"));
}
build.add_action(
@ -335,25 +337,47 @@ impl BuildAction for BuildThemedIcon<'_> {
}
}
fn build_macos_helper(build: &mut Build) -> Result<()> {
if cfg!(target_os = "macos") {
build.add_action(
"qt:aqt:data:lib:libankihelper",
RunCommand {
command: ":pyenv:bin",
args: "$script $out $in",
inputs: hashmap! {
"script" => inputs!["qt/mac/helper_build.py"],
"in" => inputs![glob!["qt/mac/*.swift"]],
"" => inputs!["out/env"],
},
outputs: hashmap! {
"out" => vec!["qt/_aqt/data/lib/libankihelper.dylib"],
},
},
)?;
}
Ok(())
}
fn build_wheel(build: &mut Build) -> Result<()> {
build.add_action(
"wheels:aqt",
BuildWheel {
name: "aqt",
version: anki_version(),
src_folder: "qt/aqt",
gen_folder: "$builddir/qt/_aqt",
platform: None,
deps: inputs![
":qt:aqt",
glob!("qt/aqt/**"),
"qt/pyproject.toml",
"qt/hatch_build.py"
],
deps: inputs![":qt:aqt", glob!("qt/aqt/**"), "python/requirements.aqt.in"],
},
)
}
fn check_python(build: &mut Build) -> Result<()> {
python_format(build, "qt", inputs![glob!("qt/**/*.py")])?;
python_format(
build,
"qt",
inputs![glob!("qt/**/*.py", "qt/bundle/PyOxidizer/**")],
)?;
build.add_action(
"check:pytest:aqt",

View file

@ -0,0 +1,442 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::env;
use anyhow::Result;
use ninja_gen::action::BuildAction;
use ninja_gen::archives::download_and_extract;
use ninja_gen::archives::empty_manifest;
use ninja_gen::archives::with_exe;
use ninja_gen::archives::OnlineArchive;
use ninja_gen::archives::Platform;
use ninja_gen::build::BuildProfile;
use ninja_gen::cargo::CargoBuild;
use ninja_gen::cargo::RustOutput;
use ninja_gen::git::SyncSubmodule;
use ninja_gen::glob;
use ninja_gen::input::BuildInput;
use ninja_gen::inputs;
use ninja_gen::python::PythonEnvironment;
use ninja_gen::Build;
use ninja_gen::Utf8Path;
use crate::anki_version;
use crate::platform::overriden_python_target_platform;
use crate::platform::overriden_rust_target_triple;
#[derive(Debug, PartialEq, Eq)]
enum DistKind {
Standard,
}
impl DistKind {
fn folder_name(&self) -> &'static str {
match self {
DistKind::Standard => "std",
}
}
fn name(&self) -> &'static str {
match self {
DistKind::Standard => "standard",
}
}
}
pub fn build_bundle(build: &mut Build) -> Result<()> {
// install into venv
setup_primary_venv(build)?;
install_anki_wheels(build)?;
// bundle venv into output binary + extra_files
build_pyoxidizer(build)?;
build_artifacts(build)?;
build_binary(build)?;
// package up outputs with Qt/other deps
download_dist_folder_deps(build)?;
build_dist_folder(build, DistKind::Standard)?;
build_packages(build)?;
Ok(())
}
fn targetting_macos_arm() -> bool {
cfg!(all(target_os = "macos", target_arch = "aarch64"))
&& overriden_python_target_platform().is_none()
}
const WIN_AUDIO: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2022-02-09/audio-win-amd64.tar.gz",
sha256: "0815a601baba05e03bc36b568cdc2332b1cf4aa17125fc33c69de125f8dd687f",
};
const MAC_ARM_AUDIO: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2022-05-26/audio-mac-arm64.tar.gz",
sha256: "f6c4af9be59ae1c82a16f5c6307f13cbf31b49ad7b69ce1cb6e0e7b403cfdb8f",
};
const MAC_AMD_AUDIO: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2022-05-26/audio-mac-amd64.tar.gz",
sha256: "ecbb3c878805cdd58b1a0b8e3fd8c753b8ce3ad36c8b5904a79111f9db29ff42",
};
const MAC_ARM_QT6: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2024-02-29/pyqt6.6-mac-arm64.tar.zst",
sha256: "9b2ade4ae9b80506689062845e83e8c60f7fa9843545bf7bb2d11d3e2f105878",
};
const MAC_AMD_QT6: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2024-02-29/pyqt6.6-mac-amd64.tar.zst",
sha256: "dbd0871e4da22820d1fa9ab29220d631467d1178038dcab4b15169ad7f499b1b",
};
const LINUX_QT_PLUGINS: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2023-05-02/qt-plugins-linux-amd64.tar.gz",
sha256: "66bb568aca7242bc55ad419bf5c96755ca15d2a743e1c3a09cba8b83230b138b",
};
const NSIS_PLUGINS: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2023-05-19/nsis.tar.zst",
sha256: "6133f730ece699de19714d0479c73bc848647d277e9cc80dda9b9ebe532b40a8",
};
fn download_dist_folder_deps(build: &mut Build) -> Result<()> {
let mut bundle_deps = vec![":wheels"];
if cfg!(windows) {
download_and_extract(build, "win_amd64_audio", WIN_AUDIO, empty_manifest())?;
download_and_extract(build, "nsis_plugins", NSIS_PLUGINS, empty_manifest())?;
bundle_deps.extend([":extract:win_amd64_audio", ":extract:nsis_plugins"]);
} else if cfg!(target_os = "macos") {
if targetting_macos_arm() {
download_and_extract(build, "mac_arm_audio", MAC_ARM_AUDIO, empty_manifest())?;
download_and_extract(build, "mac_arm_qt6", MAC_ARM_QT6, empty_manifest())?;
bundle_deps.extend([":extract:mac_arm_audio", ":extract:mac_arm_qt6"]);
} else {
download_and_extract(build, "mac_amd_audio", MAC_AMD_AUDIO, empty_manifest())?;
download_and_extract(build, "mac_amd_qt6", MAC_AMD_QT6, empty_manifest())?;
bundle_deps.extend([":extract:mac_amd_audio", ":extract:mac_amd_qt6"]);
}
} else {
download_and_extract(
build,
"linux_qt_plugins",
LINUX_QT_PLUGINS,
empty_manifest(),
)?;
bundle_deps.extend([":extract:linux_qt_plugins"]);
}
build.add_dependency(
"bundle:deps",
inputs![bundle_deps
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()],
);
Ok(())
}
struct Venv {
label: &'static str,
path_without_builddir: &'static str,
}
impl Venv {
fn label_as_target(&self, suffix: &str) -> String {
format!(":{}{suffix}", self.label)
}
}
const PRIMARY_VENV: Venv = Venv {
label: "bundle:pyenv",
path_without_builddir: "bundle/pyenv",
};
fn setup_primary_venv(build: &mut Build) -> Result<()> {
let mut qt6_reqs = inputs![
"python/requirements.bundle.txt",
"python/requirements.qt6_6.txt",
];
if cfg!(windows) {
qt6_reqs = inputs![qt6_reqs, "python/requirements.win.txt"];
}
build.add_action(
PRIMARY_VENV.label,
PythonEnvironment {
folder: PRIMARY_VENV.path_without_builddir,
base_requirements_txt: "python/requirements.base.txt".into(),
requirements_txt: qt6_reqs,
extra_binary_exports: &[],
},
)?;
Ok(())
}
struct InstallAnkiWheels {
venv: Venv,
}
impl BuildAction for InstallAnkiWheels {
fn command(&self) -> &str {
"$pip install --force-reinstall --no-deps $in"
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
build.add_inputs("pip", inputs![self.venv.label_as_target(":pip")]);
build.add_inputs("in", inputs![":wheels"]);
build.add_output_stamp("bundle/wheels.stamp");
}
}
fn install_anki_wheels(build: &mut Build) -> Result<()> {
build.add_action(
"bundle:add_wheels:qt6",
InstallAnkiWheels { venv: PRIMARY_VENV },
)?;
Ok(())
}
fn build_pyoxidizer(build: &mut Build) -> Result<()> {
let offline_build = env::var("OFFLINE_BUILD").is_ok();
build.add_action(
"bundle:pyoxidizer:repo",
SyncSubmodule {
path: "qt/bundle/PyOxidizer",
offline_build,
},
)?;
let target =
overriden_rust_target_triple().unwrap_or_else(|| Platform::current().as_rust_triple());
let output_bin = format!("bundle/rust/{target}/release/pyoxidizer",);
build.add_action(
"bundle:pyoxidizer:bin",
CargoBuild {
inputs: inputs![
":bundle:pyoxidizer:repo",
"out/env",
glob!["qt/bundle/PyOxidizer/**"]
],
// can't use ::Binary() here, as we're in a separate workspace
outputs: &[RustOutput::Data("bin", &with_exe(&output_bin))],
target: Some(target),
extra_args: &format!(
"--manifest-path={} --target-dir={} -p pyoxidizer",
"qt/bundle/PyOxidizer/Cargo.toml", "$builddir/bundle/rust"
),
release_override: Some(BuildProfile::Release),
},
)?;
Ok(())
}
struct BuildArtifacts {}
impl BuildAction for BuildArtifacts {
fn command(&self) -> &str {
"$runner build-artifacts $bundle_root $pyoxidizer_bin"
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
build.add_inputs("pyoxidizer_bin", inputs![":bundle:pyoxidizer:bin"]);
build.add_inputs("", inputs![PRIMARY_VENV.label_as_target("")]);
build.add_inputs("", inputs![":bundle:add_wheels:qt6", glob!["qt/bundle/**"]]);
build.add_variable("bundle_root", "$builddir/bundle");
build.add_outputs_ext(
"pyo3_config",
vec!["bundle/artifacts/pyo3-build-config-file.txt"],
true,
);
}
fn check_output_timestamps(&self) -> bool {
true
}
}
fn build_artifacts(build: &mut Build) -> Result<()> {
build.add_action("bundle:artifacts", BuildArtifacts {})
}
struct BuildBundle {}
impl BuildAction for BuildBundle {
fn command(&self) -> &str {
"$runner build-bundle-binary"
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
build.add_inputs("", inputs![":bundle:artifacts", glob!["qt/bundle/**"]]);
build.add_outputs(
"",
vec![RustOutput::Binary("anki").path(
Utf8Path::new("$builddir/bundle/rust"),
Some(
overriden_rust_target_triple()
.unwrap_or_else(|| Platform::current().as_rust_triple()),
),
// our pyoxidizer bin uses lto on the release profile
BuildProfile::Release,
)],
);
}
}
fn build_binary(build: &mut Build) -> Result<()> {
build.add_action("bundle:binary", BuildBundle {})
}
struct BuildDistFolder {
kind: DistKind,
deps: BuildInput,
}
impl BuildAction for BuildDistFolder {
fn command(&self) -> &str {
"$runner build-dist-folder $kind $out_folder "
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
build.add_inputs("", &self.deps);
build.add_variable("kind", self.kind.name());
let folder = match self.kind {
DistKind::Standard => "bundle/std",
};
build.add_outputs("out_folder", vec![folder]);
build.add_outputs("stamp", vec![format!("{folder}.stamp")]);
}
fn check_output_timestamps(&self) -> bool {
true
}
}
fn build_dist_folder(build: &mut Build, kind: DistKind) -> Result<()> {
let deps = inputs![":bundle:deps", ":bundle:binary", glob!["qt/bundle/**"]];
let group = match kind {
DistKind::Standard => "bundle:folder:std",
};
build.add_action(group, BuildDistFolder { kind, deps })
}
fn build_packages(build: &mut Build) -> Result<()> {
if cfg!(windows) {
build_windows_installers(build)
} else if cfg!(target_os = "macos") {
build_mac_app(build, DistKind::Standard)?;
build_dmgs(build)
} else {
build_tarball(build, DistKind::Standard)
}
}
struct BuildTarball {
kind: DistKind,
}
impl BuildAction for BuildTarball {
fn command(&self) -> &str {
"chmod -R a+r $folder && tar -I '$zstd' --transform $transform -cf $tarball -C $folder ."
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
let input_folder_name = self.kind.folder_name();
let input_folder_target = format!(":bundle:folder:{input_folder_name}");
let input_folder_path = format!("$builddir/bundle/{input_folder_name}");
let version = anki_version();
let qt = match self.kind {
DistKind::Standard => "qt6",
};
let output_folder_base = format!("anki-{version}-linux-{qt}");
let output_tarball = format!("bundle/package/{output_folder_base}.tar.zst");
build.add_inputs("", inputs![input_folder_target]);
build.add_variable("zstd", "zstd -c --long -T0 -18");
build.add_variable("transform", format!("s%^.%{output_folder_base}%S"));
build.add_variable("folder", input_folder_path);
build.add_outputs("tarball", vec![output_tarball]);
}
}
fn build_tarball(build: &mut Build, kind: DistKind) -> Result<()> {
let name = kind.folder_name();
build.add_action(format!("bundle:package:{name}"), BuildTarball { kind })
}
struct BuildWindowsInstallers {}
impl BuildAction for BuildWindowsInstallers {
fn command(&self) -> &str {
"cargo run -p makeexe --target-dir=out/rust -- $version $src_root $bundle_root $out"
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
let version = anki_version();
let outputs = ["qt6"].iter().map(|qt| {
let output_base = format!("anki-{version}-windows-{qt}");
format!("bundle/package/{output_base}.exe")
});
build.add_inputs("", inputs![":bundle:folder:std"]);
build.add_variable("version", &version);
build.add_variable("bundle_root", "$builddir/bundle");
build.add_outputs("out", outputs);
}
}
fn build_windows_installers(build: &mut Build) -> Result<()> {
build.add_action("bundle:package", BuildWindowsInstallers {})
}
struct BuildMacApp {
kind: DistKind,
}
impl BuildAction for BuildMacApp {
fn command(&self) -> &str {
"cargo run -p makeapp --target-dir=out/rust -- build-app $version $kind $stamp"
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
let folder_name = self.kind.folder_name();
build.add_inputs("", inputs![format!(":bundle:folder:{folder_name}")]);
build.add_variable("version", anki_version());
build.add_variable("kind", self.kind.name());
build.add_outputs("stamp", vec![format!("bundle/app/{folder_name}.stamp")]);
}
}
fn build_mac_app(build: &mut Build, kind: DistKind) -> Result<()> {
build.add_action(format!("bundle:app:{}", kind.name()), BuildMacApp { kind })
}
struct BuildDmgs {}
impl BuildAction for BuildDmgs {
fn command(&self) -> &str {
"cargo run -p makeapp --target-dir=out/rust -- build-dmgs $dmgs"
}
fn files(&mut self, build: &mut impl ninja_gen::build::FilesHandle) {
let version = anki_version();
let platform = if targetting_macos_arm() {
"apple"
} else {
"intel"
};
let qt = &["qt6"][..];
let dmgs = qt
.iter()
.map(|qt| format!("bundle/dmg/anki-{version}-mac-{platform}-{qt}.dmg"));
build.add_inputs("", inputs![":bundle:app"]);
build.add_outputs("dmgs", dmgs);
}
}
fn build_dmgs(build: &mut Build) -> Result<()> {
build.add_action("bundle:dmg", BuildDmgs {})
}

View file

@ -1,44 +0,0 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use anyhow::Result;
use ninja_gen::archives::download_and_extract;
use ninja_gen::archives::empty_manifest;
use ninja_gen::archives::OnlineArchive;
use ninja_gen::command::RunCommand;
use ninja_gen::hashmap;
use ninja_gen::inputs;
use ninja_gen::Build;
pub fn setup_uv_universal(build: &mut Build) -> Result<()> {
if !cfg!(target_arch = "aarch64") {
return Ok(());
}
build.add_action(
"launcher:uv_universal",
RunCommand {
command: "/usr/bin/lipo",
args: "-create -output $out $arm_bin $x86_bin",
inputs: hashmap! {
"arm_bin" => inputs![":extract:uv:bin"],
"x86_bin" => inputs![":extract:uv_mac_x86:bin"],
},
outputs: hashmap! {
"out" => vec!["launcher/uv"],
},
},
)
}
pub fn build_launcher(build: &mut Build) -> Result<()> {
setup_uv_universal(build)?;
download_and_extract(build, "nsis_plugins", NSIS_PLUGINS, empty_manifest())?;
Ok(())
}
const NSIS_PLUGINS: OnlineArchive = OnlineArchive {
url: "https://github.com/ankitects/anki-bundle-extras/releases/download/anki-2023-05-19/nsis.tar.zst",
sha256: "6133f730ece699de19714d0479c73bc848647d277e9cc80dda9b9ebe532b40a8",
};

View file

@ -2,7 +2,7 @@
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
mod aqt;
mod launcher;
mod bundle;
mod platform;
mod pylib;
mod python;
@ -13,14 +13,13 @@ use std::env;
use anyhow::Result;
use aqt::build_and_check_aqt;
use launcher::build_launcher;
use bundle::build_bundle;
use ninja_gen::glob;
use ninja_gen::inputs;
use ninja_gen::protobuf::check_proto;
use ninja_gen::protobuf::setup_protoc;
use ninja_gen::python::setup_uv;
use ninja_gen::python::setup_python;
use ninja_gen::Build;
use platform::overriden_python_venv_platform;
use pylib::build_pylib;
use pylib::check_pylib;
use python::check_python;
@ -48,10 +47,7 @@ fn main() -> Result<()> {
check_proto(build, inputs![glob!["proto/**/*.proto"]])?;
if env::var("OFFLINE_BUILD").is_err() {
setup_uv(
build,
overriden_python_venv_platform().unwrap_or(build.host_platform),
)?;
setup_python(build)?;
}
setup_venv(build)?;
@ -61,7 +57,7 @@ fn main() -> Result<()> {
build_and_check_aqt(build)?;
if env::var("OFFLINE_BUILD").is_err() {
build_launcher(build)?;
build_bundle(build)?;
}
setup_sphinx(build)?;

View file

@ -5,30 +5,18 @@ use std::env;
use ninja_gen::archives::Platform;
/// Please see [`overriden_python_target_platform()`] for details.
/// Usually None to use the host architecture; can be overriden by setting
/// MAC_X86 to build for x86_64 on Apple Silicon
pub fn overriden_rust_target_triple() -> Option<&'static str> {
overriden_python_wheel_platform().map(|p| p.as_rust_triple())
overriden_python_target_platform().map(|p| p.as_rust_triple())
}
/// Usually None to use the host architecture, except on Windows which
/// always uses x86_64, since WebEngine is unavailable for ARM64.
pub fn overriden_python_venv_platform() -> Option<Platform> {
if cfg!(target_os = "windows") {
Some(Platform::WindowsX64)
/// Usually None to use the host architecture; can be overriden by setting
/// MAC_X86 to build for x86_64 on Apple Silicon
pub fn overriden_python_target_platform() -> Option<Platform> {
if env::var("MAC_X86").is_ok() {
Some(Platform::MacX64)
} else {
None
}
}
/// Like [`overriden_python_venv_platform`], but:
/// If MAC_X86 is set, an X86 wheel will be built on macOS ARM.
/// If LIN_ARM64 is set, an ARM64 wheel will be built on Linux AMD64.
pub fn overriden_python_wheel_platform() -> Option<Platform> {
if env::var("MAC_X86").is_ok() {
Some(Platform::MacX64)
} else if env::var("LIN_ARM64").is_ok() {
Some(Platform::LinuxArm)
} else {
overriden_python_venv_platform()
}
}

View file

@ -14,7 +14,7 @@ use ninja_gen::python::PythonTest;
use ninja_gen::Build;
use crate::anki_version;
use crate::platform::overriden_python_wheel_platform;
use crate::platform::overriden_python_target_platform;
use crate::python::BuildWheel;
use crate::python::GenPythonProto;
@ -50,7 +50,7 @@ pub fn build_pylib(build: &mut Build) -> Result<()> {
output: &format!(
"pylib/anki/_rsbridge.{}",
match build.host_platform {
Platform::WindowsX64 | Platform::WindowsArm => "pyd",
Platform::WindowsX64 => "pyd",
_ => "so",
}
),
@ -64,12 +64,13 @@ pub fn build_pylib(build: &mut Build) -> Result<()> {
BuildWheel {
name: "anki",
version: anki_version(),
platform: overriden_python_wheel_platform().or(Some(build.host_platform)),
src_folder: "pylib/anki",
gen_folder: "$builddir/pylib/anki",
platform: overriden_python_target_platform().or(Some(build.host_platform)),
deps: inputs![
":pylib:anki",
glob!("pylib/anki/**"),
"pylib/pyproject.toml",
"pylib/hatch_build.py"
"python/requirements.anki.in",
],
},
)?;

View file

@ -1,73 +1,93 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::env;
use anyhow::Result;
use ninja_gen::action::BuildAction;
use ninja_gen::archives::Platform;
use ninja_gen::build::FilesHandle;
use ninja_gen::command::RunCommand;
use ninja_gen::copy::CopyFiles;
use ninja_gen::glob;
use ninja_gen::hashmap;
use ninja_gen::input::BuildInput;
use ninja_gen::inputs;
use ninja_gen::python::python_format;
use ninja_gen::python::PythonEnvironment;
use ninja_gen::python::PythonLint;
use ninja_gen::python::PythonTypecheck;
use ninja_gen::python::RuffCheck;
use ninja_gen::rsync::RsyncFiles;
use ninja_gen::Build;
/// Normalize version string by removing leading zeros from numeric parts
/// while preserving pre-release markers (b1, rc2, a3, etc.)
fn normalize_version(version: &str) -> String {
version
.split('.')
.map(|part| {
// Check if the part contains only digits
if part.chars().all(|c| c.is_ascii_digit()) {
// Numeric part: remove leading zeros
part.parse::<u32>().unwrap_or(0).to_string()
} else {
// Mixed part (contains both numbers and pre-release markers)
// Split on first non-digit character and normalize the numeric prefix
let chars = part.chars();
let mut numeric_prefix = String::new();
let mut rest = String::new();
let mut found_non_digit = false;
for ch in chars {
if ch.is_ascii_digit() && !found_non_digit {
numeric_prefix.push(ch);
} else {
found_non_digit = true;
rest.push(ch);
}
}
if numeric_prefix.is_empty() {
part.to_string()
} else {
let normalized_prefix = numeric_prefix.parse::<u32>().unwrap_or(0).to_string();
format!("{normalized_prefix}{rest}")
}
}
})
.collect::<Vec<_>>()
.join(".")
}
// When updating Qt, make sure to update the .txt file in bundle.rs as well.
pub fn setup_venv(build: &mut Build) -> Result<()> {
let extra_binary_exports = &["mypy", "ruff", "pytest", "protoc-gen-mypy"];
let platform_deps = if cfg!(windows) {
inputs![
"python/requirements.qt6_6.txt",
"python/requirements.win.txt",
]
} else if cfg!(target_os = "macos") {
inputs!["python/requirements.qt6_6.txt",]
} else if std::env::var("PYTHONPATH").is_ok() {
// assume we have a system-provided Qt
inputs![]
} else if cfg!(target_arch = "aarch64") {
inputs!["python/requirements.qt6_8.txt"]
} else {
inputs!["python/requirements.qt6_6.txt"]
};
let requirements_txt = inputs!["python/requirements.dev.txt", platform_deps];
build.add_action(
"pyenv",
PythonEnvironment {
venv_folder: "pyenv",
deps: inputs![
"pyproject.toml",
"pylib/pyproject.toml",
"qt/pyproject.toml",
"uv.lock"
folder: "pyenv",
base_requirements_txt: inputs!["python/requirements.base.txt"],
requirements_txt,
extra_binary_exports: &[
"pip-compile",
"pip-sync",
"mypy",
"black", // Required for offline build
"isort",
"pylint",
"pytest",
"protoc-gen-mypy", // ditto
],
extra_args: "--all-packages --extra qt --extra audio",
extra_binary_exports,
},
)?;
// optional venvs for testing other Qt versions
let mut venv_reqs = inputs!["python/requirements.bundle.txt"];
if cfg!(windows) {
venv_reqs = inputs![venv_reqs, "python/requirements.win.txt"];
}
build.add_action(
"pyenv-qt6.8",
PythonEnvironment {
folder: "pyenv-qt6.8",
base_requirements_txt: inputs!["python/requirements.base.txt"],
requirements_txt: inputs![&venv_reqs, "python/requirements.qt6_8.txt"],
extra_binary_exports: &[],
},
)?;
build.add_action(
"pyenv-qt5.15",
PythonEnvironment {
folder: "pyenv-qt5.15",
base_requirements_txt: inputs!["python/requirements.base.txt"],
requirements_txt: inputs![&venv_reqs, "python/requirements.qt5_15.txt"],
extra_binary_exports: &[],
},
)?;
build.add_action(
"pyenv-qt5.14",
PythonEnvironment {
folder: "pyenv-qt5.14",
base_requirements_txt: inputs!["python/requirements.base.txt"],
requirements_txt: inputs![venv_reqs, "python/requirements.qt5_14.txt"],
extra_binary_exports: &[],
},
)?;
@ -113,66 +133,45 @@ impl BuildAction for GenPythonProto {
pub struct BuildWheel {
pub name: &'static str,
pub version: String,
pub src_folder: &'static str,
pub gen_folder: &'static str,
pub platform: Option<Platform>,
pub deps: BuildInput,
}
impl BuildAction for BuildWheel {
fn command(&self) -> &str {
"$uv build --wheel --out-dir=$out_dir --project=$project_dir"
"$pyenv_bin $script $src $gen $out"
}
fn files(&mut self, build: &mut impl FilesHandle) {
if std::env::var("OFFLINE_BUILD").ok().as_deref() == Some("1") {
let uv_path =
std::env::var("UV_BINARY").expect("UV_BINARY must be set in OFFLINE_BUILD mode");
build.add_inputs("uv", inputs![uv_path]);
} else {
build.add_inputs("uv", inputs![":uv_binary"]);
}
build.add_inputs("pyenv_bin", inputs![":pyenv:bin"]);
build.add_inputs("script", inputs!["python/write_wheel.py"]);
build.add_inputs("", &self.deps);
build.add_variable("src", self.src_folder);
build.add_variable("gen", self.gen_folder);
// Set the project directory based on which package we're building
let project_dir = if self.name == "anki" { "pylib" } else { "qt" };
build.add_variable("project_dir", project_dir);
// Set environment variable for uv to use our pyenv
build.add_variable("pyenv_path", "$builddir/pyenv");
build.add_env_var("UV_PROJECT_ENVIRONMENT", "$pyenv_path");
// Set output directory
build.add_variable("out_dir", "$builddir/wheels/");
// Calculate the wheel filename that uv will generate
let tag = if let Some(platform) = self.platform {
let platform_tag = match platform {
Platform::LinuxX64 => "manylinux_2_36_x86_64",
Platform::LinuxArm => "manylinux_2_36_aarch64",
let platform = match platform {
Platform::LinuxX64 => "manylinux_2_35_x86_64",
Platform::LinuxArm => "manylinux_2_35_aarch64",
Platform::MacX64 => "macosx_12_0_x86_64",
Platform::MacArm => "macosx_12_0_arm64",
Platform::WindowsX64 => "win_amd64",
Platform::WindowsArm => "win_arm64",
};
format!("cp39-abi3-{platform_tag}")
format!("cp39-abi3-{platform}")
} else {
"py3-none-any".into()
};
// Set environment variable for hatch_build.py to use the correct platform tag
build.add_variable("wheel_tag", &tag);
build.add_env_var("ANKI_WHEEL_TAG", "$wheel_tag");
let name = self.name;
let normalized_version = normalize_version(&self.version);
let wheel_path = format!("wheels/{name}-{normalized_version}-{tag}.whl");
let version = &self.version;
let wheel_path = format!("wheels/{name}-{version}-{tag}.whl");
build.add_outputs("out", vec![wheel_path]);
}
}
pub fn check_python(build: &mut Build) -> Result<()> {
python_format(build, "ftl", inputs![glob!("ftl/**/*.py")])?;
python_format(build, "tools", inputs![glob!("tools/**/*.py")])?;
build.add_action(
@ -184,6 +183,7 @@ pub fn check_python(build: &mut Build) -> Result<()> {
"qt/tools",
"out/pylib/anki",
"out/qt/_aqt",
"ftl",
"python",
"tools",
],
@ -195,26 +195,60 @@ pub fn check_python(build: &mut Build) -> Result<()> {
},
)?;
let ruff_folders = &["qt/aqt", "ftl", "pylib/tools", "tools", "python"];
let ruff_deps = inputs![
glob!["{pylib,ftl,qt,python,tools}/**/*.py"],
":pylib:anki",
":qt:aqt"
];
add_pylint(build)?;
Ok(())
}
fn add_pylint(build: &mut Build) -> Result<()> {
// pylint does not support PEP420 implicit namespaces split across import paths,
// so we need to merge our pylib sources and generated files before invoking it,
// and add a top-level __init__.py
build.add_action(
"check:ruff",
RuffCheck {
folders: ruff_folders,
deps: ruff_deps.clone(),
check_only: true,
"check:pylint:copy_pylib",
RsyncFiles {
inputs: inputs![":pylib:anki"],
target_folder: "pylint/anki",
strip_prefix: "$builddir/pylib/anki",
// avoid copying our large rsbridge binary
extra_args: "--links",
},
)?;
build.add_action(
"fix:ruff",
RuffCheck {
folders: ruff_folders,
deps: ruff_deps,
check_only: false,
"check:pylint:copy_pylib",
RsyncFiles {
inputs: inputs![glob!["pylib/anki/**"]],
target_folder: "pylint/anki",
strip_prefix: "pylib/anki",
extra_args: "",
},
)?;
build.add_action(
"check:pylint:copy_pylib",
RunCommand {
command: ":pyenv:bin",
args: "$script $out",
inputs: hashmap! { "script" => inputs!["python/mkempty.py"] },
outputs: hashmap! { "out" => vec!["pylint/anki/__init__.py"] },
},
)?;
build.add_action(
"check:pylint",
PythonLint {
folders: &[
"$builddir/pylint/anki",
"qt/aqt",
"ftl",
"pylib/tools",
"tools",
"python",
],
pylint_ini: inputs![".pylintrc"],
deps: inputs![
":check:pylint:copy_pylib",
":qt:aqt",
glob!("{pylib/tools,ftl,qt,python,tools}/**/*.py")
],
},
)?;
@ -227,23 +261,17 @@ struct Sphinx {
impl BuildAction for Sphinx {
fn command(&self) -> &str {
if std::env::var("OFFLINE_BUILD").ok().as_deref() == Some("1") {
"$python python/sphinx/build.py"
if env::var("OFFLINE_BUILD").is_err() {
"$pip install sphinx sphinx_rtd_theme sphinx-autoapi \
&& $python python/sphinx/build.py"
} else {
"$uv sync --extra sphinx && $python python/sphinx/build.py"
"$python python/sphinx/build.py"
}
}
fn files(&mut self, build: &mut impl FilesHandle) {
if std::env::var("OFFLINE_BUILD").ok().as_deref() == Some("1") {
let uv_path =
std::env::var("UV_BINARY").expect("UV_BINARY must be set in OFFLINE_BUILD mode");
build.add_inputs("uv", inputs![uv_path]);
} else {
build.add_inputs("uv", inputs![":uv_binary"]);
// Set environment variable to use the existing pyenv
build.add_variable("pyenv_path", "$builddir/pyenv");
build.add_env_var("UV_PROJECT_ENVIRONMENT", "$pyenv_path");
if env::var("OFFLINE_BUILD").is_err() {
build.add_inputs("pip", inputs![":pyenv:pip"]);
}
build.add_inputs("python", inputs![":pyenv:bin"]);
build.add_inputs("", &self.deps);
@ -266,35 +294,8 @@ pub(crate) fn setup_sphinx(build: &mut Build) -> Result<()> {
build.add_action(
"python:sphinx",
Sphinx {
deps: inputs![
":pylib",
":qt",
":python:sphinx:copy_conf",
"pyproject.toml"
],
deps: inputs![":pylib", ":qt", ":python:sphinx:copy_conf"],
},
)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_normalize_version_basic() {
assert_eq!(normalize_version("1.2.3"), "1.2.3");
assert_eq!(normalize_version("01.02.03"), "1.2.3");
assert_eq!(normalize_version("1.0.0"), "1.0.0");
}
#[test]
fn test_normalize_version_with_prerelease() {
assert_eq!(normalize_version("1.2.3b1"), "1.2.3b1");
assert_eq!(normalize_version("01.02.03b1"), "1.2.3b1");
assert_eq!(normalize_version("1.0.0rc2"), "1.0.0rc2");
assert_eq!(normalize_version("2.1.0a3"), "2.1.0a3");
assert_eq!(normalize_version("1.2.3beta1"), "1.2.3beta1");
assert_eq!(normalize_version("1.2.3alpha1"), "1.2.3alpha1");
}
}

View file

@ -154,7 +154,7 @@ fn build_rsbridge(build: &mut Build) -> Result<()> {
"$builddir/buildhash",
// building on Windows requires python3.lib
if cfg!(windows) {
inputs![":pyenv:bin"]
inputs![":extract:python"]
} else {
inputs![]
}
@ -169,7 +169,7 @@ fn build_rsbridge(build: &mut Build) -> Result<()> {
pub fn check_rust(build: &mut Build) -> Result<()> {
let inputs = inputs![
glob!("{rslib/**,pylib/rsbridge/**,ftl/**,build/**,qt/launcher/**,tools/minilints/**}"),
glob!("{rslib/**,pylib/rsbridge/**,ftl/**,build/**,tools/workspace-hack/**}"),
"Cargo.lock",
"Cargo.toml",
"rust-toolchain.toml",
@ -247,7 +247,7 @@ pub fn check_minilints(build: &mut Build) -> Result<()> {
let files = inputs![
glob![
"**/*.{py,rs,ts,svelte,mjs,md}",
"{node_modules,ts/.svelte-kit}/**"
"{node_modules,qt/bundle/PyOxidizer,ts/.svelte-kit}/**"
],
"Cargo.lock"
];

View file

@ -16,26 +16,5 @@ globset.workspace = true
itertools.workspace = true
maplit.workspace = true
num_cpus.workspace = true
regex.workspace = true
serde_json.workspace = true
sha2.workspace = true
walkdir.workspace = true
which.workspace = true
[target.'cfg(windows)'.dependencies]
reqwest = { workspace = true, features = ["blocking", "json", "native-tls"] }
[target.'cfg(not(windows))'.dependencies]
reqwest = { workspace = true, features = ["blocking", "json", "rustls-tls"] }
[[bin]]
name = "update_uv"
path = "src/bin/update_uv.rs"
[[bin]]
name = "update_protoc"
path = "src/bin/update_protoc.rs"
[[bin]]
name = "update_node"
path = "src/bin/update_node.rs"

View file

@ -49,46 +49,6 @@ pub trait BuildAction {
}
fn name(&self) -> &'static str {
std::any::type_name::<Self>()
.split("::")
.last()
.unwrap()
.split('<')
.next()
.unwrap()
std::any::type_name::<Self>().split("::").last().unwrap()
}
}
#[cfg(test)]
trait TestBuildAction {}
#[cfg(test)]
impl<T: TestBuildAction + ?Sized> BuildAction for T {
fn command(&self) -> &str {
"test"
}
fn files(&mut self, _build: &mut impl FilesHandle) {}
}
#[allow(dead_code, unused_variables)]
#[test]
fn should_strip_regions_in_type_name() {
struct Bare;
impl TestBuildAction for Bare {}
assert_eq!(Bare {}.name(), "Bare");
struct WithLifeTime<'a>(&'a str);
impl TestBuildAction for WithLifeTime<'_> {}
assert_eq!(WithLifeTime("test").name(), "WithLifeTime");
struct WithMultiLifeTime<'a, 'b>(&'a str, &'b str);
impl TestBuildAction for WithMultiLifeTime<'_, '_> {}
assert_eq!(
WithMultiLifeTime("test", "test").name(),
"WithMultiLifeTime"
);
struct WithGeneric<T>(T);
impl<T> TestBuildAction for WithGeneric<T> {}
assert_eq!(WithGeneric(3).name(), "WithGeneric");
}

View file

@ -26,21 +26,22 @@ pub enum Platform {
MacX64,
MacArm,
WindowsX64,
WindowsArm,
}
impl Platform {
pub fn current() -> Self {
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
match (os, arch) {
("linux", "x86_64") => Self::LinuxX64,
("linux", "aarch64") => Self::LinuxArm,
("macos", "x86_64") => Self::MacX64,
("macos", "aarch64") => Self::MacArm,
("windows", "x86_64") => Self::WindowsX64,
("windows", "aarch64") => Self::WindowsArm,
_ => panic!("unsupported os/arch {os} {arch} - PR welcome!"),
if cfg!(windows) {
Self::WindowsX64
} else {
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;
match (os, arch) {
("linux", "x86_64") => Self::LinuxX64,
("linux", "aarch64") => Self::LinuxArm,
("macos", "x86_64") => Self::MacX64,
("macos", "aarch64") => Self::MacArm,
_ => panic!("unsupported os/arch {os} {arch} - PR welcome!"),
}
}
}
@ -61,13 +62,12 @@ impl Platform {
Platform::MacX64 => "x86_64-apple-darwin",
Platform::MacArm => "aarch64-apple-darwin",
Platform::WindowsX64 => "x86_64-pc-windows-msvc",
Platform::WindowsArm => "aarch64-pc-windows-msvc",
}
}
}
/// Append .exe to path if on Windows.
pub fn with_exe(path: &str) -> Cow<'_, str> {
pub fn with_exe(path: &str) -> Cow<str> {
if cfg!(windows) {
format!("{path}.exe").into()
} else {

View file

@ -1,268 +0,0 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::error::Error;
use std::fs;
use std::path::Path;
use regex::Regex;
use reqwest::blocking::Client;
use serde_json::Value;
#[derive(Debug)]
struct NodeRelease {
version: String,
files: Vec<NodeFile>,
}
#[derive(Debug)]
struct NodeFile {
filename: String,
url: String,
}
fn main() -> Result<(), Box<dyn Error>> {
let release_info = fetch_node_release_info()?;
let new_text = generate_node_archive_function(&release_info)?;
update_node_text(&new_text)?;
println!("Node.js archive function updated successfully!");
Ok(())
}
fn fetch_node_release_info() -> Result<NodeRelease, Box<dyn Error>> {
let client = Client::new();
// Get the Node.js release info
let response = client
.get("https://nodejs.org/dist/index.json")
.header("User-Agent", "anki-build-updater")
.send()?;
let releases: Vec<Value> = response.json()?;
// Find the latest LTS release
let latest = releases
.iter()
.find(|release| {
// LTS releases have a non-false "lts" field
release["lts"].as_str().is_some() && release["lts"] != false
})
.ok_or("No LTS releases found")?;
let version = latest["version"]
.as_str()
.ok_or("Version not found")?
.to_string();
let files = latest["files"]
.as_array()
.ok_or("Files array not found")?
.iter()
.map(|f| f.as_str().unwrap_or(""))
.collect::<Vec<_>>();
let lts_name = latest["lts"].as_str().unwrap_or("unknown");
println!("Found Node.js LTS version: {version} ({lts_name})");
// Map platforms to their expected file keys and full filenames
let platform_mapping = vec![
(
"linux-x64",
"linux-x64",
format!("node-{version}-linux-x64.tar.xz"),
),
(
"linux-arm64",
"linux-arm64",
format!("node-{version}-linux-arm64.tar.xz"),
),
(
"darwin-x64",
"osx-x64-tar",
format!("node-{version}-darwin-x64.tar.xz"),
),
(
"darwin-arm64",
"osx-arm64-tar",
format!("node-{version}-darwin-arm64.tar.xz"),
),
(
"win-x64",
"win-x64-zip",
format!("node-{version}-win-x64.zip"),
),
(
"win-arm64",
"win-arm64-zip",
format!("node-{version}-win-arm64.zip"),
),
];
let mut node_files = Vec::new();
for (platform, file_key, filename) in platform_mapping {
// Check if this file exists in the release
if files.contains(&file_key) {
let url = format!("https://nodejs.org/dist/{version}/{filename}");
node_files.push(NodeFile {
filename: filename.clone(),
url,
});
println!("Found file for {platform}: {filename} (key: {file_key})");
} else {
return Err(
format!("File not found for {platform} (key: {file_key}): {filename}").into(),
);
}
}
Ok(NodeRelease {
version,
files: node_files,
})
}
fn generate_node_archive_function(release: &NodeRelease) -> Result<String, Box<dyn Error>> {
let client = Client::new();
// Fetch the SHASUMS256.txt file once
println!("Fetching SHA256 checksums...");
let shasums_url = format!("https://nodejs.org/dist/{}/SHASUMS256.txt", release.version);
let shasums_response = client
.get(&shasums_url)
.header("User-Agent", "anki-build-updater")
.send()?;
let shasums_text = shasums_response.text()?;
// Create a mapping from filename patterns to platform names - using the exact
// patterns we stored in files
let platform_mapping = vec![
("linux-x64.tar.xz", "LinuxX64"),
("linux-arm64.tar.xz", "LinuxArm"),
("darwin-x64.tar.xz", "MacX64"),
("darwin-arm64.tar.xz", "MacArm"),
("win-x64.zip", "WindowsX64"),
("win-arm64.zip", "WindowsArm"),
];
let mut platform_blocks = Vec::new();
for (file_pattern, platform_name) in platform_mapping {
// Find the file that ends with this pattern
if let Some(file) = release
.files
.iter()
.find(|f| f.filename.ends_with(file_pattern))
{
// Find the SHA256 for this file
let sha256 = shasums_text
.lines()
.find(|line| line.contains(&file.filename))
.and_then(|line| line.split_whitespace().next())
.ok_or_else(|| format!("SHA256 not found for {}", file.filename))?;
println!(
"Found SHA256 for {}: {} => {}",
platform_name, file.filename, sha256
);
let block = format!(
" Platform::{} => OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }},",
platform_name, file.url, sha256
);
platform_blocks.push(block);
} else {
return Err(format!(
"File not found for platform {platform_name}: no file ending with {file_pattern}"
)
.into());
}
}
let function = format!(
"pub fn node_archive(platform: Platform) -> OnlineArchive {{\n match platform {{\n{}\n }}\n}}",
platform_blocks.join("\n")
);
Ok(function)
}
fn update_node_text(new_function: &str) -> Result<(), Box<dyn Error>> {
let node_rs_content = read_node_rs()?;
// Regex to match the entire node_archive function with proper multiline
// matching
let re = Regex::new(
r"(?s)pub fn node_archive\(platform: Platform\) -> OnlineArchive \{.*?\n\s*\}\s*\n\s*\}",
)?;
let updated_content = re.replace(&node_rs_content, new_function);
write_node_rs(&updated_content)?;
Ok(())
}
fn read_node_rs() -> Result<String, Box<dyn Error>> {
// Use CARGO_MANIFEST_DIR to get the crate root, then find src/node.rs
let manifest_dir =
std::env::var("CARGO_MANIFEST_DIR").map_err(|_| "CARGO_MANIFEST_DIR not set")?;
let path = Path::new(&manifest_dir).join("src").join("node.rs");
Ok(fs::read_to_string(path)?)
}
fn write_node_rs(content: &str) -> Result<(), Box<dyn Error>> {
// Use CARGO_MANIFEST_DIR to get the crate root, then find src/node.rs
let manifest_dir =
std::env::var("CARGO_MANIFEST_DIR").map_err(|_| "CARGO_MANIFEST_DIR not set")?;
let path = Path::new(&manifest_dir).join("src").join("node.rs");
fs::write(path, content)?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_regex_replacement() {
let sample_content = r#"Some other code
pub fn node_archive(platform: Platform) -> OnlineArchive {
match platform {
Platform::LinuxX64 => OnlineArchive {
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-x64.tar.xz",
sha256: "old_hash",
},
Platform::MacX64 => OnlineArchive {
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-x64.tar.xz",
sha256: "old_hash",
},
}
}
More code here"#;
let new_function = r#"pub fn node_archive(platform: Platform) -> OnlineArchive {
match platform {
Platform::LinuxX64 => OnlineArchive {
url: "https://nodejs.org/dist/v21.0.0/node-v21.0.0-linux-x64.tar.xz",
sha256: "new_hash",
},
Platform::MacX64 => OnlineArchive {
url: "https://nodejs.org/dist/v21.0.0/node-v21.0.0-darwin-x64.tar.xz",
sha256: "new_hash",
},
}
}"#;
let re = Regex::new(
r"(?s)pub fn node_archive\(platform: Platform\) -> OnlineArchive \{.*?\n\s*\}\s*\n\s*\}"
).unwrap();
let result = re.replace(sample_content, new_function);
assert!(result.contains("v21.0.0"));
assert!(result.contains("new_hash"));
assert!(!result.contains("old_hash"));
assert!(result.contains("Some other code"));
assert!(result.contains("More code here"));
}
}

View file

@ -1,125 +0,0 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::error::Error;
use std::fs;
use std::path::Path;
use regex::Regex;
use reqwest::blocking::Client;
use serde_json::Value;
use sha2::Digest;
use sha2::Sha256;
fn fetch_protoc_release_info() -> Result<String, Box<dyn Error>> {
let client = Client::new();
println!("Fetching latest protoc release info from GitHub...");
// Fetch latest release info
let response = client
.get("https://api.github.com/repos/protocolbuffers/protobuf/releases/latest")
.header("User-Agent", "Anki-Build-Script")
.send()?;
let release_info: Value = response.json()?;
let assets = release_info["assets"]
.as_array()
.expect("assets should be an array");
// Map platform names to their corresponding asset patterns
let platform_patterns = [
("LinuxX64", "linux-x86_64"),
("LinuxArm", "linux-aarch_64"),
("MacX64", "osx-universal_binary"), // Mac uses universal binary for both
("MacArm", "osx-universal_binary"),
("WindowsX64", "win64"), // Windows uses x86 binary for both archs
("WindowsArm", "win64"),
];
let mut match_blocks = Vec::new();
for (platform, pattern) in platform_patterns {
// Find the asset matching the platform pattern
let asset = assets.iter().find(|asset| {
let name = asset["name"].as_str().unwrap_or("");
name.starts_with("protoc-") && name.contains(pattern) && name.ends_with(".zip")
});
if asset.is_none() {
eprintln!("No asset found for platform {platform} pattern {pattern}");
continue;
}
let asset = asset.unwrap();
let download_url = asset["browser_download_url"].as_str().unwrap();
let asset_name = asset["name"].as_str().unwrap();
// Download the file and calculate SHA256 locally
println!("Downloading and checksumming {asset_name} for {platform}...");
let response = client
.get(download_url)
.header("User-Agent", "Anki-Build-Script")
.send()?;
let bytes = response.bytes()?;
let mut hasher = Sha256::new();
hasher.update(&bytes);
let sha256 = format!("{:x}", hasher.finalize());
// Handle platform-specific match patterns
let match_pattern = match platform {
"MacX64" => "Platform::MacX64 | Platform::MacArm",
"MacArm" => continue, // Skip MacArm since it's handled with MacX64
"WindowsX64" => "Platform::WindowsX64 | Platform::WindowsArm",
"WindowsArm" => continue, // Skip WindowsArm since it's handled with WindowsX64
_ => &format!("Platform::{platform}"),
};
match_blocks.push(format!(
" {match_pattern} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}"
));
}
Ok(format!(
"pub fn protoc_archive(platform: Platform) -> OnlineArchive {{\n match platform {{\n{}\n }}\n}}",
match_blocks.join(",\n")
))
}
fn read_protobuf_rs() -> Result<String, Box<dyn Error>> {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
let path = Path::new(&manifest_dir).join("src/protobuf.rs");
println!("Reading {}", path.display());
let content = fs::read_to_string(path)?;
Ok(content)
}
fn update_protoc_text(old_text: &str, new_protoc_text: &str) -> Result<String, Box<dyn Error>> {
let re =
Regex::new(r"(?ms)^pub fn protoc_archive\(platform: Platform\) -> OnlineArchive \{.*?\n\}")
.unwrap();
if !re.is_match(old_text) {
return Err("Could not find protoc_archive function block to replace".into());
}
let new_content = re.replace(old_text, new_protoc_text).to_string();
println!("Original lines: {}", old_text.lines().count());
println!("Updated lines: {}", new_content.lines().count());
Ok(new_content)
}
fn write_protobuf_rs(content: &str) -> Result<(), Box<dyn Error>> {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
let path = Path::new(&manifest_dir).join("src/protobuf.rs");
println!("Writing to {}", path.display());
fs::write(path, content)?;
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
let new_protoc_archive = fetch_protoc_release_info()?;
let content = read_protobuf_rs()?;
let updated_content = update_protoc_text(&content, &new_protoc_archive)?;
write_protobuf_rs(&updated_content)?;
println!("Successfully updated protoc_archive function in protobuf.rs");
Ok(())
}

View file

@ -1,140 +0,0 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::error::Error;
use std::fs;
use std::path::Path;
use regex::Regex;
use reqwest::blocking::Client;
use serde_json::Value;
fn fetch_uv_release_info() -> Result<String, Box<dyn Error>> {
let client = Client::new();
println!("Fetching latest uv release info from GitHub...");
// Fetch latest release info
let response = client
.get("https://api.github.com/repos/astral-sh/uv/releases/latest")
.header("User-Agent", "Anki-Build-Script")
.send()?;
let release_info: Value = response.json()?;
let assets = release_info["assets"]
.as_array()
.expect("assets should be an array");
// Map platform names to their corresponding asset patterns
let platform_patterns = [
("LinuxX64", "x86_64-unknown-linux-gnu"),
("LinuxArm", "aarch64-unknown-linux-gnu"),
("MacX64", "x86_64-apple-darwin"),
("MacArm", "aarch64-apple-darwin"),
("WindowsX64", "x86_64-pc-windows-msvc"),
("WindowsArm", "aarch64-pc-windows-msvc"),
];
let mut match_blocks = Vec::new();
for (platform, pattern) in platform_patterns {
// Find the asset matching the platform pattern (the binary)
let asset = assets.iter().find(|asset| {
let name = asset["name"].as_str().unwrap_or("");
name.contains(pattern) && (name.ends_with(".tar.gz") || name.ends_with(".zip"))
});
if asset.is_none() {
eprintln!("No asset found for platform {platform} pattern {pattern}");
continue;
}
let asset = asset.unwrap();
let download_url = asset["browser_download_url"].as_str().unwrap();
let asset_name = asset["name"].as_str().unwrap();
// Find the corresponding .sha256 or .sha256sum asset
let sha_asset = assets.iter().find(|a| {
let name = a["name"].as_str().unwrap_or("");
name == format!("{asset_name}.sha256") || name == format!("{asset_name}.sha256sum")
});
if sha_asset.is_none() {
eprintln!("No sha256 asset found for {asset_name}");
continue;
}
let sha_asset = sha_asset.unwrap();
let sha_url = sha_asset["browser_download_url"].as_str().unwrap();
println!("Fetching SHA256 for {platform}...");
let sha_text = client
.get(sha_url)
.header("User-Agent", "Anki-Build-Script")
.send()?
.text()?;
// The sha file is usually of the form: "<sha256> <filename>"
let sha256 = sha_text.split_whitespace().next().unwrap_or("");
match_blocks.push(format!(
" Platform::{platform} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}"
));
}
Ok(format!(
"pub fn uv_archive(platform: Platform) -> OnlineArchive {{\n match platform {{\n{}\n }}",
match_blocks.join(",\n")
))
}
fn read_python_rs() -> Result<String, Box<dyn Error>> {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
let path = Path::new(&manifest_dir).join("src/python.rs");
println!("Reading {}", path.display());
let content = fs::read_to_string(path)?;
Ok(content)
}
fn update_uv_text(old_text: &str, new_uv_text: &str) -> Result<String, Box<dyn Error>> {
let re = Regex::new(r"(?ms)^pub fn uv_archive\(platform: Platform\) -> OnlineArchive \{.*?\n\s*\}\s*\n\s*\}\s*\n\s*\}").unwrap();
if !re.is_match(old_text) {
return Err("Could not find uv_archive function block to replace".into());
}
let new_content = re.replace(old_text, new_uv_text).to_string();
println!("Original lines: {}", old_text.lines().count());
println!("Updated lines: {}", new_content.lines().count());
Ok(new_content)
}
fn write_python_rs(content: &str) -> Result<(), Box<dyn Error>> {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
let path = Path::new(&manifest_dir).join("src/python.rs");
println!("Writing to {}", path.display());
fs::write(path, content)?;
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
let new_uv_archive = fetch_uv_release_info()?;
let content = read_python_rs()?;
let updated_content = update_uv_text(&content, &new_uv_archive)?;
write_python_rs(&updated_content)?;
println!("Successfully updated uv_archive function in python.rs");
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_update_uv_text_with_actual_file() {
let content = fs::read_to_string("src/python.rs").unwrap();
let original_lines = content.lines().count();
const EXPECTED_LINES_REMOVED: usize = 38;
let updated = update_uv_text(&content, "").unwrap();
let updated_lines = updated.lines().count();
assert_eq!(
updated_lines,
original_lines - EXPECTED_LINES_REMOVED,
"Expected line count to decrease by exactly {EXPECTED_LINES_REMOVED} lines (original: {original_lines}, updated: {updated_lines})"
);
}
}

View file

@ -300,7 +300,7 @@ impl BuildStatement<'_> {
writeln!(buf, "build {outputs_str}: {action_name} {inputs_str}").unwrap();
for (key, value) in self.variables.iter().sorted() {
writeln!(buf, " {key} = {value}").unwrap();
writeln!(buf, " {key} = {}", value).unwrap();
}
writeln!(buf).unwrap();
@ -476,7 +476,7 @@ impl FilesHandle for BuildStatement<'_> {
let outputs = outputs.into_iter().map(|v| {
let v = v.as_ref();
let v = if !v.starts_with("$builddir/") && !v.starts_with("$builddir\\") {
format!("$builddir/{v}")
format!("$builddir/{}", v)
} else {
v.to_owned()
};

View file

@ -162,7 +162,7 @@ impl BuildAction for CargoTest {
"cargo-nextest",
CargoInstall {
binary_name: "cargo-nextest",
args: "cargo-nextest --version 0.9.99 --locked --no-default-features --features default-no-update",
args: "cargo-nextest --version 0.9.57 --locked",
},
)?;
setup_flags(build)

View file

@ -19,28 +19,24 @@ use crate::input::BuildInput;
pub fn node_archive(platform: Platform) -> OnlineArchive {
match platform {
Platform::LinuxX64 => OnlineArchive {
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz",
sha256: "325c0f1261e0c61bcae369a1274028e9cfb7ab7949c05512c5b1e630f7e80e12",
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-x64.tar.xz",
sha256: "822780369d0ea309e7d218e41debbd1a03f8cdf354ebf8a4420e89f39cc2e612",
},
Platform::LinuxArm => OnlineArchive {
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-arm64.tar.xz",
sha256: "140aee84be6774f5fb3f404be72adbe8420b523f824de82daeb5ab218dab7b18",
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-arm64.tar.xz",
sha256: "f6df68c6793244071f69023a9b43a0cf0b13d65cbe86d55925c28e4134d9aafb",
},
Platform::MacX64 => OnlineArchive {
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-darwin-x64.tar.xz",
sha256: "f79de1f64df4ac68493a344bb5ab7d289d0275271e87b543d1278392c9de778a",
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-x64.tar.xz",
sha256: "d4b4ab81ebf1f7aab09714f834992f27270ad0079600da00c8110f8950ca6c5a",
},
Platform::MacArm => OnlineArchive {
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-darwin-arm64.tar.xz",
sha256: "cc9cc294eaf782dd93c8c51f460da610cc35753c6a9947411731524d16e97914",
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-arm64.tar.xz",
sha256: "f18a7438723d48417f5e9be211a2f3c0520ffbf8e02703469e5153137ca0f328",
},
Platform::WindowsX64 => OnlineArchive {
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-win-x64.zip",
sha256: "721ab118a3aac8584348b132767eadf51379e0616f0db802cc1e66d7f0d98f85",
},
Platform::WindowsArm => OnlineArchive {
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-win-arm64.zip",
sha256: "78355dc9ca117bb71d3f081e4b1b281855e2b134f3939bb0ca314f7567b0e621",
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-win-x64.zip",
sha256: "893115cd92ad27bf178802f15247115e93c0ef0c753b93dca96439240d64feb5",
},
}
}
@ -98,7 +94,7 @@ impl BuildAction for YarnInstall<'_> {
}
}
fn with_cmd_ext(bin: &str) -> Cow<'_, str> {
fn with_cmd_ext(bin: &str) -> Cow<str> {
if cfg!(windows) {
format!("{bin}.cmd").into()
} else {

View file

@ -21,26 +21,26 @@ pub fn protoc_archive(platform: Platform) -> OnlineArchive {
match platform {
Platform::LinuxX64 => {
OnlineArchive {
url: "https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-linux-x86_64.zip",
sha256: "96553041f1a91ea0efee963cb16f462f5985b4d65365f3907414c360044d8065",
url: "https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-linux-x86_64.zip",
sha256: "f90d0dd59065fef94374745627336d622702b67f0319f96cee894d41a974d47a",
}
},
}
Platform::LinuxArm => {
OnlineArchive {
url: "https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-linux-aarch_64.zip",
sha256: "6c554de11cea04c56ebf8e45b54434019b1cd85223d4bbd25c282425e306ecc2",
url: "https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-linux-aarch_64.zip",
sha256: "f3d8eb5839d6186392d8c7b54fbeabbb6fcdd90618a500b77cb2e24faa245cad",
}
},
}
Platform::MacX64 | Platform::MacArm => {
OnlineArchive {
url: "https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-osx-universal_binary.zip",
sha256: "99ea004549c139f46da5638187a85bbe422d78939be0fa01af1aa8ab672e395f",
url: "https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-osx-universal_binary.zip",
sha256: "e3324d3bc2e9bc967a0bec2472e0ec73b26f952c7c87f2403197414f780c3c6c",
}
},
Platform::WindowsX64 | Platform::WindowsArm => {
}
Platform::WindowsX64 => {
OnlineArchive {
url: "https://github.com/protocolbuffers/protobuf/releases/download/v31.1/protoc-31.1-win64.zip",
sha256: "70381b116ab0d71cb6a5177d9b17c7c13415866603a0fd40d513dafe32d56c35",
url: "https://github.com/protocolbuffers/protobuf/releases/download/v21.8/protoc-21.8-win64.zip",
sha256: "3657053024faa439ff5f8c1dd2ee06bac0f9b9a3d660e99944f015a7451e87ec",
}
}
}
@ -67,7 +67,7 @@ fn clang_format_archive(platform: Platform) -> OnlineArchive {
sha256: "238be68d9478163a945754f06a213483473044f5a004c4125d3d9d8d3556466e",
}
}
Platform::WindowsX64 | Platform::WindowsArm=> {
Platform::WindowsX64 => {
OnlineArchive {
url: "https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_windows_x86_64.zip",
sha256: "7d9f6915e3f0fb72407830f0fc37141308d2e6915daba72987a52f309fbeaccc",

View file

@ -9,7 +9,6 @@ use maplit::hashmap;
use crate::action::BuildAction;
use crate::archives::download_and_extract;
use crate::archives::with_exe;
use crate::archives::OnlineArchive;
use crate::archives::Platform;
use crate::hash::simple_hash;
@ -17,113 +16,82 @@ use crate::input::BuildInput;
use crate::inputs;
use crate::Build;
// To update, run 'cargo run --bin update_uv'.
// You'll need to do this when bumping Python versions, as uv bakes in
// the latest known version.
// When updating Python version, make sure to update version tag in BuildWheel
// too.
pub fn uv_archive(platform: Platform) -> OnlineArchive {
/// When updating this, pyoxidizer.bzl needs updating too, but it uses different
/// files.
pub fn python_archive(platform: Platform) -> OnlineArchive {
match platform {
Platform::LinuxX64 => {
OnlineArchive {
url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-x86_64-unknown-linux-gnu.tar.gz",
sha256: "909278eb197c5ed0e9b5f16317d1255270d1f9ea4196e7179ce934d48c4c2545",
url: "https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18+20240107-x86_64_v2-unknown-linux-gnu-install_only.tar.gz",
sha256: "9426bca501ae0a257392b10719e2e20ff5fa5e22a3ce4599d6ad0b3139f86417",
}
},
}
Platform::LinuxArm => {
OnlineArchive {
url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-aarch64-unknown-linux-gnu.tar.gz",
sha256: "0b2ad9fe4295881615295add8cc5daa02549d29cc9a61f0578e397efcf12f08f",
url: "https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18+20240107-aarch64-unknown-linux-gnu-install_only.tar.gz",
sha256: "7d19e1ecd6e582423f7c74a0c67491eaa982ce9d5c5f35f0e4289f83127abcb8",
}
},
}
Platform::MacX64 => {
OnlineArchive {
url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-x86_64-apple-darwin.tar.gz",
sha256: "d785753ac092e25316180626aa691c5dfe1fb075290457ba4fdb72c7c5661321",
url: "https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18+20240107-x86_64-apple-darwin-install_only.tar.gz",
sha256: "5a0bf895a5cb08d6d008140abb41bb2c8cd638a665273f7d8eb258bc89de439b",
}
},
}
Platform::MacArm => {
OnlineArchive {
url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-aarch64-apple-darwin.tar.gz",
sha256: "721f532b73171586574298d4311a91d5ea2c802ef4db3ebafc434239330090c6",
url: "https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18+20240107-aarch64-apple-darwin-install_only.tar.gz",
sha256: "bf0cd90204a2cc6da48cae1e4b32f48c9f7031fbe1238c5972104ccb0155d368",
}
},
}
Platform::WindowsX64 => {
OnlineArchive {
url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-x86_64-pc-windows-msvc.zip",
sha256: "e199b10bef1a7cc540014483e7f60f825a174988f41020e9d2a6b01bd60f0669",
}
},
Platform::WindowsArm => {
OnlineArchive {
url: "https://github.com/astral-sh/uv/releases/download/0.7.13/uv-aarch64-pc-windows-msvc.zip",
sha256: "bb40708ad549ad6a12209cb139dd751bf0ede41deb679ce7513ce197bd9ef234",
url: "https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18+20240107-x86_64-pc-windows-msvc-shared-install_only.tar.gz",
sha256: "8f0544cd593984f7ecb90c685931249c579302124b9821064873f3a14ed07005",
}
}
}
}
pub fn setup_uv(build: &mut Build, platform: Platform) -> Result<()> {
let uv_binary = match env::var("UV_BINARY") {
/// Returns the Python binary, which can be used to create venvs.
/// Downloads if missing.
pub fn setup_python(build: &mut Build) -> Result<()> {
// if changing this, make sure you remove out/pyenv
let python_binary = match env::var("PYTHON_BINARY") {
Ok(path) => {
assert!(
Utf8Path::new(&path).is_absolute(),
"UV_BINARY must be absolute"
"PYTHON_BINARY must be absolute"
);
path.into()
}
Err(_) => {
download_and_extract(
build,
"uv",
uv_archive(platform),
"python",
python_archive(build.host_platform),
hashmap! { "bin" => [
with_exe("uv")
] },
if cfg!(windows) { "python.exe" } else { "bin/python3"}
] },
)?;
inputs![":extract:uv:bin"]
inputs![":extract:python:bin"]
}
};
build.add_dependency("uv_binary", uv_binary);
// Our macOS packaging needs access to the x86 binary on ARM.
if cfg!(target_arch = "aarch64") {
download_and_extract(
build,
"uv_mac_x86",
uv_archive(Platform::MacX64),
hashmap! { "bin" => [
with_exe("uv")
] },
)?;
}
// Our Linux packaging needs access to the ARM binary on x86
if cfg!(target_arch = "x86_64") {
download_and_extract(
build,
"uv_lin_arm",
uv_archive(Platform::LinuxArm),
hashmap! { "bin" => [
with_exe("uv")
] },
)?;
}
build.add_dependency("python_binary", python_binary);
Ok(())
}
pub struct PythonEnvironment {
pub deps: BuildInput,
// todo: rename
pub venv_folder: &'static str,
pub extra_args: &'static str,
pub folder: &'static str,
pub base_requirements_txt: BuildInput,
pub requirements_txt: BuildInput,
pub extra_binary_exports: &'static [&'static str],
}
impl BuildAction for PythonEnvironment {
fn command(&self) -> &str {
if env::var("OFFLINE_BUILD").is_err() {
"$runner pyenv $uv_binary $builddir/$pyenv_folder -- $extra_args"
"$runner pyenv $python_binary $builddir/$pyenv_folder $system_pkgs $base_requirements $requirements"
} else {
"echo 'OFFLINE_BUILD is set. Using the existing PythonEnvironment.'"
}
@ -131,7 +99,7 @@ impl BuildAction for PythonEnvironment {
fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
let bin_path = |binary: &str| -> Vec<String> {
let folder = self.venv_folder;
let folder = self.folder;
let path = if cfg!(windows) {
format!("{folder}/scripts/{binary}.exe")
} else {
@ -140,24 +108,17 @@ impl BuildAction for PythonEnvironment {
vec![path]
};
build.add_inputs("", &self.deps);
build.add_variable("pyenv_folder", self.venv_folder);
if env::var("OFFLINE_BUILD").is_err() {
build.add_inputs("uv_binary", inputs![":uv_binary"]);
// Add --python flag to extra_args if PYTHON_BINARY is set
let mut args = self.extra_args.to_string();
if let Ok(python_binary) = env::var("PYTHON_BINARY") {
args = format!("--python {python_binary} {args}");
}
build.add_variable("extra_args", args);
build.add_inputs("python_binary", inputs![":python_binary"]);
build.add_variable("pyenv_folder", self.folder);
build.add_inputs("base_requirements", &self.base_requirements_txt);
build.add_inputs("requirements", &self.requirements_txt);
build.add_outputs_ext("pip", bin_path("pip"), true);
}
build.add_outputs_ext("bin", bin_path("python"), true);
for binary in self.extra_binary_exports {
build.add_outputs_ext(*binary, bin_path(binary), true);
}
build.add_output_stamp(format!("{}/.stamp", self.venv_folder));
}
fn check_output_timestamps(&self) -> bool {
@ -193,19 +154,31 @@ impl BuildAction for PythonTypecheck {
struct PythonFormat<'a> {
pub inputs: &'a BuildInput,
pub check_only: bool,
pub isort_ini: &'a BuildInput,
}
impl BuildAction for PythonFormat<'_> {
fn command(&self) -> &str {
"$ruff format $mode $in && $ruff check --select I --fix $in"
"$black -t py39 -q $check --color $in && $
$isort --color --settings-path $isort_ini $check $in"
}
fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
build.add_inputs("in", self.inputs);
build.add_inputs("ruff", inputs![":pyenv:ruff"]);
build.add_inputs("black", inputs![":pyenv:black"]);
build.add_inputs("isort", inputs![":pyenv:isort"]);
let hash = simple_hash(self.inputs);
build.add_variable("mode", if self.check_only { "--check" } else { "" });
build.add_env_var("BLACK_CACHE_DIR", "out/python/black.cache.{hash}");
build.add_inputs("isort_ini", self.isort_ini);
build.add_variable(
"check",
if self.check_only {
"--diff --check"
} else {
""
},
);
build.add_output_stamp(format!(
"tests/python_format.{}.{hash}",
@ -215,11 +188,13 @@ impl BuildAction for PythonFormat<'_> {
}
pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Result<()> {
let isort_ini = &inputs![".isort.cfg"];
build.add_action(
format!("check:format:python:{group}"),
PythonFormat {
inputs: &inputs,
check_only: true,
isort_ini,
},
)?;
@ -228,39 +203,34 @@ pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Resu
PythonFormat {
inputs: &inputs,
check_only: false,
isort_ini,
},
)?;
Ok(())
}
pub struct RuffCheck {
pub struct PythonLint {
pub folders: &'static [&'static str],
pub pylint_ini: BuildInput,
pub deps: BuildInput,
pub check_only: bool,
}
impl BuildAction for RuffCheck {
impl BuildAction for PythonLint {
fn command(&self) -> &str {
"$ruff check $folders $mode"
"$pylint --rcfile $pylint_ini -sn -j $cpus $folders"
}
fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
build.add_inputs("", &self.deps);
build.add_inputs("", inputs![".ruff.toml"]);
build.add_inputs("ruff", inputs![":pyenv:ruff"]);
build.add_inputs("pylint", inputs![":pyenv:pylint"]);
build.add_inputs("pylint_ini", &self.pylint_ini);
build.add_variable("folders", self.folders.join(" "));
build.add_variable(
"mode",
if self.check_only {
""
} else {
"--fix --unsafe-fixes"
},
);
// On a 16 core system, values above 10 do not improve wall clock time,
// but waste extra cores that could be working on other tests.
build.add_variable("cpus", num_cpus::get().min(10).to_string());
let hash = simple_hash(&self.deps);
let kind = if self.check_only { "check" } else { "fix" };
build.add_output_stamp(format!("tests/python_ruff.{kind}.{hash}"));
build.add_output_stamp(format!("tests/python_lint.{hash}"));
}
}

View file

@ -30,12 +30,12 @@ impl Build {
)
.unwrap();
for (key, value) in &self.variables {
writeln!(&mut buf, "{key} = {value}").unwrap();
writeln!(&mut buf, "{} = {}", key, value).unwrap();
}
buf.push('\n');
for (key, value) in &self.pools {
writeln!(&mut buf, "pool {key}\n depth = {value}").unwrap();
writeln!(&mut buf, "pool {}\n depth = {}", key, value).unwrap();
}
buf.push('\n');

View file

@ -15,6 +15,7 @@ camino.workspace = true
clap.workspace = true
flate2.workspace = true
junction.workspace = true
reqwest = { workspace = true, features = ["rustls-tls", "rustls-tls-native-roots"] }
sha2.workspace = true
tar.workspace = true
termcolor.workspace = true
@ -23,9 +24,3 @@ which.workspace = true
xz2.workspace = true
zip.workspace = true
zstd.workspace = true
[target.'cfg(windows)'.dependencies]
reqwest = { workspace = true, features = ["native-tls"] }
[target.'cfg(not(windows))'.dependencies]
reqwest = { workspace = true, features = ["rustls-tls", "rustls-tls-native-roots"] }

View file

@ -65,7 +65,7 @@ fn sha2_data(data: &[u8]) -> String {
let mut digest = sha2::Sha256::new();
digest.update(data);
let result = digest.finalize();
format!("{result:x}")
format!("{:x}", result)
}
enum CompressionKind {

View file

@ -67,10 +67,7 @@ pub fn run_build(args: BuildArgs) {
"MYPY_CACHE_DIR",
build_root.join("tests").join("mypy").into_string(),
)
.env(
"PYTHONPYCACHEPREFIX",
std::path::absolute(build_root.join("pycache")).unwrap(),
)
.env("PYTHONPYCACHEPREFIX", build_root.join("pycache"))
// commands will not show colors by default, as we do not provide a tty
.env("FORCE_COLOR", "1")
.env("MYPY_FORCE_COLOR", "1")
@ -138,7 +135,7 @@ fn setup_build_root() -> Utf8PathBuf {
true
};
if create {
println!("Switching build root to {new_target}");
println!("Switching build root to {}", new_target);
std::os::unix::fs::symlink(new_target, build_root).unwrap();
}
}

View file

@ -0,0 +1,62 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::env;
use std::fs;
use std::process::Command;
use camino::Utf8PathBuf;
use clap::Args;
use crate::run::run_command;
#[derive(Args, Debug)]
pub struct BuildArtifactsArgs {
bundle_root: Utf8PathBuf,
pyoxidizer_bin: String,
}
pub fn build_artifacts(args: BuildArtifactsArgs) {
// build.rs doesn't declare inputs from venv, so we need to force a rebuild to
// ensure changes to our libs/the venv get included
let artifacts = args.bundle_root.join("artifacts");
if artifacts.exists() {
fs::remove_dir_all(&artifacts).unwrap();
}
let bundle_root = args.bundle_root.canonicalize_utf8().unwrap();
let build_folder = bundle_root.join("build");
if build_folder.exists() {
fs::remove_dir_all(&build_folder).unwrap();
}
run_command(
Command::new(&args.pyoxidizer_bin)
.args([
"--system-rust",
"run-build-script",
"qt/bundle/build.rs",
"--var",
"venv",
"out/bundle/pyenv",
"--var",
"build",
build_folder.as_str(),
])
.env("CARGO_MANIFEST_DIR", "qt/bundle")
.env("CARGO_TARGET_DIR", "out/bundle/rust")
.env("PROFILE", "release")
.env("OUT_DIR", &artifacts)
.env("TARGET", env!("TARGET"))
.env("SDKROOT", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
.env("MACOSX_DEPLOYMENT_TARGET", macos_deployment_target())
.env("CARGO_BUILD_TARGET", env!("TARGET")),
);
}
pub fn macos_deployment_target() -> &'static str {
if env!("TARGET") == "x86_64-apple-darwin" {
"10.13.4"
} else {
"11"
}
}

View file

@ -0,0 +1,53 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::process::Command;
use anki_process::CommandExt;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use super::artifacts::macos_deployment_target;
use crate::run::run_command;
pub fn build_bundle_binary() {
let mut features = String::from("build-mode-prebuilt-artifacts");
if cfg!(target_os = "linux") || cfg!(target_os = "macos") {
features.push_str(",global-allocator-jemalloc,allocator-jemalloc");
}
let mut command = Command::new("cargo");
command
.args([
"build",
"--manifest-path=qt/bundle/Cargo.toml",
"--target-dir=out/bundle/rust",
"--release",
"--no-default-features",
])
.arg(format!("--features={features}"))
.env(
"DEFAULT_PYTHON_CONFIG_RS",
// included in main.rs, so relative to qt/bundle/src
"../../../out/bundle/artifacts/",
)
.env(
"PYO3_CONFIG_FILE",
Utf8Path::new("out/bundle/artifacts/pyo3-build-config-file.txt")
.canonicalize_utf8()
.unwrap(),
)
.env("MACOSX_DEPLOYMENT_TARGET", macos_deployment_target())
.env("SDKROOT", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk")
.env("CARGO_BUILD_TARGET", env!("TARGET"));
if env!("TARGET") == "x86_64-apple-darwin" {
let xcode_path = Command::run_with_output(["xcode-select", "-p"]).unwrap();
let ld_classic = Utf8PathBuf::from(xcode_path.stdout.trim())
.join("Toolchains/XcodeDefault.xctoolchain/usr/bin/ld-classic");
if ld_classic.exists() {
// work around XCode 15's default linker not supporting macOS 10.15-12.
command.env("RUSTFLAGS", format!("-Clink-arg=-fuse-ld={ld_classic}"));
}
}
run_command(&mut command);
}

View file

@ -0,0 +1,156 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::env;
use std::fs;
use std::process::Command;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use clap::Args;
use clap::ValueEnum;
use crate::paths::absolute_msys_path;
use crate::paths::unix_path;
use crate::run::run_command;
#[derive(Clone, Copy, ValueEnum, Debug)]
enum DistKind {
Standard,
Alternate,
}
#[derive(Args, Debug)]
pub struct BuildDistFolderArgs {
kind: DistKind,
folder_root: Utf8PathBuf,
}
pub fn build_dist_folder(args: BuildDistFolderArgs) {
let BuildDistFolderArgs { kind, folder_root } = args;
fs::create_dir_all(&folder_root).unwrap();
// Start with Qt, as it's the largest, and we use --delete to ensure there are
// no stale files in lib/. Skipped on macOS as Qt is handled later.
if !cfg!(target_os = "macos") {
copy_qt_from_venv(kind, &folder_root);
}
clean_top_level_files(&folder_root);
copy_binary_and_pylibs(&folder_root);
if cfg!(target_os = "linux") {
copy_linux_extras(kind, &folder_root);
} else if cfg!(windows) {
copy_windows_extras(&folder_root);
}
fs::write(folder_root.with_extension("stamp"), b"").unwrap();
}
fn copy_qt_from_venv(kind: DistKind, folder_root: &Utf8Path) {
let python39 = if cfg!(windows) { "" } else { "python3.9/" };
let qt_root = match kind {
DistKind::Standard => {
folder_root.join(format!("../pyenv/lib/{python39}site-packages/PyQt6"))
}
DistKind::Alternate => {
folder_root.join(format!("../pyenv-qt5/lib/{python39}site-packages/PyQt5"))
}
};
let src_path = absolute_msys_path(&qt_root);
let lib_path = folder_root.join("lib");
fs::create_dir_all(&lib_path).unwrap();
let dst_path = with_slash(absolute_msys_path(&lib_path));
run_command(Command::new("rsync").args([
"-a",
"--delete",
"--exclude-from",
"qt/bundle/qt.exclude",
&src_path,
&dst_path,
]));
}
fn copy_linux_extras(kind: DistKind, folder_root: &Utf8Path) {
// add README, installer, etc
run_command(Command::new("rsync").args(["-a", "qt/bundle/lin/", &with_slash(folder_root)]));
// add extra IME plugins from download
let lib_path = folder_root.join("lib");
let src_path = folder_root
.join("../../extracted/linux_qt_plugins")
.join(match kind {
DistKind::Standard => "qt6",
DistKind::Alternate => "qt5",
});
let dst_path = lib_path.join(match kind {
DistKind::Standard => "PyQt6/Qt6/plugins",
DistKind::Alternate => "PyQt5/Qt5/plugins",
});
run_command(Command::new("rsync").args(["-a", &with_slash(src_path), &with_slash(dst_path)]));
}
fn copy_windows_extras(folder_root: &Utf8Path) {
run_command(Command::new("rsync").args([
"-a",
"out/extracted/win_amd64_audio/",
&with_slash(folder_root),
]));
}
fn clean_top_level_files(folder_root: &Utf8Path) {
let mut to_remove = vec![];
for entry in fs::read_dir(folder_root).unwrap() {
let entry = entry.unwrap();
if entry.file_name() == "lib" {
continue;
} else {
to_remove.push(entry.path());
}
}
for path in to_remove {
if path.is_dir() {
fs::remove_dir_all(path).unwrap()
} else {
fs::remove_file(path).unwrap()
}
}
}
fn with_slash<P>(path: P) -> String
where
P: AsRef<str>,
{
format!("{}/", path.as_ref())
}
fn copy_binary_and_pylibs(folder_root: &Utf8Path) {
let binary = folder_root
.join("../rust")
.join(env!("TARGET"))
.join("release")
.join(if cfg!(windows) { "anki.exe" } else { "anki" });
let extra_files = folder_root
.join("../build")
.join(env!("TARGET"))
.join("release/resources/extra_files");
run_command(Command::new("rsync").args([
"-a",
"--exclude",
"PyQt6",
// misleading, as it misses the GPL PyQt, and our Rust/JS
// dependencies
"--exclude",
"COPYING.txt",
&unix_path(&binary),
&with_slash(unix_path(&extra_files)),
&with_slash(unix_path(folder_root)),
]));
let google_py = if cfg!(windows) {
folder_root.join("../pyenv/lib/site-packages/google")
} else {
folder_root.join("../pyenv/lib/python3.9/site-packages/google")
};
run_command(Command::new("rsync").args([
"-a",
&unix_path(&google_py),
&with_slash(unix_path(&folder_root.join("lib"))),
]));
}

View file

@ -1,6 +1,6 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
int main(void) {
return 0;
}
pub mod artifacts;
pub mod binary;
pub mod folder;

View file

@ -7,6 +7,7 @@
mod archive;
mod build;
mod bundle;
mod paths;
mod pyenv;
mod rsync;
@ -18,6 +19,11 @@ use archive::archive_command;
use archive::ArchiveArgs;
use build::run_build;
use build::BuildArgs;
use bundle::artifacts::build_artifacts;
use bundle::artifacts::BuildArtifactsArgs;
use bundle::binary::build_bundle_binary;
use bundle::folder::build_dist_folder;
use bundle::folder::BuildDistFolderArgs;
use clap::Parser;
use clap::Subcommand;
use pyenv::setup_pyenv;
@ -42,6 +48,9 @@ enum Command {
Rsync(RsyncArgs),
Run(RunArgs),
Build(BuildArgs),
BuildArtifacts(BuildArtifactsArgs),
BuildBundleBinary,
BuildDistFolder(BuildDistFolderArgs),
#[clap(subcommand)]
Archive(ArchiveArgs),
}
@ -53,6 +62,9 @@ fn main() -> Result<()> {
Command::Rsync(args) => rsync_files(args),
Command::Yarn(args) => setup_yarn(args),
Command::Build(args) => run_build(args),
Command::BuildArtifacts(args) => build_artifacts(args),
Command::BuildBundleBinary => build_bundle_binary(),
Command::BuildDistFolder(args) => build_dist_folder(args),
Command::Archive(args) => archive_command(args)?,
};
Ok(())

View file

@ -16,3 +16,8 @@ pub fn absolute_msys_path(path: &Utf8Path) -> String {
// and \ -> /
format!("/{drive}/{}", path[7..].replace('\\', "/"))
}
/// Converts backslashes to forward slashes
pub fn unix_path(path: &Utf8Path) -> String {
path.as_str().replace('\\', "/")
}

View file

@ -1,7 +1,6 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::fs;
use std::process::Command;
use camino::Utf8Path;
@ -11,10 +10,12 @@ use crate::run::run_command;
#[derive(Args)]
pub struct PyenvArgs {
uv_bin: String,
python_bin: String,
pyenv_folder: String,
#[arg(trailing_var_arg = true)]
extra_args: Vec<String>,
initial_reqs: String,
reqs: Vec<String>,
#[arg(long, allow_hyphen_values(true))]
venv_args: Vec<String>,
}
/// Set up a venv if one doesn't already exist, and then sync packages with
@ -22,32 +23,35 @@ pub struct PyenvArgs {
pub fn setup_pyenv(args: PyenvArgs) {
let pyenv_folder = Utf8Path::new(&args.pyenv_folder);
// On first run, ninja creates an empty bin/ folder which breaks the initial
// install. But we don't want to indiscriminately remove the folder, or
// macOS Gatekeeper needs to rescan the files each time.
if pyenv_folder.exists() {
let cache_tag = pyenv_folder.join("CACHEDIR.TAG");
if !cache_tag.exists() {
fs::remove_dir_all(pyenv_folder).expect("Failed to remove existing pyenv folder");
let pyenv_bin_folder = pyenv_folder.join(if cfg!(windows) { "scripts" } else { "bin" });
let pyenv_python = pyenv_bin_folder.join("python");
let pip_sync = pyenv_bin_folder.join("pip-sync");
if !pyenv_python.exists() {
run_command(
Command::new(&args.python_bin)
.args(["-m", "venv"])
.args(args.venv_args)
.arg(pyenv_folder),
);
if cfg!(windows) {
// the first install on Windows throws an error the first time pip is upgraded,
// so we install it twice and swallow the first error
let _output = Command::new(&pyenv_python)
.args(["-m", "pip", "install", "-r", &args.initial_reqs])
.output()
.unwrap();
}
run_command(Command::new(pyenv_python).args([
"-m",
"pip",
"install",
"-r",
&args.initial_reqs,
]));
}
let mut command = Command::new(args.uv_bin);
// remove UV_* environment variables to avoid interference
for (key, _) in std::env::vars() {
if key.starts_with("UV_") || key == "VIRTUAL_ENV" {
command.env_remove(key);
}
}
run_command(
command
.env("UV_PROJECT_ENVIRONMENT", args.pyenv_folder.clone())
.args(["sync", "--locked", "--no-config"])
.args(args.extra_args),
);
// Write empty stamp file
fs::write(pyenv_folder.join(".stamp"), "").expect("Failed to write stamp file");
run_command(Command::new(pip_sync).args(&args.reqs));
}

View file

@ -1,6 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::io::ErrorKind;
use std::process::Command;
use anki_io::create_dir_all;
@ -43,7 +44,7 @@ fn split_env(s: &str) -> Result<(String, String), std::io::Error> {
if let Some((k, v)) = s.split_once('=') {
Ok((k.into(), v.into()))
} else {
Err(std::io::Error::other("invalid env var"))
Err(std::io::Error::new(ErrorKind::Other, "invalid env var"))
}
}
@ -83,7 +84,7 @@ fn split_args(args: Vec<String>) -> Vec<Vec<String>> {
pub fn run_command(command: &mut Command) {
if let Err(err) = command.ensure_success() {
println!("{err}");
println!("{}", err);
std::process::exit(1);
}
}

View file

@ -28,11 +28,7 @@ pub fn setup_yarn(args: YarnArgs) {
.arg("--ignore-scripts"),
);
} else {
run_command(
Command::new(&args.yarn_bin)
.arg("install")
.arg("--immutable"),
);
run_command(Command::new(&args.yarn_bin).arg("install"));
}
std::fs::write(args.stamp, b"").unwrap();

File diff suppressed because it is too large Load diff

View file

@ -85,7 +85,7 @@ When formatting issues are reported, they can be fixed with
./ninja format
```
## Fixing ruff/eslint/copyright header issues
## Fixing eslint/copyright header issues
```
./ninja fix
@ -190,10 +190,13 @@ in the collection2.log file will also be printed on stdout.
If ANKI_PROFILE_CODE is set, Python profiling data will be written on exit.
# Installer/launcher
# Binary Bundles
- The anki-release package is created/published with the scripts in qt/release.
- The installer/launcher is created with the build scripts in qt/launcher/{platform}.
Anki's official binary packages are created with `./ninja bundle`. The bundling
process was created specifically for the official builds, and is provided as-is;
we are unfortunately not able to provide assistance with any issues you may run
into when using it. You'll need to run
`git submodule update --checkout qt/bundle/PyOxidizer` first.
## Mixing development and study

View file

@ -1,78 +1,35 @@
# This is a user-contributed Dockerfile. No official support is available.
# This Dockerfile uses three stages.
# 1. Compile anki (and dependencies) and build python wheels.
# 2. Create a virtual environment containing anki and its dependencies.
# 3. Create a final image that only includes anki's virtual environment and required
# system packages.
ARG PYTHON_VERSION="3.9"
ARG DEBIAN_FRONTEND="noninteractive"
FROM ubuntu:24.04 AS build
# Build anki.
FROM python:$PYTHON_VERSION AS build
RUN curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64 \
> /usr/local/bin/bazel \
&& chmod +x /usr/local/bin/bazel \
# Bazel expects /usr/bin/python
&& ln -s /usr/local/bin/python /usr/bin/python
WORKDIR /opt/anki
ENV PYTHON_VERSION="3.13"
# System deps
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
build-essential \
pkg-config \
libssl-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libffi-dev \
zlib1g-dev \
liblzma-dev \
ca-certificates \
ninja-build \
rsync \
libglib2.0-0 \
libgl1 \
libx11-6 \
libxext6 \
libxrender1 \
libxkbcommon0 \
libxkbcommon-x11-0 \
libxcb1 \
libxcb-render0 \
libxcb-shm0 \
libxcb-icccm4 \
libxcb-image0 \
libxcb-keysyms1 \
libxcb-randr0 \
libxcb-shape0 \
libxcb-xfixes0 \
libxcb-xinerama0 \
libxcb-xinput0 \
libsm6 \
libice6 \
&& rm -rf /var/lib/apt/lists/*
# install rust with rustup
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
# Install uv and Python 3.13 with uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
&& ln -s /root/.local/bin/uv /usr/local/bin/uv
ENV PATH="/root/.local/bin:${PATH}"
RUN uv python install ${PYTHON_VERSION} --default
COPY . .
# Build python wheels.
RUN ./tools/build
# Install pre-compiled Anki.
FROM python:3.13-slim AS installer
FROM python:${PYTHON_VERSION}-slim as installer
WORKDIR /opt/anki/
COPY --from=build /opt/anki/out/wheels/ wheels/
COPY --from=build /opt/anki/wheels/ wheels/
# Use virtual environment.
RUN python -m venv venv \
&& ./venv/bin/python -m pip install --no-cache-dir setuptools wheel \
&& ./venv/bin/python -m pip install --no-cache-dir /opt/anki/wheels/*.whl
# We use another build stage here so we don't include the wheels in the final image.
FROM python:3.13-slim AS final
FROM python:${PYTHON_VERSION}-slim as final
COPY --from=installer /opt/anki/venv /opt/anki/venv
ENV PATH=/opt/anki/venv/bin:$PATH
# Install run-time dependencies.
@ -102,9 +59,9 @@ RUN apt-get update \
libxrender1 \
libxtst6 \
&& rm -rf /var/lib/apt/lists/*
# Add non-root user.
RUN useradd --create-home anki
USER anki
WORKDIR /work
ENTRYPOINT ["/opt/anki/venv/bin/anki"]
LABEL maintainer="Jakub Kaczmarzyk <jakub.kaczmarzyk@gmail.com>"

View file

@ -51,8 +51,13 @@ Anki requires a recent glibc.
If you are using a distro that uses musl, Anki will not work.
You can use your system's Qt libraries if they are Qt 6.2 or later, if
you wish. After installing the system libraries (eg:
If your glibc version is 2.35+ on AMD64 or 2.39+ on ARM64, you can skip the rest of this section.
If your system has an older glibc, you won't be able to use the PyQt wheels that are
available in pip/PyPy, and will need to use your system-installed PyQt instead.
Your distro will also need to have Python 3.9 or later.
After installing the system libraries (eg:
'sudo apt install python3-pyqt6.qt{quick,webengine} python3-venv pyqt6-dev-tools'),
find the place they are installed (eg '/usr/lib/python3/dist-packages'). On modern Ubuntu, you'll
also need 'sudo apt remove python3-protobuf'. Then before running any commands like './run', tell Anki where
@ -63,6 +68,12 @@ export PYTHONPATH=/usr/lib/python3/dist-packages
export PYTHON_BINARY=/usr/bin/python3
```
There are a few things to be aware of:
- You should use ./run and not tools/run-qt5\*, even if your system libraries are Qt5.
- If your system libraries are Qt5, when creating an aqt wheel, the wheel will not work
on Qt6 environments.
## Packaging considerations
Python, node and protoc are downloaded as part of the build. You can optionally define

View file

@ -98,6 +98,12 @@ should preferably be assigned a number between 1 and 15. If a message contains
Protobuf has an official Python implementation with an extensive [reference](https://developers.google.com/protocol-buffers/docs/reference/python-generated).
- Every message used in aqt or pylib must be added to the respective `.pylintrc`
to avoid failing type checks. The unqualified protobuf message's name must be
used, not an alias from `collection.py` for example. This should be taken into
account when choosing a message name in order to prevent skipping typechecking
a Python class of the same name.
### Typescript
Anki uses [protobuf-es](https://github.com/bufbuild/protobuf-es), which offers

View file

@ -9,12 +9,7 @@ You must be running 64 bit Windows 10, version 1703 or newer.
**Rustup**:
As mentioned in development.md, rustup must be installed. If you're on
ARM Windows and install the ARM64 version of rust-up, from this project folder,
run
```
rustup target add x86_64-pc-windows-msvc
```
ARM Windows, you must set the default target to x86_64-pc-windows-msvc.
**Visual Studio**:

@ -1 +1 @@
Subproject commit 480ef0da728c7ea3485c58529ae7ee02be3e5dba
Subproject commit 78412ce163d4dc50dd82f5b27cde3119086a2eb7

View file

@ -60,6 +60,7 @@ card-templates-this-will-create-card-proceed =
}
card-templates-type-boxes-warning = Only one typing box per card template is supported.
card-templates-restore-to-default = Restore to Default
card-templates-restore-to-default-confirmation = This will reset all fields and templates in this note type to their default values, removing any extra fields/templates and their content, and any custom styling. Do you wish to proceed?
card-templates-restore-to-default-confirmation = This will reset all fields and templates in this note type to their default
values, removing any extra fields/templates and their content, and any custom styling. Do you wish to proceed?
card-templates-restored-to-default = Note type has been restored to its original state.

View file

@ -5,11 +5,6 @@ database-check-card-properties =
[one] Fixed { $count } invalid card property.
*[other] Fixed { $count } invalid card properties.
}
database-check-card-last-review-time-empty =
{ $count ->
[one] Added last review time to { $count } card.
*[other] Added last review time to { $count } cards.
}
database-check-missing-templates =
{ $count ->
[one] Deleted { $count } card with missing template.

View file

@ -307,17 +307,16 @@ deck-config-new-interval-tooltip = The multiplier applied to a review interval w
deck-config-minimum-interval-tooltip = The minimum interval given to a review card after answering `Again`.
deck-config-custom-scheduling = Custom scheduling
deck-config-custom-scheduling-tooltip = Affects the entire collection. Use at your own risk!
## Easy Days section.
# Easy Days section
deck-config-easy-days-title = Easy Days
deck-config-easy-days-monday = Mon
deck-config-easy-days-tuesday = Tue
deck-config-easy-days-wednesday = Wed
deck-config-easy-days-thursday = Thu
deck-config-easy-days-friday = Fri
deck-config-easy-days-saturday = Sat
deck-config-easy-days-sunday = Sun
deck-config-easy-days-monday = Monday
deck-config-easy-days-tuesday = Tuesday
deck-config-easy-days-wednesday = Wednesday
deck-config-easy-days-thursday = Thursday
deck-config-easy-days-friday = Friday
deck-config-easy-days-saturday = Saturday
deck-config-easy-days-sunday = Sunday
deck-config-easy-days-normal = Normal
deck-config-easy-days-reduced = Reduced
deck-config-easy-days-minimum = Minimum
@ -384,6 +383,8 @@ deck-config-which-deck = Which deck would you like to display options for?
deck-config-updating-cards = Updating cards: { $current_cards_count }/{ $total_cards_count }...
deck-config-invalid-parameters = The provided FSRS parameters are invalid. Leave them blank to use the default parameters.
deck-config-not-enough-history = Insufficient review history to perform this operation.
deck-config-unable-to-determine-desired-retention =
Unable to determine a minimum recommended retention.
deck-config-must-have-400-reviews =
{ $count ->
[one] Only { $count } review was found.
@ -392,9 +393,9 @@ deck-config-must-have-400-reviews =
# Numbers that control how aggressively the FSRS algorithm schedules cards
deck-config-weights = FSRS parameters
deck-config-compute-optimal-weights = Optimize FSRS parameters
deck-config-compute-minimum-recommended-retention = Minimum recommended retention
deck-config-optimize-button = Optimize Current Preset
# Indicates that a given function or label, provided via the "text" variable, operates slowly.
deck-config-slow-suffix = { $text } (slow)
deck-config-health-check = Check health when optimizing (slow)
deck-config-compute-button = Compute
deck-config-ignore-before = Ignore cards reviewed before
deck-config-time-to-optimize = It's been a while - using the Optimize All Presets button is recommended.
@ -404,6 +405,7 @@ deck-config-historical-retention = Historical retention
deck-config-smaller-is-better = Smaller numbers indicate a better fit to your review history.
deck-config-steps-too-large-for-fsrs = When FSRS is enabled, steps of 1 day or more are not recommended.
deck-config-get-params = Get Params
deck-config-predicted-minimum-recommended-retention = Minimum recommended retention: { $num }
deck-config-complete = { $num }% complete.
deck-config-iterations = Iteration: { $count }...
deck-config-reschedule-cards-on-change = Reschedule cards on change
@ -421,8 +423,6 @@ deck-config-desired-retention-tooltip =
less frequently, and you will forget more of them. Be conservative when adjusting this - higher
values will greatly increase your workload, and lower values can be demoralizing when you forget
a lot of material.
deck-config-desired-retention-tooltip2 =
The workload values provided by the info box are a rough approximation. For a greater level of accuracy, use the simulator.
deck-config-historical-retention-tooltip =
When some of your review history is missing, FSRS needs to fill in the gaps. By default, it will
assume that when you did those old reviews, you remembered 90% of the material. If your old retention
@ -464,7 +464,12 @@ deck-config-compute-optimal-weights-tooltip2 =
By default, parameters will be calculated from the review history of all decks using the current preset. You can
optionally adjust the search before calculating the parameters, if you'd like to alter which cards are used for
optimizing the parameters.
deck-config-compute-optimal-retention-tooltip4 =
This tool will attempt to find the desired retention value
that will lead to the most material learnt, in the least amount of time. The calculated number can serve as a reference
when deciding what to set your desired retention to. You may wish to choose a higher desired retention if youre
willing to invest more study time to achieve it. Setting your desired retention lower than the minimum
is not recommended, as it will lead to a higher workload, because of the high forgetting rate.
deck-config-please-save-your-changes-first = Please save your changes first.
deck-config-workload-factor-change = Approximate workload: {$factor}x
(compared to {$previousDR}% desired retention)
@ -478,11 +483,17 @@ deck-config-percent-of-reviews =
*[other] { $pct }% of { $reviews } reviews
}
deck-config-percent-input = { $pct }%
# This message appears during FSRS parameter optimization.
deck-config-checking-for-improvement = Checking for improvement...
deck-config-optimizing-preset = Optimizing preset { $current_count }/{ $total_count }...
deck-config-fsrs-must-be-enabled = FSRS must be enabled first.
deck-config-fsrs-params-optimal = The FSRS parameters currently appear to be optimal.
deck-config-fsrs-bad-fit-warning = Your memory is difficult for FSRS to predict. Recommendations:
- Suspend or reformulate leeches.
- Use the answer buttons consistently. Keep in mind that "Hard" is a passing grade, not a failing grade.
- Understand before you memorize.
If you follow these suggestions, performance will usually improve over the next few months.
deck-config-fsrs-good-fit = FSRS is well adjusted to your memory.
deck-config-fsrs-params-no-reviews = No reviews found. Make sure this preset is assigned to all decks (including subdecks) that you want to optimize, and try again.
@ -496,10 +507,7 @@ deck-config-desired-retention-below-optimal = Your desired retention is below op
# Description of the y axis in the FSRS simulation
# diagram (Deck options -> FSRS) showing the total number of
# cards that can be recalled or retrieved on a specific date.
deck-config-fsrs-simulator-experimental = FSRS Simulator (Experimental)
deck-config-fsrs-simulate-desired-retention-experimental = FSRS Desired Retention Simulator (Experimental)
deck-config-fsrs-simulate-save-preset = After optimizing, please save your deck preset before running the simulator.
deck-config-fsrs-desired-retention-help-me-decide-experimental = Help Me Decide (Experimental)
deck-config-fsrs-simulator-experimental = FSRS simulator (experimental)
deck-config-additional-new-cards-to-simulate = Additional new cards to simulate
deck-config-simulate = Simulate
deck-config-clear-last-simulate = Clear Last Simulation
@ -508,45 +516,13 @@ deck-config-advanced-settings = Advanced Settings
deck-config-smooth-graph = Smooth graph
deck-config-suspend-leeches = Suspend leeches
deck-config-save-options-to-preset = Save Changes to Preset
deck-config-save-options-to-preset-confirm = Overwrite the options in your current preset with the options that are currently set in the simulator?
# Radio button in the FSRS simulation diagram (Deck options -> FSRS) selecting
# to show the total number of cards that can be recalled or retrieved on a
# specific date.
deck-config-fsrs-simulator-radio-memorized = Memorized
deck-config-fsrs-simulator-radio-ratio = Time / Memorized Ratio
# $time here is pre-formatted e.g. "10 Seconds"
deck-config-fsrs-simulator-ratio-tooltip = { $time } per memorized card
## Messages related to the FSRS schedulers health check. The health check determines whether the correlation between FSRS predictions and your memory is good or bad. It can be optionally triggered as part of the "Optimize" function.
# Checkbox
deck-config-health-check = Check health when optimizing
# Message box showing the result of the health check
deck-config-fsrs-bad-fit-warning = Health Check:
Your memory is difficult for FSRS to predict. Recommendations:
- Suspend or reformulate any cards you constantly forget.
- Use the answer buttons consistently. Keep in mind that "Hard" is a passing grade, not a failing grade.
- Understand before you memorize.
If you follow these suggestions, performance will usually improve over the next few months.
# Message box showing the result of the health check
deck-config-fsrs-good-fit = Health Check:
FSRS can adapt to your memory well.
## NO NEED TO TRANSLATE. This text is no longer used by Anki, and will be removed in the future.
deck-config-unable-to-determine-desired-retention =
Unable to determine a minimum recommended retention.
deck-config-predicted-minimum-recommended-retention = Minimum recommended retention: { $num }
deck-config-compute-minimum-recommended-retention = Minimum recommended retention
deck-config-compute-optimal-retention-tooltip4 =
This tool will attempt to find the desired retention value
that will lead to the most material learnt, in the least amount of time. The calculated number can serve as a reference
when deciding what to set your desired retention to. You may wish to choose a higher desired retention if youre
willing to invest more study time to achieve it. Setting your desired retention lower than the minimum
is not recommended, as it will lead to a higher workload, because of the high forgetting rate.
deck-config-plotted-on-x-axis = (Plotted on the X-axis)
deck-config-a-100-day-interval =
{ $days ->
[one] A 100 day interval will become { $days } day.
@ -584,8 +560,6 @@ deck-config-compute-optimal-retention-tooltip =
if it significantly differs from 0.9, it's a sign that the time you've allocated each day is either too low
or too high for the amount of cards you're trying to learn. This number can be useful as a reference, but it
is not recommended to copy it into the desired retention field.
deck-config-health-check-tooltip1 = This will show a warning if FSRS struggles to adapt to your memory.
deck-config-health-check-tooltip2 = Health check is performed only when using Optimize Current Preset.
deck-config-compute-optimal-retention = Compute minimum recommended retention
deck-config-predicted-optimal-retention = Minimum recommended retention: { $num }

View file

@ -48,7 +48,6 @@ importing-merge-notetypes-help =
Warning: This will require a one-way sync, and may mark existing notes as modified.
importing-mnemosyne-20-deck-db = Mnemosyne 2.0 Deck (*.db)
importing-multicharacter-separators-are-not-supported-please = Multi-character separators are not supported. Please enter one character only.
importing-new-deck-will-be-created = A new deck will be created: { $name }
importing-notes-added-from-file = Notes added from file: { $val }
importing-notes-found-in-file = Notes found in file: { $val }
importing-notes-skipped-as-theyre-already-in = Notes skipped, as up-to-date copies are already in your collection: { $val }
@ -66,6 +65,7 @@ importing-with-deck-configs-help =
If enabled, any deck options that the deck sharer included will also be imported.
Otherwise, all decks will be assigned the default preset.
importing-packaged-anki-deckcollection-apkg-colpkg-zip = Packaged Anki Deck/Collection (*.apkg *.colpkg *.zip)
importing-pauker-18-lesson-paugz = Pauker 1.8 Lesson (*.pau.gz)
# the '|' character
importing-pipe = Pipe
# Warning displayed when the csv import preview table is clipped (some columns were hidden)
@ -78,6 +78,7 @@ importing-rows-had-num1d-fields-expected-num2d = '{ $row }' had { $found } field
importing-selected-file-was-not-in-utf8 = Selected file was not in UTF-8 format. Please see the importing section of the manual.
importing-semicolon = Semicolon
importing-skipped = Skipped
importing-supermemo-xml-export-xml = Supermemo XML export (*.xml)
importing-tab = Tab
importing-tag-modified-notes = Tag modified notes:
importing-text-separated-by-tabs-or-semicolons = Text separated by tabs or semicolons (*)
@ -251,5 +252,3 @@ importing-importing-collection = Importing collection...
importing-unable-to-import-filename = Unable to import { $filename }: file type not supported
importing-notes-that-could-not-be-imported = Notes that could not be imported as note type has changed: { $val }
importing-added = Added
importing-pauker-18-lesson-paugz = Pauker 1.8 Lesson (*.pau.gz)
importing-supermemo-xml-export-xml = Supermemo XML export (*.xml)

View file

@ -34,7 +34,7 @@ preferences-when-adding-default-to-current-deck = When adding, default to curren
preferences-you-can-restore-backups-via-fileswitch = You can restore backups via File > Switch Profile.
preferences-legacy-timezone-handling = Legacy timezone handling (buggy, but required for AnkiDroid <= 2.14)
preferences-default-search-text = Default search text
preferences-default-search-text-example = e.g. "deck:current"
preferences-default-search-text-example = eg. 'deck:current '
preferences-theme = Theme
preferences-theme-follow-system = Follow System
preferences-theme-light = Light

View file

@ -80,7 +80,7 @@ statistics-reviews =
# This fragment of the tooltip in the FSRS simulation
# diagram (Deck options -> FSRS) shows the total number of
# cards that can be recalled or retrieved on a specific date.
statistics-memorized = {$memorized} cards memorized
statistics-memorized = {$memorized} memorized
statistics-today-title = Today
statistics-today-again-count = Again count:
statistics-today-type-counts = Learn: { $learnCount }, Review: { $reviewCount }, Relearn: { $relearnCount }, Filtered: { $filteredCount }
@ -99,9 +99,9 @@ statistics-counts-relearning-cards = Relearning
statistics-counts-title = Card Counts
statistics-counts-separate-suspended-buried-cards = Separate suspended/buried cards
## Retention represents your actual retention from past reviews, in
## comparison to the "desired retention" setting of FSRS, which forecasts
## future retention. Retention is the percentage of all reviewed cards
## True Retention represents your actual retention rate from past reviews, in
## comparison to the "desired retention" parameter of FSRS, which forecasts
## future retention. True Retention is the percentage of all reviewed cards
## that were marked as "Hard," "Good," or "Easy" within a specific time period.
##
## Most of these strings are used as column / row headings in a table.
@ -112,9 +112,9 @@ statistics-counts-separate-suspended-buried-cards = Separate suspended/buried ca
## N.B. Stats cards may be very small on mobile devices and when the Stats
## window is certain sizes.
statistics-true-retention-title = Retention
statistics-true-retention-title = True Retention
statistics-true-retention-subtitle = Pass rate of cards with an interval ≥ 1 day.
statistics-true-retention-tooltip = If you are using FSRS, your retention is expected to be close to your desired retention. Please keep in mind that data for a single day is noisy, so it's better to look at monthly data.
statistics-true-retention-tooltip = If you are using FSRS, your true retention is expected to be close to your desired retention. Please keep in mind that data for a single day is noisy, so it's better to look at monthly data.
statistics-true-retention-range = Range
statistics-true-retention-pass = Pass
statistics-true-retention-fail = Fail

View file

@ -46,20 +46,6 @@ studying-type-answer-unknown-field = Type answer: unknown field { $val }
studying-unbury = Unbury
studying-what-would-you-like-to-unbury = What would you like to unbury?
studying-you-havent-recorded-your-voice-yet = You haven't recorded your voice yet.
studying-card-studied-in-minute =
{ $cards ->
[one] { $cards } card
*[other] { $cards } cards
} studied in
{ $minutes ->
[one] { $minutes } minute.
*[other] { $minutes } minutes.
}
studying-question-time-elapsed = Question time elapsed
studying-answer-time-elapsed = Answer time elapsed
## OBSOLETE; you do not need to translate this
studying-card-studied-in =
{ $count ->
[one] { $count } card studied in
@ -70,3 +56,5 @@ studying-minute =
[one] { $count } minute.
*[other] { $count } minutes.
}
studying-question-time-elapsed = Question time elapsed
studying-answer-time-elapsed = Answer time elapsed

36
ftl/extract-strings.py Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python3
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""
Tool to extract core strings and keys from .ftl files.
"""
import glob
import json
import os
from fluent.syntax import parse
from fluent.syntax.ast import Junk, Message
from fluent.syntax.serializer import serialize_element
root = ".."
ftl_files = glob.glob(os.path.join(root, "ftl", "core", "*.ftl"), recursive=True)
keys_by_value: dict[str, list[str]] = {}
for path in ftl_files:
obj = parse(open(path, encoding="utf8").read(), with_spans=False)
for ent in obj.body:
if isinstance(ent, Junk):
raise Exception(f"file had junk! {path} {ent}")
if isinstance(ent, Message):
key = ent.id.name
val = "".join(serialize_element(elem) for elem in ent.value.elements)
if val in keys_by_value:
print("duplicate found:", keys_by_value[val], key)
keys_by_value.setdefault(val, []).append(key)
json.dump(
keys_by_value, open(os.path.join(root, "keys_by_value.json"), "w", encoding="utf8")
)
print("keys:", len(keys_by_value))

99
ftl/format.py Normal file
View file

@ -0,0 +1,99 @@
#!/usr/bin/env python3
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""
Parse and re-serialize ftl files to get them in a consistent form.
"""
import difflib
import glob
import os
from typing import List
from compare_locales import parser
from compare_locales.checks.fluent import ReferenceMessageVisitor
from compare_locales.paths import File
from fluent.syntax import parse, serialize
from fluent.syntax.ast import Junk
def check_missing_terms(path: str) -> bool:
"True if file is ok."
file = File(path, os.path.basename(path))
content = open(path, "rb").read()
p = parser.getParser(file.file)
p.readContents(content)
refList = p.parse()
p.readContents(content)
for e in p.parse():
ref_data = ReferenceMessageVisitor()
ref_data.visit(e.entry)
for attr_or_val, refs in ref_data.entry_refs.items():
for ref, ref_type in refs.items():
if ref not in refList:
print(f"In {path}:{e}, missing '{ref}'")
return False
return True
def check_file(path: str, fix: bool) -> bool:
"True if file is ok."
orig_text = open(path, encoding="utf8").read()
obj = parse(orig_text, with_spans=False)
# make sure there's no junk
for ent in obj.body:
if isinstance(ent, Junk):
raise Exception(f"file had junk! {path} {ent}")
# serialize
new_text = serialize(obj)
# make sure serializing did not introduce new junk
obj = parse(new_text, with_spans=False)
for ent in obj.body:
if isinstance(ent, Junk):
raise Exception(f"file introduced junk! {path} {ent}")
if new_text == orig_text:
return check_missing_terms(path)
if fix:
print(f"Fixing {path}")
open(path, "w", newline="\n", encoding="utf8").write(new_text)
return True
else:
print(f"Bad formatting in {path}")
print(
"\n".join(
difflib.unified_diff(
orig_text.splitlines(),
new_text.splitlines(),
fromfile="bad",
tofile="good",
lineterm="",
)
)
)
return False
def check_files(files: List[str], fix: bool) -> bool:
"True if files ok."
found_bad = False
for path in files:
ok = check_file(path, fix)
if not ok:
found_bad = True
return not found_bad
if __name__ == "__main__":
template_root = os.environ["BUILD_WORKSPACE_DIRECTORY"]
template_files = glob.glob(
os.path.join(template_root, "ftl", "*", "*.ftl"), recursive=True
)
check_files(template_files, fix=True)

14
ftl/format_check.py Normal file
View file

@ -0,0 +1,14 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import glob
import os
import sys
import format
template_root = os.path.dirname(sys.argv[1])
template_files = glob.glob(os.path.join(template_root, "*", "*.ftl"), recursive=True)
if not format.check_files(template_files, fix=False):
sys.exit(1)

@ -1 +1 @@
Subproject commit fd5f984785ad07a0d3dbd893ee3d7e3671eaebd6
Subproject commit fbe9d1c731f7ad09953e63fdb0c455a6d3a3b6be

View file

@ -1,5 +1,4 @@
qt-accel-about = &About
qt-accel-about-mac = About Anki...
qt-accel-cards = &Cards
qt-accel-check-database = &Check Database
qt-accel-check-media = Check &Media
@ -46,4 +45,3 @@ qt-accel-zoom-editor-in = Zoom Editor &In
qt-accel-zoom-editor-out = Zoom Editor &Out
qt-accel-create-backup = Create &Backup
qt-accel-load-backup = &Revert to Backup
qt-accel-upgrade-downgrade = Upgrade/Downgrade

View file

@ -73,7 +73,6 @@ qt-misc-second =
qt-misc-layout-auto-enabled = Responsive layout enabled
qt-misc-layout-vertical-enabled = Vertical layout enabled
qt-misc-layout-horizontal-enabled = Horizontal layout enabled
qt-misc-open-anki-launcher = Change to a different Anki version?
## deprecated- these strings will be removed in the future, and do not need
## to be translated

View file

@ -435,7 +435,7 @@ impl TextWriter {
item = item.trim_start_matches(' ');
}
write!(self.buffer, "{item}")
write!(self.buffer, "{}", item)
}
fn write_char_into_indent(&mut self, ch: char) {

View file

@ -67,7 +67,7 @@ fn additional_template_folder(dst_folder: &Utf8Path) -> Option<Utf8PathBuf> {
fn all_langs(lang_folder: &Utf8Path) -> Result<Vec<Utf8PathBuf>> {
std::fs::read_dir(lang_folder)
.with_context(|| format!("reading {lang_folder:?}"))?
.with_context(|| format!("reading {:?}", lang_folder))?
.filter_map(Result::ok)
.map(|e| Ok(e.path().utf8()?))
.collect()

2
ninja
View file

@ -8,7 +8,7 @@ else
out="$BUILD_ROOT"
fi
export CARGO_TARGET_DIR=$out/rust
export RECONFIGURE_KEY="${MAC_X86};${LIN_ARM64};${SOURCEMAP};${HMR}"
export RECONFIGURE_KEY="${MAC_X86};${SOURCEMAP};${HMR}"
if [ "$SKIP_RUNNER_BUILD" = "1" ]; then
echo "Runner not rebuilt."

View file

@ -19,8 +19,8 @@
"@poppanator/sveltekit-svg": "^5.0.0",
"@sqltools/formatter": "^1.2.2",
"@sveltejs/adapter-static": "^3.0.0",
"@sveltejs/kit": "^2.22.2",
"@sveltejs/vite-plugin-svelte": "5.1",
"@sveltejs/kit": "^2.20.7",
"@sveltejs/vite-plugin-svelte": "4.0.0",
"@types/bootstrap": "^5.0.12",
"@types/codemirror": "^5.60.0",
"@types/d3": "^7.0.0",
@ -30,7 +30,7 @@
"@types/jqueryui": "^1.12.13",
"@types/lodash-es": "^4.17.4",
"@types/marked": "^5.0.0",
"@types/node": "^22",
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^5.60.1",
"@typescript-eslint/parser": "^5.60.1",
"caniuse-lite": "^1.0.30001431",
@ -48,16 +48,16 @@
"prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.2",
"sass": "<1.77",
"svelte": "^5.34.9",
"svelte-check": "^4.2.2",
"svelte-preprocess": "^6.0.3",
"svelte": "^5.17.3",
"svelte-check": "^3.4.4",
"svelte-preprocess": "^5.0.4",
"svelte-preprocess-esbuild": "^3.0.1",
"svgo": "^3.2.0",
"tslib": "^2.0.3",
"tsx": "^4.8.1",
"tsx": "^3.12.0",
"typescript": "^5.0.4",
"vite": "6",
"vitest": "^3"
"vite": "5.4.19",
"vitest": "^2"
},
"dependencies": {
"@bufbuild/protobuf": "^1.2.1",
@ -81,9 +81,7 @@
},
"resolutions": {
"canvas": "npm:empty-npm-package@1.0.0",
"cookie": "0.7.0",
"devalue": "^5.3.2",
"vite": "6"
"cookie": "0.7.0"
},
"browserslist": [
"defaults",

View file

@ -51,7 +51,6 @@ message Card {
optional FsrsMemoryState memory_state = 20;
optional float desired_retention = 21;
optional float decay = 22;
optional int64 last_review_time_secs = 23;
string custom_data = 19;
}

View file

@ -56,7 +56,6 @@ message ConfigKey {
RENDER_LATEX = 25;
LOAD_BALANCER_ENABLED = 26;
FSRS_SHORT_TERM_WITH_STEPS_ENABLED = 27;
FSRS_LEGACY_EVALUATE = 28;
}
enum String {
SET_DUE_BROWSER = 0;

View file

@ -40,10 +40,12 @@ message DeckConfigId {
message GetRetentionWorkloadRequest {
repeated float w = 1;
string search = 2;
float before = 3;
float after = 4;
}
message GetRetentionWorkloadResponse {
map<uint32, float> costs = 1;
float factor = 1;
}
message GetIgnoredBeforeCountRequest {
@ -217,8 +219,6 @@ message DeckConfigsForUpdate {
bool review_today_active = 5;
// Whether new_today applies to today or a past day.
bool new_today_active = 6;
// Deck-specific desired retention override
optional float desired_retention = 7;
}
string name = 1;
int64 config_id = 2;
@ -236,7 +236,6 @@ message DeckConfigsForUpdate {
bool new_cards_ignore_review_limit = 7;
bool fsrs = 8;
bool fsrs_health_check = 11;
bool fsrs_legacy_evaluate = 12;
bool apply_all_parent_limits = 9;
uint32 days_since_last_fsrs_optimize = 10;
}

View file

@ -83,8 +83,6 @@ message Deck {
optional uint32 new_limit = 7;
DayLimit review_limit_today = 8;
DayLimit new_limit_today = 9;
// Deck-specific desired retention override
optional float desired_retention = 10;
reserved 12 to 15;
}

View file

@ -27,9 +27,6 @@ service FrontendService {
rpc deckOptionsRequireClose(generic.Empty) returns (generic.Empty);
// Warns python that the deck option web view is ready to receive requests.
rpc deckOptionsReady(generic.Empty) returns (generic.Empty);
// Save colour picker's custom colour palette
rpc SaveCustomColours(generic.Empty) returns (generic.Empty);
}
service BackendFrontendService {}

View file

@ -176,12 +176,9 @@ message CsvMetadata {
// to determine the number of columns.
repeated string column_labels = 5;
oneof deck {
// id of an existing deck
int64 deck_id = 6;
// One-based. 0 means n/a.
uint32 deck_column = 7;
// name of new deck to be created
string deck_name = 17;
}
oneof notetype {
// One notetype for all rows with given column mapping.

View file

@ -59,7 +59,7 @@ message AddNoteRequest {
}
message AddNoteResponse {
collection.OpChangesWithCount changes = 1;
collection.OpChanges changes = 1;
int64 note_id = 2;
}

View file

@ -55,11 +55,7 @@ service SchedulerService {
returns (ComputeOptimalRetentionResponse);
rpc SimulateFsrsReview(SimulateFsrsReviewRequest)
returns (SimulateFsrsReviewResponse);
rpc SimulateFsrsWorkload(SimulateFsrsReviewRequest)
returns (SimulateFsrsWorkloadResponse);
rpc EvaluateParams(EvaluateParamsRequest) returns (EvaluateParamsResponse);
rpc EvaluateParamsLegacy(EvaluateParamsLegacyRequest)
returns (EvaluateParamsResponse);
rpc ComputeMemoryState(cards.CardId) returns (ComputeMemoryStateResponse);
// The number of days the calculated interval was fuzzed by on the previous
// review (if any). Utilized by the FSRS add-on.
@ -406,9 +402,6 @@ message SimulateFsrsReviewRequest {
repeated float easy_days_percentages = 10;
deck_config.DeckConfig.Config.ReviewCardOrder review_order = 11;
optional uint32 suspend_after_lapse_count = 12;
float historical_retention = 13;
uint32 learning_step_count = 14;
uint32 relearning_step_count = 15;
}
message SimulateFsrsReviewResponse {
@ -418,12 +411,6 @@ message SimulateFsrsReviewResponse {
repeated float daily_time_cost = 4;
}
message SimulateFsrsWorkloadResponse {
map<uint32, float> cost = 1;
map<uint32, float> memorized = 2;
map<uint32, uint32> review_count = 3;
}
message ComputeOptimalRetentionResponse {
float optimal_retention = 1;
}
@ -455,12 +442,6 @@ message EvaluateParamsRequest {
uint32 num_of_relearning_steps = 3;
}
message EvaluateParamsLegacyRequest {
repeated float params = 1;
string search = 2;
int64 ignore_revlogs_before_ms = 3;
}
message EvaluateParamsResponse {
float log_loss = 1;
float rmse_bins = 2;
@ -469,7 +450,6 @@ message EvaluateParamsResponse {
message ComputeMemoryStateResponse {
optional cards.FsrsMemoryState state = 1;
float desired_retention = 2;
float decay = 3;
}
message FuzzDeltaRequest {

View file

@ -74,15 +74,10 @@ message SearchNode {
repeated SearchNode nodes = 1;
Joiner joiner = 2;
}
enum FieldSearchMode {
FIELD_SEARCH_MODE_NORMAL = 0;
FIELD_SEARCH_MODE_REGEX = 1;
FIELD_SEARCH_MODE_NOCOMBINING = 2;
}
message Field {
string field_name = 1;
string text = 2;
FieldSearchMode mode = 3;
bool is_re = 3;
}
oneof filter {

View file

@ -46,6 +46,7 @@ from .errors import (
# the following comment is required to suppress a warning that only shows up
# when there are other pylint failures
# pylint: disable=c-extension-no-member
if _rsbridge.buildhash() != anki.buildinfo.buildhash:
raise Exception(
f"""rsbridge and anki build hashes do not match:
@ -163,7 +164,7 @@ class RustBackend(RustBackendGenerated):
finally:
elapsed = time.time() - start
if current_thread() is main_thread() and elapsed > 0.2:
print(f"blocked main thread for {int(elapsed * 1000)}ms:")
print(f"blocked main thread for {int(elapsed*1000)}ms:")
print("".join(traceback.format_stack()))
err = backend_pb2.BackendError()
@ -246,7 +247,7 @@ def backend_exception_to_pylib(err: backend_pb2.BackendError) -> Exception:
return BackendError(err.message, help_page, context, backtrace)
elif val == kind.SEARCH_ERROR:
return SearchError(err.message, help_page, context, backtrace)
return SearchError(markdown(err.message), help_page, context, backtrace)
elif val == kind.UNDO_EMPTY:
return UndoEmpty(err.message, help_page, context, backtrace)

View file

@ -7,7 +7,7 @@ import pprint
import time
from typing import NewType
import anki
import anki # pylint: disable=unused-import
import anki.collection
import anki.decks
import anki.notes
@ -49,7 +49,6 @@ class Card(DeprecatedNamesMixin):
memory_state: FSRSMemoryState | None
desired_retention: float | None
decay: float | None
last_review_time: int | None
def __init__(
self,
@ -104,11 +103,6 @@ class Card(DeprecatedNamesMixin):
card.desired_retention if card.HasField("desired_retention") else None
)
self.decay = card.decay if card.HasField("decay") else None
self.last_review_time = (
card.last_review_time_secs
if card.HasField("last_review_time_secs")
else None
)
def _to_backend_card(self) -> cards_pb2.Card:
# mtime & usn are set by backend
@ -133,7 +127,6 @@ class Card(DeprecatedNamesMixin):
memory_state=self.memory_state,
desired_retention=self.desired_retention,
decay=self.decay,
last_review_time_secs=self.last_review_time,
)
@deprecated(info="please use col.update_card()")

View file

@ -122,7 +122,6 @@ class ComputedMemoryState:
desired_retention: float
stability: float | None = None
difficulty: float | None = None
decay: float | None = None
@dataclass
@ -158,7 +157,7 @@ class Collection(DeprecatedNamesMixin):
self.tags = TagManager(self)
self.conf = ConfigManager(self)
self._load_scheduler()
self._startReps = 0
self._startReps = 0 # pylint: disable=invalid-name
def name(self) -> Any:
return os.path.splitext(os.path.basename(self.path))[0]
@ -511,7 +510,9 @@ class Collection(DeprecatedNamesMixin):
# Utils
##########################################################################
def nextID(self, type: str, inc: bool = True) -> Any:
def nextID( # pylint: disable=invalid-name
self, type: str, inc: bool = True
) -> Any:
type = f"next{type.capitalize()}"
id = self.conf.get(type, 1)
if inc:
@ -528,7 +529,7 @@ class Collection(DeprecatedNamesMixin):
def new_note(self, notetype: NotetypeDict) -> Note:
return Note(self, notetype)
def add_note(self, note: Note, deck_id: DeckId) -> OpChangesWithCount:
def add_note(self, note: Note, deck_id: DeckId) -> OpChanges:
hooks.note_will_be_added(self, note, deck_id)
out = self._backend.add_note(note=note._to_backend_note(), deck_id=deck_id)
note.id = NoteId(out.note_id)
@ -847,6 +848,7 @@ class Collection(DeprecatedNamesMixin):
)
def _pb_search_separator(self, operator: SearchJoiner) -> SearchNode.Group.Joiner.V:
# pylint: disable=no-member
if operator == "AND":
return SearchNode.Group.Joiner.AND
else:
@ -864,9 +866,7 @@ class Collection(DeprecatedNamesMixin):
return column
return None
def browser_row_for_id(
self, id_: int
) -> tuple[
def browser_row_for_id(self, id_: int) -> tuple[
Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
BrowserRow.Color.V,
str,
@ -1189,13 +1189,9 @@ class Collection(DeprecatedNamesMixin):
desired_retention=resp.desired_retention,
stability=resp.state.stability,
difficulty=resp.state.difficulty,
decay=resp.decay,
)
else:
return ComputedMemoryState(
desired_retention=resp.desired_retention,
decay=resp.decay,
)
return ComputedMemoryState(desired_retention=resp.desired_retention)
def fuzz_delta(self, card_id: CardId, interval: int) -> int:
"The delta days of fuzz applied if reviewing the card in v3."
@ -1211,6 +1207,8 @@ class Collection(DeprecatedNamesMixin):
# the count on things like edits, which we probably could do by checking
# the previous state in moveToState.
# pylint: disable=invalid-name
def startTimebox(self) -> None:
self._startTime = time.time()
self._startReps = self.sched.reps

View file

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations
@ -350,7 +351,7 @@ class AnkiPackageExporter(AnkiExporter):
colfile = path.replace(".apkg", ".anki2")
AnkiExporter.exportInto(self, colfile)
# prevent older clients from accessing
# pylint: disable=unreachable
self._addDummyCollection(z)
z.write(colfile, "collection.anki21")

View file

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations

View file

@ -1,7 +1,8 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""Helpers for serializing third-party collections to a common JSON form."""
"""Helpers for serializing third-party collections to a common JSON form.
"""
from __future__ import annotations

View file

@ -175,8 +175,8 @@ class MnemoFact:
def fact_view(self) -> type[MnemoFactView]:
try:
fact_view = self.cards[0].fact_view_id
except IndexError:
return FrontOnly
except IndexError as err:
raise Exception(f"Fact {id} has no cards") from err
if fact_view.startswith("1.") or fact_view.startswith("1::"):
return FrontOnly
@ -187,7 +187,7 @@ class MnemoFact:
elif fact_view.startswith("5.1"):
return Cloze
raise Exception(f"Fact {self.id} has unknown fact view: {fact_view}")
raise Exception(f"Fact {id} has unknown fact view: {fact_view}")
def anki_fields(self, fact_view: type[MnemoFactView]) -> list[str]:
return [munge_field(self.fields.get(k, "")) for k in fact_view.field_keys]

View file

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
"""
Tools for extending Anki.

View file

@ -11,6 +11,8 @@ from anki.importing.apkg import AnkiPackageImporter
from anki.importing.base import Importer
from anki.importing.csvfile import TextImporter
from anki.importing.mnemo import MnemosyneImporter
from anki.importing.pauker import PaukerImporter
from anki.importing.supermemo_xml import SupermemoXmlImporter # type: ignore
from anki.lang import TR
@ -22,6 +24,8 @@ def importers(col: Collection) -> Sequence[tuple[str, type[Importer]]]:
AnkiPackageImporter,
),
(col.tr.importing_mnemosyne_20_deck_db(), MnemosyneImporter),
(col.tr.importing_supermemo_xml_export_xml(), SupermemoXmlImporter),
(col.tr.importing_pauker_18_lesson_paugz(), PaukerImporter),
]
anki.hooks.importing_importers(importers)
return importers

View file

@ -1,7 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations
import os

View file

@ -1,7 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations
import json

View file

@ -1,7 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations
from typing import Any

View file

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations
@ -143,6 +144,7 @@ class TextImporter(NoteImporter):
self.close()
zuper = super()
if hasattr(zuper, "__del__"):
# pylint: disable=no-member
zuper.__del__(self) # type: ignore
def noteFromFields(self, fields: list[str]) -> ForeignNote:

View file

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
import re
import time
@ -34,6 +35,7 @@ f._id=d._fact_id"""
):
if id != curid:
if note:
# pylint: disable=unsubscriptable-object
notes[note["_id"]] = note
note = {"_id": _id}
curid = id
@ -183,6 +185,7 @@ acq_reps+ret_reps, lapses, card_type_id from cards"""
state = dict(n=1)
def repl(match):
# pylint: disable=cell-var-from-loop
# replace [...] with cloze refs
res = "{{c%d::%s}}" % (state["n"], match.group(1))
state["n"] += 1

View file

@ -1,6 +1,7 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
from __future__ import annotations
@ -166,9 +167,9 @@ class NoteImporter(Importer):
firsts[fld0] = True
# already exists?
found = False
if csum in csums: # type: ignore[comparison-overlap]
if csum in csums:
# csum is not a guarantee; have to check
for id in csums[csum]: # type: ignore[index]
for id in csums[csum]:
flds = self.col.db.scalar("select flds from notes where id = ?", id)
sflds = split_fields(flds)
if fld0 == sflds[0]:

Some files were not shown because too many files have changed in this diff Show more