Merge branch 'main' into editor-3830

This commit is contained in:
Abdo 2025-06-29 21:59:30 +03:00
commit 939d833e12
187 changed files with 1620 additions and 811 deletions

2
.gitignore vendored
View file

@ -19,4 +19,4 @@ yarn-error.log
ts/.svelte-kit ts/.svelte-kit
.yarn .yarn
.claude/settings.local.json .claude/settings.local.json
CLAUDE.local.md .claude/user.md

View file

@ -1,4 +0,0 @@
[settings]
py_version=39
known_first_party=anki,aqt,tests
profile=black

View file

@ -1,48 +0,0 @@
[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,2 +1,91 @@
target-version = "py39" lint.select = [
extend-exclude = [] "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"]

View file

@ -1 +1 @@
25.06b6 25.06b7

View file

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

View file

@ -18,7 +18,7 @@
"out/qt", "out/qt",
"qt" "qt"
], ],
"python.formatting.provider": "black", "python.formatting.provider": "charliermarsh.ruff",
"python.linting.mypyEnabled": false, "python.linting.mypyEnabled": false,
"python.analysis.diagnosticSeverityOverrides": { "python.analysis.diagnosticSeverityOverrides": {
"reportMissingModuleSource": "none" "reportMissingModuleSource": "none"

View file

@ -80,3 +80,7 @@ when possible.
in rslib, use error/mod.rs's AnkiError/Result and snafu. In our other Rust modules, prefer anyhow + additional context where appropriate. Unwrapping 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. in build scripts/tests is fine.
## Individual preferences
See @.claude/user.md

9
Cargo.lock generated
View file

@ -3548,7 +3548,8 @@ dependencies = [
"embed-resource", "embed-resource",
"libc", "libc",
"libc-stdhandle", "libc-stdhandle",
"winapi", "widestring",
"windows 0.61.3",
] ]
[[package]] [[package]]
@ -7375,6 +7376,12 @@ dependencies = [
"winsafe", "winsafe",
] ]
[[package]]
name = "widestring"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd7cf3379ca1aac9eea11fba24fd7e315d621f8dfe35c8d7d2be8b793726e07d"
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"

View file

@ -138,8 +138,9 @@ unic-ucd-category = "0.9.0"
unicode-normalization = "0.1.24" unicode-normalization = "0.1.24"
walkdir = "2.5.0" walkdir = "2.5.0"
which = "8.0.0" which = "8.0.0"
winapi = { version = "0.3", features = ["wincon"] } widestring = "1.1.0"
windows = { version = "0.61.3", features = ["Media_SpeechSynthesis", "Media_Core", "Foundation_Collections", "Storage_Streams"] } 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_Foundation", "Win32_UI_Shell"] }
wiremock = "0.6.3" wiremock = "0.6.3"
xz2 = "0.1.7" xz2 = "0.1.7"
zip = { version = "4.1.0", default-features = false, features = ["deflate", "time"] } zip = { version = "4.1.0", default-features = false, features = ["deflate", "time"] }

View file

@ -7,17 +7,14 @@ use anyhow::Result;
use ninja_gen::action::BuildAction; use ninja_gen::action::BuildAction;
use ninja_gen::archives::Platform; use ninja_gen::archives::Platform;
use ninja_gen::build::FilesHandle; use ninja_gen::build::FilesHandle;
use ninja_gen::command::RunCommand;
use ninja_gen::copy::CopyFiles; use ninja_gen::copy::CopyFiles;
use ninja_gen::glob; use ninja_gen::glob;
use ninja_gen::hashmap;
use ninja_gen::input::BuildInput; use ninja_gen::input::BuildInput;
use ninja_gen::inputs; use ninja_gen::inputs;
use ninja_gen::python::python_format; use ninja_gen::python::python_format;
use ninja_gen::python::PythonEnvironment; use ninja_gen::python::PythonEnvironment;
use ninja_gen::python::PythonLint;
use ninja_gen::python::PythonTypecheck; use ninja_gen::python::PythonTypecheck;
use ninja_gen::rsync::RsyncFiles; use ninja_gen::python::RuffCheck;
use ninja_gen::Build; use ninja_gen::Build;
/// Normalize version string by removing leading zeros from numeric parts /// Normalize version string by removing leading zeros from numeric parts
@ -51,7 +48,7 @@ fn normalize_version(version: &str) -> String {
part.to_string() part.to_string()
} else { } else {
let normalized_prefix = numeric_prefix.parse::<u32>().unwrap_or(0).to_string(); let normalized_prefix = numeric_prefix.parse::<u32>().unwrap_or(0).to_string();
format!("{}{}", normalized_prefix, rest) format!("{normalized_prefix}{rest}")
} }
} }
}) })
@ -60,14 +57,7 @@ fn normalize_version(version: &str) -> String {
} }
pub fn setup_venv(build: &mut Build) -> Result<()> { pub fn setup_venv(build: &mut Build) -> Result<()> {
let extra_binary_exports = &[ let extra_binary_exports = &["mypy", "ruff", "pytest", "protoc-gen-mypy"];
"mypy",
"black",
"isort",
"pylint",
"pytest",
"protoc-gen-mypy",
];
build.add_action( build.add_action(
"pyenv", "pyenv",
PythonEnvironment { PythonEnvironment {
@ -200,60 +190,26 @@ pub fn check_python(build: &mut Build) -> Result<()> {
}, },
)?; )?;
add_pylint(build)?; let ruff_folders = &["qt/aqt", "ftl", "pylib/tools", "tools", "python"];
let ruff_deps = inputs![
Ok(()) glob!["{pylib,ftl,qt,python,tools}/**/*.py"],
} ":pylib:anki",
":qt:aqt"
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( build.add_action(
"check:pylint:copy_pylib", "check:ruff",
RsyncFiles { RuffCheck {
inputs: inputs![":pylib:anki"], folders: ruff_folders,
target_folder: "pylint/anki", deps: ruff_deps.clone(),
strip_prefix: "$builddir/pylib/anki", check_only: true,
// avoid copying our large rsbridge binary
extra_args: "--links",
}, },
)?; )?;
build.add_action( build.add_action(
"check:pylint:copy_pylib", "fix:ruff",
RsyncFiles { RuffCheck {
inputs: inputs![glob!["pylib/anki/**"]], folders: ruff_folders,
target_folder: "pylint/anki", deps: ruff_deps,
strip_prefix: "pylib/anki", check_only: false,
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")
],
}, },
)?; )?;

View file

@ -169,7 +169,7 @@ fn build_rsbridge(build: &mut Build) -> Result<()> {
pub fn check_rust(build: &mut Build) -> Result<()> { pub fn check_rust(build: &mut Build) -> Result<()> {
let inputs = inputs![ let inputs = inputs![
glob!("{rslib/**,pylib/rsbridge/**,ftl/**,build/**,tools/workspace-hack/**}"), glob!("{rslib/**,pylib/rsbridge/**,ftl/**,build/**,qt/launcher/**}"),
"Cargo.lock", "Cargo.lock",
"Cargo.toml", "Cargo.toml",
"rust-toolchain.toml", "rust-toolchain.toml",

View file

@ -72,12 +72,11 @@ fn fetch_protoc_release_info() -> Result<String, Box<dyn Error>> {
"MacArm" => continue, // Skip MacArm since it's handled with MacX64 "MacArm" => continue, // Skip MacArm since it's handled with MacX64
"WindowsX64" => "Platform::WindowsX64 | Platform::WindowsArm", "WindowsX64" => "Platform::WindowsX64 | Platform::WindowsArm",
"WindowsArm" => continue, // Skip WindowsArm since it's handled with WindowsX64 "WindowsArm" => continue, // Skip WindowsArm since it's handled with WindowsX64
_ => &format!("Platform::{}", platform), _ => &format!("Platform::{platform}"),
}; };
match_blocks.push(format!( match_blocks.push(format!(
" {} => {{\n OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }}\n }}", " {match_pattern} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}"
match_pattern, download_url, sha256
)); ));
} }

View file

@ -53,7 +53,7 @@ fn fetch_uv_release_info() -> Result<String, Box<dyn Error>> {
// Find the corresponding .sha256 or .sha256sum asset // Find the corresponding .sha256 or .sha256sum asset
let sha_asset = assets.iter().find(|a| { let sha_asset = assets.iter().find(|a| {
let name = a["name"].as_str().unwrap_or(""); let name = a["name"].as_str().unwrap_or("");
name == format!("{}.sha256", asset_name) || name == format!("{}.sha256sum", asset_name) name == format!("{asset_name}.sha256") || name == format!("{asset_name}.sha256sum")
}); });
if sha_asset.is_none() { if sha_asset.is_none() {
eprintln!("No sha256 asset found for {asset_name}"); eprintln!("No sha256 asset found for {asset_name}");
@ -71,8 +71,7 @@ fn fetch_uv_release_info() -> Result<String, Box<dyn Error>> {
let sha256 = sha_text.split_whitespace().next().unwrap_or(""); let sha256 = sha_text.split_whitespace().next().unwrap_or("");
match_blocks.push(format!( match_blocks.push(format!(
" Platform::{} => {{\n OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }}\n }}", " Platform::{platform} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}"
platform, download_url, sha256
)); ));
} }
@ -135,10 +134,7 @@ mod tests {
assert_eq!( assert_eq!(
updated_lines, updated_lines,
original_lines - EXPECTED_LINES_REMOVED, original_lines - EXPECTED_LINES_REMOVED,
"Expected line count to decrease by exactly {} lines (original: {}, updated: {})", "Expected line count to decrease by exactly {EXPECTED_LINES_REMOVED} lines (original: {original_lines}, updated: {updated_lines})"
EXPECTED_LINES_REMOVED,
original_lines,
updated_lines
); );
} }
} }

View file

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

View file

@ -148,7 +148,7 @@ impl BuildAction for PythonEnvironment {
// Add --python flag to extra_args if PYTHON_BINARY is set // Add --python flag to extra_args if PYTHON_BINARY is set
let mut args = self.extra_args.to_string(); let mut args = self.extra_args.to_string();
if let Ok(python_binary) = env::var("PYTHON_BINARY") { if let Ok(python_binary) = env::var("PYTHON_BINARY") {
args = format!("--python {} {}", python_binary, args); args = format!("--python {python_binary} {args}");
} }
build.add_variable("extra_args", args); build.add_variable("extra_args", args);
} }
@ -193,31 +193,19 @@ impl BuildAction for PythonTypecheck {
struct PythonFormat<'a> { struct PythonFormat<'a> {
pub inputs: &'a BuildInput, pub inputs: &'a BuildInput,
pub check_only: bool, pub check_only: bool,
pub isort_ini: &'a BuildInput,
} }
impl BuildAction for PythonFormat<'_> { impl BuildAction for PythonFormat<'_> {
fn command(&self) -> &str { fn command(&self) -> &str {
"$black -t py39 -q $check --color $in && $ "$ruff format $mode $in && $ruff check --select I --fix $in"
$isort --color --settings-path $isort_ini $check $in"
} }
fn files(&mut self, build: &mut impl crate::build::FilesHandle) { fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
build.add_inputs("in", self.inputs); build.add_inputs("in", self.inputs);
build.add_inputs("black", inputs![":pyenv:black"]); build.add_inputs("ruff", inputs![":pyenv:ruff"]);
build.add_inputs("isort", inputs![":pyenv:isort"]);
let hash = simple_hash(self.inputs); let hash = simple_hash(self.inputs);
build.add_env_var("BLACK_CACHE_DIR", "out/python/black.cache.{hash}"); build.add_variable("mode", if self.check_only { "--check" } else { "" });
build.add_inputs("isort_ini", self.isort_ini);
build.add_variable(
"check",
if self.check_only {
"--diff --check"
} else {
""
},
);
build.add_output_stamp(format!( build.add_output_stamp(format!(
"tests/python_format.{}.{hash}", "tests/python_format.{}.{hash}",
@ -227,13 +215,11 @@ impl BuildAction for PythonFormat<'_> {
} }
pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Result<()> { pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Result<()> {
let isort_ini = &inputs![".isort.cfg"];
build.add_action( build.add_action(
format!("check:format:python:{group}"), format!("check:format:python:{group}"),
PythonFormat { PythonFormat {
inputs: &inputs, inputs: &inputs,
check_only: true, check_only: true,
isort_ini,
}, },
)?; )?;
@ -242,34 +228,39 @@ pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Resu
PythonFormat { PythonFormat {
inputs: &inputs, inputs: &inputs,
check_only: false, check_only: false,
isort_ini,
}, },
)?; )?;
Ok(()) Ok(())
} }
pub struct PythonLint { pub struct RuffCheck {
pub folders: &'static [&'static str], pub folders: &'static [&'static str],
pub pylint_ini: BuildInput,
pub deps: BuildInput, pub deps: BuildInput,
pub check_only: bool,
} }
impl BuildAction for PythonLint { impl BuildAction for RuffCheck {
fn command(&self) -> &str { fn command(&self) -> &str {
"$pylint --rcfile $pylint_ini -sn -j $cpus $folders" "$ruff check $folders $mode"
} }
fn files(&mut self, build: &mut impl crate::build::FilesHandle) { fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
build.add_inputs("", &self.deps); build.add_inputs("", &self.deps);
build.add_inputs("pylint", inputs![":pyenv:pylint"]); build.add_inputs("", inputs![".ruff.toml"]);
build.add_inputs("pylint_ini", &self.pylint_ini); build.add_inputs("ruff", inputs![":pyenv:ruff"]);
build.add_variable("folders", self.folders.join(" ")); build.add_variable("folders", self.folders.join(" "));
// On a 16 core system, values above 10 do not improve wall clock time, build.add_variable(
// but waste extra cores that could be working on other tests. "mode",
build.add_variable("cpus", num_cpus::get().min(10).to_string()); if self.check_only {
""
} else {
"--fix --unsafe-fixes"
},
);
let hash = simple_hash(&self.deps); let hash = simple_hash(&self.deps);
build.add_output_stamp(format!("tests/python_lint.{hash}")); let kind = if self.check_only { "check" } else { "fix" };
build.add_output_stamp(format!("tests/python_ruff.{kind}.{hash}"));
} }
} }

View file

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

View file

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

View file

@ -138,7 +138,7 @@ fn setup_build_root() -> Utf8PathBuf {
true true
}; };
if create { 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(); std::os::unix::fs::symlink(new_target, build_root).unwrap();
} }
} }

View file

@ -83,7 +83,7 @@ fn split_args(args: Vec<String>) -> Vec<Vec<String>> {
pub fn run_command(command: &mut Command) { pub fn run_command(command: &mut Command) {
if let Err(err) = command.ensure_success() { if let Err(err) = command.ensure_success() {
println!("{}", err); println!("{err}");
std::process::exit(1); std::process::exit(1);
} }
} }

View file

@ -85,7 +85,7 @@ When formatting issues are reported, they can be fixed with
./ninja format ./ninja format
``` ```
## Fixing eslint/copyright header issues ## Fixing ruff/eslint/copyright header issues
``` ```
./ninja fix ./ninja fix

View file

@ -98,12 +98,6 @@ 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). 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 ### Typescript
Anki uses [protobuf-es](https://github.com/bufbuild/protobuf-es), which offers Anki uses [protobuf-es](https://github.com/bufbuild/protobuf-es), which offers

@ -1 +1 @@
Subproject commit cc56464ab6354d4f1ad87ab3cc5c071c076b662d Subproject commit 4a65d6012ac022a35f5c80c80b2b665447b6a525

View file

@ -425,6 +425,8 @@ deck-config-desired-retention-tooltip =
less frequently, and you will forget more of them. Be conservative when adjusting this - higher 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 values will greatly increase your workload, and lower values can be demoralizing when you forget
a lot of material. a lot of material.
deck-config-desired-retention-tooltip2 =
The workload values provided by the tooltip are a rough approximation. For a greater level of accuracy, use the simulator.
deck-config-historical-retention-tooltip = deck-config-historical-retention-tooltip =
When some of your review history is missing, FSRS needs to fill in the gaps. By default, it will 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 assume that when you did those old reviews, you remembered 90% of the material. If your old retention

@ -1 +1 @@
Subproject commit 5f9a9ceb6e8a9aade26c1ad9f1c936f5cc4d9e2a Subproject commit f42461a6438cbe844150f543128d79a669bc4ef2

View file

@ -435,7 +435,7 @@ impl TextWriter {
item = item.trim_start_matches(' '); item = item.trim_start_matches(' ');
} }
write!(self.buffer, "{}", item) write!(self.buffer, "{item}")
} }
fn write_char_into_indent(&mut self, ch: char) { 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>> { fn all_langs(lang_folder: &Utf8Path) -> Result<Vec<Utf8PathBuf>> {
std::fs::read_dir(lang_folder) std::fs::read_dir(lang_folder)
.with_context(|| format!("reading {:?}", lang_folder))? .with_context(|| format!("reading {lang_folder:?}"))?
.filter_map(Result::ok) .filter_map(Result::ok)
.map(|e| Ok(e.path().utf8()?)) .map(|e| Ok(e.path().utf8()?))
.collect() .collect()

View file

@ -46,7 +46,6 @@ from .errors import (
# the following comment is required to suppress a warning that only shows up # the following comment is required to suppress a warning that only shows up
# when there are other pylint failures # when there are other pylint failures
# pylint: disable=c-extension-no-member
if _rsbridge.buildhash() != anki.buildinfo.buildhash: if _rsbridge.buildhash() != anki.buildinfo.buildhash:
raise Exception( raise Exception(
f"""rsbridge and anki build hashes do not match: f"""rsbridge and anki build hashes do not match:
@ -164,7 +163,7 @@ class RustBackend(RustBackendGenerated):
finally: finally:
elapsed = time.time() - start elapsed = time.time() - start
if current_thread() is main_thread() and elapsed > 0.2: 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())) print("".join(traceback.format_stack()))
err = backend_pb2.BackendError() err = backend_pb2.BackendError()

View file

@ -7,7 +7,7 @@ import pprint
import time import time
from typing import NewType from typing import NewType
import anki # pylint: disable=unused-import import anki
import anki.collection import anki.collection
import anki.decks import anki.decks
import anki.notes import anki.notes

View file

@ -158,7 +158,7 @@ class Collection(DeprecatedNamesMixin):
self.tags = TagManager(self) self.tags = TagManager(self)
self.conf = ConfigManager(self) self.conf = ConfigManager(self)
self._load_scheduler() self._load_scheduler()
self._startReps = 0 # pylint: disable=invalid-name self._startReps = 0
def name(self) -> Any: def name(self) -> Any:
return os.path.splitext(os.path.basename(self.path))[0] return os.path.splitext(os.path.basename(self.path))[0]
@ -511,9 +511,7 @@ class Collection(DeprecatedNamesMixin):
# Utils # Utils
########################################################################## ##########################################################################
def nextID( # pylint: disable=invalid-name def nextID(self, type: str, inc: bool = True) -> Any:
self, type: str, inc: bool = True
) -> Any:
type = f"next{type.capitalize()}" type = f"next{type.capitalize()}"
id = self.conf.get(type, 1) id = self.conf.get(type, 1)
if inc: if inc:
@ -849,7 +847,6 @@ class Collection(DeprecatedNamesMixin):
) )
def _pb_search_separator(self, operator: SearchJoiner) -> SearchNode.Group.Joiner.V: def _pb_search_separator(self, operator: SearchJoiner) -> SearchNode.Group.Joiner.V:
# pylint: disable=no-member
if operator == "AND": if operator == "AND":
return SearchNode.Group.Joiner.AND return SearchNode.Group.Joiner.AND
else: else:
@ -867,7 +864,9 @@ class Collection(DeprecatedNamesMixin):
return column return column
return None 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], Generator[tuple[str, bool, BrowserRow.Cell.TextElideMode.V], None, None],
BrowserRow.Color.V, BrowserRow.Color.V,
str, str,
@ -1212,8 +1211,6 @@ class Collection(DeprecatedNamesMixin):
# the count on things like edits, which we probably could do by checking # the count on things like edits, which we probably could do by checking
# the previous state in moveToState. # the previous state in moveToState.
# pylint: disable=invalid-name
def startTimebox(self) -> None: def startTimebox(self) -> None:
self._startTime = time.time() self._startTime = time.time()
self._startReps = self.sched.reps self._startReps = self.sched.reps

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -157,13 +157,13 @@ def lang_to_disk_lang(lang: str) -> str:
# the currently set interface language # the currently set interface language
current_lang = "en" # pylint: disable=invalid-name current_lang = "en"
# the current Fluent translation instance. Code in pylib/ should # the current Fluent translation instance. Code in pylib/ should
# not reference this, and should use col.tr instead. The global # not reference this, and should use col.tr instead. The global
# instance exists for legacy reasons, and as a convenience for the # instance exists for legacy reasons, and as a convenience for the
# Qt code. # Qt code.
current_i18n: anki._backend.RustBackend | None = None # pylint: disable=invalid-name current_i18n: anki._backend.RustBackend | None = None
tr_legacyglobal = anki._backend.Translations(None) tr_legacyglobal = anki._backend.Translations(None)
@ -178,7 +178,7 @@ def ngettext(single: str, plural: str, num: int) -> str:
def set_lang(lang: str) -> None: def set_lang(lang: str) -> None:
global current_lang, current_i18n # pylint: disable=invalid-name global current_lang, current_i18n
current_lang = lang current_lang = lang
current_i18n = anki._backend.RustBackend(langs=[lang]) current_i18n = anki._backend.RustBackend(langs=[lang])
tr_legacyglobal.backend = weakref.ref(current_i18n) tr_legacyglobal.backend = weakref.ref(current_i18n)
@ -198,9 +198,7 @@ def get_def_lang(user_lang: str | None = None) -> tuple[int, str]:
# getdefaultlocale() is deprecated since Python 3.11, but we need to keep using it as getlocale() behaves differently: https://bugs.python.org/issue38805 # getdefaultlocale() is deprecated since Python 3.11, but we need to keep using it as getlocale() behaves differently: https://bugs.python.org/issue38805
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", DeprecationWarning)
(sys_lang, enc) = ( (sys_lang, enc) = locale.getdefaultlocale()
locale.getdefaultlocale() # pylint: disable=deprecated-method
)
except AttributeError: except AttributeError:
# this will return a different format on Windows (e.g. Italian_Italy), resulting in us falling back to en_US # this will return a different format on Windows (e.g. Italian_Italy), resulting in us falling back to en_US
# further below # further below

View file

@ -10,7 +10,7 @@ import time
from collections.abc import Sequence from collections.abc import Sequence
from typing import Any, NewType, Union from typing import Any, NewType, Union
import anki # pylint: disable=unused-import import anki
import anki.collection import anki.collection
import anki.notes import anki.notes
from anki import notetypes_pb2 from anki import notetypes_pb2
@ -419,7 +419,7 @@ and notes.mid = ? and cards.ord = ?""",
# legacy API - used by unit tests and add-ons # legacy API - used by unit tests and add-ons
def change( # pylint: disable=invalid-name def change(
self, self,
notetype: NotetypeDict, notetype: NotetypeDict,
nids: list[anki.notes.NoteId], nids: list[anki.notes.NoteId],
@ -478,8 +478,6 @@ and notes.mid = ? and cards.ord = ?""",
# Legacy # Legacy
########################################################################## ##########################################################################
# pylint: disable=invalid-name
@deprecated(info="use note.cloze_numbers_in_fields()") @deprecated(info="use note.cloze_numbers_in_fields()")
def _availClozeOrds( def _availClozeOrds(
self, notetype: NotetypeDict, flds: str, allow_empty: bool = True self, notetype: NotetypeDict, flds: str, allow_empty: bool = True

View file

@ -7,7 +7,7 @@ import copy
from collections.abc import Sequence from collections.abc import Sequence
from typing import NewType from typing import NewType
import anki # pylint: disable=unused-import import anki
import anki.cards import anki.cards
import anki.collection import anki.collection
import anki.decks import anki.decks

View file

@ -4,10 +4,8 @@
# The backend code has moved into _backend; this file exists only to avoid breaking # The backend code has moved into _backend; this file exists only to avoid breaking
# some add-ons. They should be updated to point to the correct location in the # some add-ons. They should be updated to point to the correct location in the
# future. # future.
#
# pylint: disable=unused-import
# pylint: enable=invalid-name
# ruff: noqa: F401
from anki.decks import DeckTreeNode from anki.decks import DeckTreeNode
from anki.errors import InvalidInput, NotFoundError from anki.errors import InvalidInput, NotFoundError
from anki.lang import TR from anki.lang import TR

View file

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

View file

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

View file

@ -1,7 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=invalid-name
""" """
The V3/2021 scheduler. The V3/2021 scheduler.
@ -184,7 +183,7 @@ class Scheduler(SchedulerBaseWithLegacy):
return self._interval_for_filtered_state(state.filtered) return self._interval_for_filtered_state(state.filtered)
else: else:
assert_exhaustive(kind) assert_exhaustive(kind)
return 0 # pylint: disable=unreachable return 0
def _interval_for_normal_state( def _interval_for_normal_state(
self, normal: scheduler_pb2.SchedulingState.Normal self, normal: scheduler_pb2.SchedulingState.Normal
@ -200,7 +199,7 @@ class Scheduler(SchedulerBaseWithLegacy):
return normal.relearning.learning.scheduled_secs return normal.relearning.learning.scheduled_secs
else: else:
assert_exhaustive(kind) assert_exhaustive(kind)
return 0 # pylint: disable=unreachable return 0
def _interval_for_filtered_state( def _interval_for_filtered_state(
self, filtered: scheduler_pb2.SchedulingState.Filtered self, filtered: scheduler_pb2.SchedulingState.Filtered
@ -212,7 +211,7 @@ class Scheduler(SchedulerBaseWithLegacy):
return self._interval_for_normal_state(filtered.rescheduling.original_state) return self._interval_for_normal_state(filtered.rescheduling.original_state)
else: else:
assert_exhaustive(kind) assert_exhaustive(kind)
return 0 # pylint: disable=unreachable return 0
def nextIvl(self, card: Card, ease: int) -> Any: def nextIvl(self, card: Card, ease: int) -> Any:
"Don't use this - it is only required by tests, and will be moved in the future." "Don't use this - it is only required by tests, and will be moved in the future."

View file

@ -1,7 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pylint: disable=C
from __future__ import annotations from __future__ import annotations
@ -27,7 +26,7 @@ def _legacy_card_stats(
col: anki.collection.Collection, card_id: anki.cards.CardId, include_revlog: bool col: anki.collection.Collection, card_id: anki.cards.CardId, include_revlog: bool
) -> str: ) -> str:
"A quick hack to preserve compatibility with the old HTML string API." "A quick hack to preserve compatibility with the old HTML string API."
random_id = f"cardinfo-{base62(random.randint(0, 2 ** 64 - 1))}" random_id = f"cardinfo-{base62(random.randint(0, 2**64 - 1))}"
varName = random_id.replace("-", "") varName = random_id.replace("-", "")
return f""" return f"""
<div id="{random_id}"></div> <div id="{random_id}"></div>
@ -324,7 +323,6 @@ group by day order by day"""
yaxes=[dict(min=0), dict(position="right", min=0)], yaxes=[dict(min=0), dict(position="right", min=0)],
) )
if days is not None: if days is not None:
# pylint: disable=invalid-unary-operand-type
conf["xaxis"]["min"] = -days + 0.5 conf["xaxis"]["min"] = -days + 0.5
def plot(id: str, data: Any, ylabel: str, ylabel2: str) -> str: def plot(id: str, data: Any, ylabel: str, ylabel2: str) -> str:
@ -359,7 +357,6 @@ group by day order by day"""
yaxes=[dict(min=0), dict(position="right", min=0)], yaxes=[dict(min=0), dict(position="right", min=0)],
) )
if days is not None: if days is not None:
# pylint: disable=invalid-unary-operand-type
conf["xaxis"]["min"] = -days + 0.5 conf["xaxis"]["min"] = -days + 0.5
def plot(id: str, data: Any, ylabel: str, ylabel2: str) -> str: def plot(id: str, data: Any, ylabel: str, ylabel2: str) -> str:

View file

@ -1,5 +1,3 @@
# pylint: disable=invalid-name
# from subtlepatterns.com; CC BY 4.0. # from subtlepatterns.com; CC BY 4.0.
# by Daniel Beaton # by Daniel Beaton
# https://www.toptal.com/designers/subtlepatterns/fancy-deboss/ # https://www.toptal.com/designers/subtlepatterns/fancy-deboss/

View file

@ -12,7 +12,6 @@ from anki import notetypes_pb2
from anki._legacy import DeprecatedNamesMixinForModule from anki._legacy import DeprecatedNamesMixinForModule
from anki.utils import from_json_bytes from anki.utils import from_json_bytes
# pylint: disable=no-member
StockNotetypeKind = notetypes_pb2.StockNotetype.Kind StockNotetypeKind = notetypes_pb2.StockNotetype.Kind
# add-on authors can add ("note type name", function) # add-on authors can add ("note type name", function)

View file

@ -16,7 +16,7 @@ import re
from collections.abc import Collection, Sequence from collections.abc import Collection, Sequence
from typing import Match from typing import Match
import anki # pylint: disable=unused-import import anki
import anki.collection import anki.collection
from anki import tags_pb2 from anki import tags_pb2
from anki._legacy import DeprecatedNamesMixin, deprecated from anki._legacy import DeprecatedNamesMixin, deprecated

View file

@ -24,7 +24,6 @@ from anki.dbproxy import DBProxy
_tmpdir: str | None _tmpdir: str | None
try: try:
# pylint: disable=c-extension-no-member
import orjson import orjson
to_json_bytes: Callable[[Any], bytes] = orjson.dumps to_json_bytes: Callable[[Any], bytes] = orjson.dumps
@ -156,12 +155,12 @@ def field_checksum(data: str) -> int:
# Temp files # Temp files
############################################################################## ##############################################################################
_tmpdir = None # pylint: disable=invalid-name _tmpdir = None
def tmpdir() -> str: def tmpdir() -> str:
"A reusable temp folder which we clean out on each program invocation." "A reusable temp folder which we clean out on each program invocation."
global _tmpdir # pylint: disable=invalid-name global _tmpdir
if not _tmpdir: if not _tmpdir:
def cleanup() -> None: def cleanup() -> None:
@ -216,7 +215,6 @@ def call(argv: list[str], wait: bool = True, **kwargs: Any) -> int:
try: try:
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW # type: ignore info.dwFlags |= subprocess.STARTF_USESHOWWINDOW # type: ignore
except Exception: except Exception:
# pylint: disable=no-member
info.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW # type: ignore info.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW # type: ignore
else: else:
info = None info = None
@ -282,7 +280,7 @@ def plat_desc() -> str:
elif is_win: elif is_win:
theos = f"win:{platform.win32_ver()[0]}" theos = f"win:{platform.win32_ver()[0]}"
elif system == "Linux": elif system == "Linux":
import distro # pytype: disable=import-error # pylint: disable=import-error import distro # pytype: disable=import-error
dist_id = distro.id() dist_id = distro.id()
dist_version = distro.version() dist_version = distro.version()

View file

@ -28,6 +28,6 @@ fn main() {
.to_string(); .to_string();
let libs_path = stdlib_path + "s"; let libs_path = stdlib_path + "s";
println!("cargo:rustc-link-search={}", libs_path); println!("cargo:rustc-link-search={libs_path}");
} }
} }

View file

@ -169,8 +169,7 @@ def test_find_cards():
# properties # properties
id = col.db.scalar("select id from cards limit 1") id = col.db.scalar("select id from cards limit 1")
col.db.execute( col.db.execute(
"update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 " "update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 where id = ?",
"where id = ?",
id, id,
) )
assert len(col.find_cards("prop:ivl>5")) == 1 assert len(col.find_cards("prop:ivl>5")) == 1

View file

@ -551,12 +551,10 @@ def test_bury():
col.addNote(note) col.addNote(note)
c2 = note.cards()[0] c2 = note.cards()[0]
# burying # burying
col.sched.bury_cards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg col.sched.bury_cards([c.id], manual=True)
c.load() c.load()
assert c.queue == QUEUE_TYPE_MANUALLY_BURIED assert c.queue == QUEUE_TYPE_MANUALLY_BURIED
col.sched.bury_cards( col.sched.bury_cards([c2.id], manual=False)
[c2.id], manual=False
) # pylint: disable=unexpected-keyword-arg
c2.load() c2.load()
assert c2.queue == QUEUE_TYPE_SIBLING_BURIED assert c2.queue == QUEUE_TYPE_SIBLING_BURIED

View file

@ -15,6 +15,5 @@ with open(buildhash_file, "r", encoding="utf8") as f:
with open(outpath, "w", encoding="utf8") as f: with open(outpath, "w", encoding="utf8") as f:
# if we switch to uppercase we'll need to add legacy aliases # if we switch to uppercase we'll need to add legacy aliases
f.write("# pylint: disable=invalid-name\n")
f.write(f"version = '{version}'\n") f.write(f"version = '{version}'\n")
f.write(f"buildhash = '{buildhash}'\n") f.write(f"buildhash = '{buildhash}'\n")

View file

@ -133,7 +133,7 @@ prefix = """\
# This file is automatically generated; edit tools/genhooks.py instead. # This file is automatically generated; edit tools/genhooks.py instead.
# Please import from anki.hooks instead of this file. # Please import from anki.hooks instead of this file.
# pylint: disable=unused-import # ruff: noqa: F401
from __future__ import annotations from __future__ import annotations

View file

@ -7,7 +7,6 @@ Code for generating hooks.
from __future__ import annotations from __future__ import annotations
import os
import subprocess import subprocess
import sys import sys
from dataclasses import dataclass from dataclasses import dataclass
@ -204,9 +203,6 @@ def write_file(path: str, hooks: list[Hook], prefix: str, suffix: str):
code += f"\n{suffix}" code += f"\n{suffix}"
# work around issue with latest black
if sys.platform == "win32" and "HOME" in os.environ:
os.environ["USERPROFILE"] = os.environ["HOME"]
with open(path, "wb") as file: with open(path, "wb") as file:
file.write(code.encode("utf8")) file.write(code.encode("utf8"))
subprocess.run([sys.executable, "-m", "black", "-q", path], check=True) subprocess.run([sys.executable, "-m", "ruff", "format", "-q", path], check=True)

View file

@ -7,14 +7,11 @@ classifiers = ["Private :: Do Not Upload"]
[dependency-groups] [dependency-groups]
dev = [ dev = [
"black",
"isort",
"mypy", "mypy",
"mypy-protobuf", "mypy-protobuf",
"pylint", "ruff",
"pytest", "pytest",
"PyChromeDevTools", "PyChromeDevTools",
"colorama", # for isort --color
"wheel", "wheel",
"hatchling", # for type checking hatch_build.py files "hatchling", # for type checking hatch_build.py files
"mock", "mock",

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os import os
import subprocess import subprocess
os.environ["REPO_ROOT"] = os.path.abspath(".") os.environ["REPO_ROOT"] = os.path.abspath(".")
subprocess.run(["out/pyenv/bin/sphinx-apidoc", "-o", "out/python/sphinx", "pylib", "qt"], check=True) subprocess.run(["out/pyenv/bin/sphinx-apidoc", "-o", "out/python/sphinx", "pylib", "qt"], check=True)
subprocess.run(["out/pyenv/bin/sphinx-build", "out/python/sphinx", "out/python/sphinx/html"], check=True) subprocess.run(["out/pyenv/bin/sphinx-build", "out/python/sphinx", "out/python/sphinx/html"], check=True)

View file

@ -1,5 +0,0 @@
[settings]
py_version=39
profile=black
known_first_party=anki,aqt
extend_skip=aqt/forms,hooks_gen.py

View file

@ -3,6 +3,7 @@
from __future__ import annotations from __future__ import annotations
# ruff: noqa: F401
import atexit import atexit
import logging import logging
import os import os
@ -28,7 +29,7 @@ if sys.version_info[0] < 3 or sys.version_info[1] < 9:
# ensure unicode filenames are supported # ensure unicode filenames are supported
try: try:
"テスト".encode(sys.getfilesystemencoding()) "テスト".encode(sys.getfilesystemencoding())
except UnicodeEncodeError as exc: except UnicodeEncodeError:
print("Anki requires a UTF-8 locale.") print("Anki requires a UTF-8 locale.")
print("Please Google 'how to change locale on [your Linux distro]'") print("Please Google 'how to change locale on [your Linux distro]'")
sys.exit(1) sys.exit(1)
@ -41,6 +42,11 @@ if "--syncserver" in sys.argv:
# does not return # does not return
run_sync_server() run_sync_server()
if sys.platform == "win32":
from win32com.shell import shell
shell.SetCurrentProcessExplicitAppUserModelID("Ankitects.Anki")
import argparse import argparse
import builtins import builtins
import cProfile import cProfile
@ -285,7 +291,6 @@ class NativeEventFilter(QAbstractNativeEventFilter):
def nativeEventFilter( def nativeEventFilter(
self, eventType: Any, message: Any self, eventType: Any, message: Any
) -> tuple[bool, Any | None]: ) -> tuple[bool, Any | None]:
if eventType == "windows_generic_MSG": if eventType == "windows_generic_MSG":
import ctypes.wintypes import ctypes.wintypes
@ -558,7 +563,7 @@ def run() -> None:
print(f"Starting Anki {_version}...") print(f"Starting Anki {_version}...")
try: try:
_run() _run()
except Exception as e: except Exception:
traceback.print_exc() traceback.print_exc()
QMessageBox.critical( QMessageBox.critical(
None, None,

View file

@ -6,8 +6,6 @@ from __future__ import annotations
import sys import sys
if sys.platform == "darwin": if sys.platform == "darwin":
from anki_mac_helper import ( # pylint:disable=unused-import,import-error from anki_mac_helper import macos_helper
macos_helper,
)
else: else:
macos_helper = None macos_helper = None

View file

@ -927,7 +927,6 @@ class AddonsDialog(QDialog):
or self.mgr.configAction(addon.dir_name) or self.mgr.configAction(addon.dir_name)
) )
) )
return
def _onAddonItemSelected(self, row_int: int) -> None: def _onAddonItemSelected(self, row_int: int) -> None:
try: try:
@ -1457,7 +1456,9 @@ class ChooseAddonsToUpdateDialog(QDialog):
layout.addWidget(addons_list_widget) layout.addWidget(addons_list_widget)
self.addons_list_widget = addons_list_widget self.addons_list_widget = addons_list_widget
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) # type: ignore button_box = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
) # type: ignore
qconnect( qconnect(
button_box.button(QDialogButtonBox.StandardButton.Ok).clicked, self.accept button_box.button(QDialogButtonBox.StandardButton.Ok).clicked, self.accept
) )

View file

@ -36,7 +36,6 @@ def ankihub_login(
username: str = "", username: str = "",
password: str = "", password: str = "",
) -> None: ) -> None:
def on_future_done(fut: Future[str], username: str, password: str) -> None: def on_future_done(fut: Future[str], username: str, password: str) -> None:
try: try:
token = fut.result() token = fut.result()
@ -73,7 +72,6 @@ def ankihub_logout(
on_success: Callable[[], None], on_success: Callable[[], None],
token: str, token: str,
) -> None: ) -> None:
def logout() -> None: def logout() -> None:
mw.pm.set_ankihub_username(None) mw.pm.set_ankihub_username(None)
mw.pm.set_ankihub_token(None) mw.pm.set_ankihub_token(None)

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations from __future__ import annotations
# ruff: noqa: F401
import sys import sys
import aqt import aqt

View file

@ -1,5 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# ruff: noqa: F401
from anki.utils import is_mac from anki.utils import is_mac
from aqt.theme import theme_manager from aqt.theme import theme_manager

View file

@ -106,7 +106,7 @@ class SidebarTreeView(QTreeView):
def _setup_style(self) -> None: def _setup_style(self) -> None:
# match window background color and tweak style # match window background color and tweak style
bgcolor = QPalette().window().color().name() bgcolor = QPalette().window().color().name()
border = theme_manager.var(colors.BORDER) theme_manager.var(colors.BORDER)
styles = [ styles = [
"padding: 3px", "padding: 3px",
"padding-right: 0px", "padding-right: 0px",
@ -711,7 +711,6 @@ class SidebarTreeView(QTreeView):
def _flags_tree(self, root: SidebarItem) -> None: def _flags_tree(self, root: SidebarItem) -> None:
icon_off = "icons:flag-variant-off-outline.svg" icon_off = "icons:flag-variant-off-outline.svg"
icon = "icons:flag-variant.svg"
icon_outline = "icons:flag-variant-outline.svg" icon_outline = "icons:flag-variant-outline.svg"
root = self._section_root( root = self._section_root(

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations from __future__ import annotations
# ruff: noqa: F401
import copy import copy
import time import time
from collections.abc import Generator, Sequence from collections.abc import Generator, Sequence

View file

@ -105,11 +105,11 @@ class DataModel(QAbstractTableModel):
row = CellRow(*self.col.browser_row_for_id(item)) row = CellRow(*self.col.browser_row_for_id(item))
except BackendError as e: except BackendError as e:
return CellRow.disabled(self.len_columns(), str(e)) return CellRow.disabled(self.len_columns(), str(e))
except Exception as e: except Exception:
return CellRow.disabled( return CellRow.disabled(
self.len_columns(), tr.errors_please_check_database() self.len_columns(), tr.errors_please_check_database()
) )
except BaseException as e: except BaseException:
# fatal error like a panic in the backend - dump it to the # fatal error like a panic in the backend - dump it to the
# console so it gets picked up by the error handler # console so it gets picked up by the error handler
import traceback import traceback

View file

@ -59,7 +59,7 @@ class ItemState(ABC):
# abstractproperty is deprecated but used due to mypy limitations # abstractproperty is deprecated but used due to mypy limitations
# (https://github.com/python/mypy/issues/1362) # (https://github.com/python/mypy/issues/1362)
@abstractproperty # pylint: disable=deprecated-decorator @abstractproperty
def active_columns(self) -> list[str]: def active_columns(self) -> list[str]:
"""Return the saved or default columns for the state.""" """Return the saved or default columns for the state."""

View file

@ -361,8 +361,7 @@ class Table:
for m in self.col.models.all(): for m in self.col.models.all():
for t in m["tmpls"]: for t in m["tmpls"]:
bsize = t.get("bsize", 0) bsize = t.get("bsize", 0)
if bsize > curmax: curmax = max(curmax, bsize)
curmax = bsize
assert self._view is not None assert self._view is not None
vh = self._view.verticalHeader() vh = self._view.verticalHeader()

View file

@ -221,7 +221,7 @@ class CardLayout(QDialog):
) )
for i in range(min(len(self.cloze_numbers), 9)): for i in range(min(len(self.cloze_numbers), 9)):
QShortcut( # type: ignore QShortcut( # type: ignore
QKeySequence(f"Alt+{i+1}"), QKeySequence(f"Alt+{i + 1}"),
self, self,
activated=lambda n=i: self.pform.cloze_number_combo.setCurrentIndex(n), activated=lambda n=i: self.pform.cloze_number_combo.setCurrentIndex(n),
) )
@ -790,7 +790,7 @@ class CardLayout(QDialog):
assert a is not None assert a is not None
qconnect( qconnect(
a.triggered, a.triggered,
lambda: self.on_restore_to_default(), # pylint: disable=unnecessary-lambda lambda: self.on_restore_to_default(),
) )
if not self._isCloze(): if not self._isCloze():

View file

@ -294,7 +294,6 @@ class DebugConsole(QDialog):
} }
self._captureOutput(True) self._captureOutput(True)
try: try:
# pylint: disable=exec-used
exec(text, vars) exec(text, vars)
except Exception: except Exception:
self._output += traceback.format_exc() self._output += traceback.format_exc()

View file

@ -386,9 +386,7 @@ class DeckBrowser:
if b[0]: if b[0]:
b[0] = tr.actions_shortcut_key(val=shortcut(b[0])) b[0] = tr.actions_shortcut_key(val=shortcut(b[0]))
buf += """ buf += """
<button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple( <button title='%s' onclick='pycmd(\"%s\");'>%s</button>""" % tuple(b)
b
)
self.bottom.draw( self.bottom.draw(
buf=buf, buf=buf,
link_handler=self._linkHandler, link_handler=self._linkHandler,

View file

@ -320,7 +320,7 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
gui_hooks.editor_did_init_shortcuts(cuts, self) gui_hooks.editor_did_init_shortcuts(cuts, self)
for row in cuts: for row in cuts:
if len(row) == 2: if len(row) == 2:
keys, fn = row # pylint: disable=unbalanced-tuple-unpacking keys, fn = row
fn = self._addFocusCheck(fn) fn = self._addFocusCheck(fn)
else: else:
keys, fn, _ = row keys, fn, _ = row

View file

@ -212,11 +212,10 @@ class ExportDialog(QDialog):
if self.isVerbatim: if self.isVerbatim:
msg = tr.exporting_collection_exported() msg = tr.exporting_collection_exported()
self.mw.reopen() self.mw.reopen()
elif self.isTextNote:
msg = tr.exporting_note_exported(count=self.exporter.count)
else: else:
if self.isTextNote: msg = tr.exporting_card_exported(count=self.exporter.count)
msg = tr.exporting_note_exported(count=self.exporter.count)
else:
msg = tr.exporting_card_exported(count=self.exporter.count)
gui_hooks.legacy_exporter_did_export(self.exporter) gui_hooks.legacy_exporter_did_export(self.exporter)
tooltip(msg, period=3000) tooltip(msg, period=3000)
QDialog.reject(self) QDialog.reject(self)

View file

@ -1,3 +1,4 @@
# ruff: noqa: F401
from . import ( from . import (
about, about,
addcards, addcards,

View file

@ -134,9 +134,8 @@ IMPORTERS: list[type[Importer]] = [
def legacy_file_endings(col: Collection) -> list[str]: def legacy_file_endings(col: Collection) -> list[str]:
from anki.importing import AnkiPackageImporter from anki.importing import AnkiPackageImporter, TextImporter, importers
from anki.importing import MnemosyneImporter as LegacyMnemosyneImporter from anki.importing import MnemosyneImporter as LegacyMnemosyneImporter
from anki.importing import TextImporter, importers
return [ return [
ext ext

View file

@ -11,10 +11,10 @@ from collections.abc import Callable
from concurrent.futures import Future from concurrent.futures import Future
from typing import Any from typing import Any
import anki.importing as importing
import aqt.deckchooser import aqt.deckchooser
import aqt.forms import aqt.forms
import aqt.modelchooser import aqt.modelchooser
from anki import importing
from anki.importing.anki2 import MediaMapInvalid, V2ImportIntoV1 from anki.importing.anki2 import MediaMapInvalid, V2ImportIntoV1
from anki.importing.apkg import AnkiPackageImporter from anki.importing.apkg import AnkiPackageImporter
from aqt.import_export.importing import ColpkgImporter from aqt.import_export.importing import ColpkgImporter
@ -262,7 +262,7 @@ class ImportDialog(QDialog):
self.mapwidget.setLayout(self.grid) self.mapwidget.setLayout(self.grid)
self.grid.setContentsMargins(3, 3, 3, 3) self.grid.setContentsMargins(3, 3, 3, 3)
self.grid.setSpacing(6) self.grid.setSpacing(6)
for num in range(len(self.mapping)): # pylint: disable=consider-using-enumerate for num in range(len(self.mapping)):
text = tr.importing_field_of_file_is(val=num + 1) text = tr.importing_field_of_file_is(val=num + 1)
self.grid.addWidget(QLabel(text), num, 0) self.grid.addWidget(QLabel(text), num, 0)
if self.mapping[num] == "_tags": if self.mapping[num] == "_tags":
@ -357,7 +357,7 @@ def importFile(mw: AnkiQt, file: str) -> None:
try: try:
importer.open() importer.open()
mw.progress.finish() mw.progress.finish()
diag = ImportDialog(mw, importer) ImportDialog(mw, importer)
except UnicodeDecodeError: except UnicodeDecodeError:
mw.progress.finish() mw.progress.finish()
showUnicodeWarning() showUnicodeWarning()
@ -443,3 +443,4 @@ def setupApkgImport(mw: AnkiQt, importer: AnkiPackageImporter) -> bool:
return True return True
ColpkgImporter.do_import(mw, importer.file) ColpkgImporter.do_import(mw, importer.file)
return False return False
return False

View file

@ -376,7 +376,6 @@ class AnkiQt(QMainWindow):
def openProfile(self) -> None: def openProfile(self) -> None:
name = self.pm.profiles()[self.profileForm.profiles.currentRow()] name = self.pm.profiles()[self.profileForm.profiles.currentRow()]
self.pm.load(name) self.pm.load(name)
return
def onOpenProfile(self, *, callback: Callable[[], None] | None = None) -> None: def onOpenProfile(self, *, callback: Callable[[], None] | None = None) -> None:
def on_done() -> None: def on_done() -> None:
@ -451,7 +450,6 @@ class AnkiQt(QMainWindow):
self.loadProfile() self.loadProfile()
def onOpenBackup(self) -> None: def onOpenBackup(self) -> None:
def do_open(path: str) -> None: def do_open(path: str) -> None:
if not askUser( if not askUser(
tr.qt_misc_replace_your_collection_with_an_earlier2( tr.qt_misc_replace_your_collection_with_an_earlier2(
@ -677,7 +675,7 @@ class AnkiQt(QMainWindow):
gui_hooks.collection_did_load(self.col) gui_hooks.collection_did_load(self.col)
self.apply_collection_options() self.apply_collection_options()
self.moveToState("deckBrowser") self.moveToState("deckBrowser")
except Exception as e: except Exception:
# dump error to stderr so it gets picked up by errors.py # dump error to stderr so it gets picked up by errors.py
traceback.print_exc() traceback.print_exc()
@ -774,7 +772,6 @@ class AnkiQt(QMainWindow):
oldState = self.state oldState = self.state
cleanup = getattr(self, f"_{oldState}Cleanup", None) cleanup = getattr(self, f"_{oldState}Cleanup", None)
if cleanup: if cleanup:
# pylint: disable=not-callable
cleanup(state) cleanup(state)
self.clearStateShortcuts() self.clearStateShortcuts()
self.state = state self.state = state
@ -821,7 +818,7 @@ class AnkiQt(QMainWindow):
self.bottomWeb.hide_timer.start() self.bottomWeb.hide_timer.start()
def _reviewCleanup(self, newState: MainWindowState) -> None: def _reviewCleanup(self, newState: MainWindowState) -> None:
if newState != "resetRequired" and newState != "review": if newState not in {"resetRequired", "review"}:
self.reviewer.auto_advance_enabled = False self.reviewer.auto_advance_enabled = False
self.reviewer.cleanup() self.reviewer.cleanup()
self.toolbarWeb.elevate() self.toolbarWeb.elevate()
@ -1722,11 +1719,37 @@ title="{}" {}>{}</button>""".format(
self.maybeHideAccelerators() self.maybeHideAccelerators()
self.hideStatusTips() self.hideStatusTips()
elif is_win: elif is_win:
# make sure ctypes is bundled self._setupWin32()
from ctypes import windll, wintypes # type: ignore
_dummy1 = windll def _setupWin32(self):
_dummy2 = wintypes """Fix taskbar display/pinning"""
if sys.platform != "win32":
return
launcher_path = os.environ.get("ANKI_LAUNCHER")
if not launcher_path:
return
from win32com.propsys import propsys, pscon
from win32com.propsys.propsys import PROPVARIANTType
hwnd = int(self.winId())
prop_store = propsys.SHGetPropertyStoreForWindow(hwnd) # type: ignore[call-arg]
prop_store.SetValue(
pscon.PKEY_AppUserModel_ID, PROPVARIANTType("Ankitects.Anki")
)
prop_store.SetValue(
pscon.PKEY_AppUserModel_RelaunchCommand,
PROPVARIANTType(f'"{launcher_path}"'),
)
prop_store.SetValue(
pscon.PKEY_AppUserModel_RelaunchDisplayNameResource, PROPVARIANTType("Anki")
)
prop_store.SetValue(
pscon.PKEY_AppUserModel_RelaunchIconResource,
PROPVARIANTType(f"{launcher_path},0"),
)
prop_store.Commit()
def maybeHideAccelerators(self, tgt: Any | None = None) -> None: def maybeHideAccelerators(self, tgt: Any | None = None) -> None:
if not self.hideMenuAccels: if not self.hideMenuAccels:

View file

@ -232,7 +232,11 @@ def _handle_local_file_request(request: LocalFileRequest) -> Response:
else: else:
max_age = 60 * 60 max_age = 60 * 60
return flask.send_file( return flask.send_file(
fullpath, mimetype=mimetype, conditional=True, max_age=max_age, download_name="foo" # type: ignore[call-arg] fullpath,
mimetype=mimetype,
conditional=True,
max_age=max_age,
download_name="foo", # type: ignore[call-arg]
) )
else: else:
print(f"Not found: {path}") print(f"Not found: {path}")

View file

@ -24,7 +24,7 @@
# #
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# pylint: disable=raise-missing-from
from __future__ import annotations from __future__ import annotations
import inspect import inspect
@ -66,7 +66,6 @@ class MPVTimeoutError(MPVError):
if is_win: if is_win:
# pylint: disable=import-error
import pywintypes import pywintypes
import win32file # pytype: disable=import-error import win32file # pytype: disable=import-error
import win32job import win32job
@ -138,15 +137,15 @@ class MPVBase:
extended_info = win32job.QueryInformationJobObject( extended_info = win32job.QueryInformationJobObject(
self._job, win32job.JobObjectExtendedLimitInformation self._job, win32job.JobObjectExtendedLimitInformation
) )
extended_info["BasicLimitInformation"][ extended_info["BasicLimitInformation"]["LimitFlags"] = (
"LimitFlags" win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
] = win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE )
win32job.SetInformationJobObject( win32job.SetInformationJobObject(
self._job, self._job,
win32job.JobObjectExtendedLimitInformation, win32job.JobObjectExtendedLimitInformation,
extended_info, extended_info,
) )
handle = self._proc._handle # pylint: disable=no-member handle = self._proc._handle
win32job.AssignProcessToJobObject(self._job, handle) win32job.AssignProcessToJobObject(self._job, handle)
def _stop_process(self): def _stop_process(self):
@ -193,7 +192,10 @@ class MPVBase:
None, None,
) )
win32pipe.SetNamedPipeHandleState( win32pipe.SetNamedPipeHandleState(
self._sock, 1, None, None # PIPE_NOWAIT self._sock,
1,
None,
None, # PIPE_NOWAIT
) )
except pywintypes.error as err: except pywintypes.error as err:
if err.args[0] == winerror.ERROR_FILE_NOT_FOUND: if err.args[0] == winerror.ERROR_FILE_NOT_FOUND:
@ -394,7 +396,7 @@ class MPVBase:
return self._get_response(timeout) return self._get_response(timeout)
except MPVCommandError as e: except MPVCommandError as e:
raise MPVCommandError(f"{message['command']!r}: {e}") raise MPVCommandError(f"{message['command']!r}: {e}")
except Exception as e: except Exception:
if _retry: if _retry:
print("mpv timed out, restarting") print("mpv timed out, restarting")
self._stop_process() self._stop_process()
@ -501,7 +503,6 @@ class MPV(MPVBase):
# Simulate an init event when the process and all callbacks have been # Simulate an init event when the process and all callbacks have been
# completely set up. # completely set up.
if hasattr(self, "on_init"): if hasattr(self, "on_init"):
# pylint: disable=no-member
self.on_init() self.on_init()
# #

View file

@ -113,7 +113,7 @@ class Overview:
self.mw.moveToState("deckBrowser") self.mw.moveToState("deckBrowser")
elif url == "review": elif url == "review":
openLink(f"{aqt.appShared}info/{self.sid}?v={self.sidVer}") openLink(f"{aqt.appShared}info/{self.sid}?v={self.sidVer}")
elif url == "studymore" or url == "customStudy": elif url in {"studymore", "customStudy"}:
self.onStudyMore() self.onStudyMore()
elif url == "unbury": elif url == "unbury":
self.on_unbury() self.on_unbury()
@ -180,7 +180,6 @@ class Overview:
############################################################ ############################################################
def _renderPage(self) -> None: def _renderPage(self) -> None:
but = self.mw.button
deck = self.mw.col.decks.current() deck = self.mw.col.decks.current()
self.sid = deck.get("sharedFrom") self.sid = deck.get("sharedFrom")
if self.sid: if self.sid:
@ -307,9 +306,7 @@ class Overview:
if b[0]: if b[0]:
b[0] = tr.actions_shortcut_key(val=shortcut(b[0])) b[0] = tr.actions_shortcut_key(val=shortcut(b[0]))
buf += """ buf += """
<button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple( <button title="%s" onclick='pycmd("%s")'>%s</button>""" % tuple(b)
b
)
self.bottom.draw( self.bottom.draw(
buf=buf, buf=buf,
link_handler=link_handler, link_handler=link_handler,

View file

@ -11,7 +11,7 @@ from pathlib import Path
from anki.utils import is_mac from anki.utils import is_mac
# pylint: disable=unused-import,import-error # ruff: noqa: F401
def first_run_setup() -> None: def first_run_setup() -> None:
"""Code run the first time after install/upgrade. """Code run the first time after install/upgrade.

View file

@ -128,7 +128,7 @@ class ProfileManager:
default_answer_keys = {ease_num: str(ease_num) for ease_num in range(1, 5)} default_answer_keys = {ease_num: str(ease_num) for ease_num in range(1, 5)}
last_run_version: int = 0 last_run_version: int = 0
def __init__(self, base: Path) -> None: # def __init__(self, base: Path) -> None:
"base should be retrieved via ProfileMangager.get_created_base_folder" "base should be retrieved via ProfileMangager.get_created_base_folder"
## Settings which should be forgotten each Anki restart ## Settings which should be forgotten each Anki restart
self.session: dict[str, Any] = {} self.session: dict[str, Any] = {}
@ -153,7 +153,7 @@ class ProfileManager:
else: else:
try: try:
self.load(profile) self.load(profile)
except Exception as exc: except Exception:
self.invalid_profile_provided_on_commandline = True self.invalid_profile_provided_on_commandline = True
# Profile load/save # Profile load/save
@ -483,7 +483,11 @@ create table if not exists profiles
code = obj[1] code = obj[1]
name = obj[0] name = obj[0]
r = QMessageBox.question( r = QMessageBox.question(
None, "Anki", tr.profiles_confirm_lang_choice(lang=name), QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No, QMessageBox.StandardButton.No # type: ignore None,
"Anki",
tr.profiles_confirm_lang_choice(lang=name),
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
QMessageBox.StandardButton.No, # type: ignore
) )
if r != QMessageBox.StandardButton.Yes: if r != QMessageBox.StandardButton.Yes:
return self.setDefaultLang(f.lang.currentRow()) return self.setDefaultLang(f.lang.currentRow())

View file

@ -119,13 +119,12 @@ class ProgressManager:
if not self._levels: if not self._levels:
# no current progress; safe to fire # no current progress; safe to fire
func() func()
elif repeat:
# skip this time; we'll fire again
pass
else: else:
if repeat: # retry in 100ms
# skip this time; we'll fire again self.single_shot(100, func, requires_collection)
pass
else:
# retry in 100ms
self.single_shot(100, func, requires_collection)
return handler return handler

View file

@ -2,7 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# make sure not to optimize imports on this file # make sure not to optimize imports on this file
# pylint: disable=unused-import # ruff: noqa: F401
from __future__ import annotations from __future__ import annotations
import os import os
@ -23,7 +23,7 @@ def debug() -> None:
from pdb import set_trace from pdb import set_trace
pyqtRemoveInputHook() pyqtRemoveInputHook()
set_trace() # pylint: disable=forgotten-debug-statement set_trace()
if os.environ.get("DEBUG"): if os.environ.get("DEBUG"):

View file

@ -2,8 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# make sure not to optimize imports on this file # make sure not to optimize imports on this file
# pylint: disable=unused-import # ruff: noqa: F401
""" """
PyQt6 imports PyQt6 imports
""" """

View file

@ -21,13 +21,11 @@ from anki.scheduler.base import ScheduleCardsAsNew
from anki.scheduler.v3 import ( from anki.scheduler.v3 import (
CardAnswer, CardAnswer,
QueuedCards, QueuedCards,
)
from anki.scheduler.v3 import Scheduler as V3Scheduler
from anki.scheduler.v3 import (
SchedulingContext, SchedulingContext,
SchedulingStates, SchedulingStates,
SetSchedulingStatesRequest, SetSchedulingStatesRequest,
) )
from anki.scheduler.v3 import Scheduler as V3Scheduler
from anki.tags import MARKED_TAG from anki.tags import MARKED_TAG
from anki.types import assert_exhaustive from anki.types import assert_exhaustive
from anki.utils import is_mac from anki.utils import is_mac
@ -597,10 +595,9 @@ class Reviewer:
def _shortcutKeys( def _shortcutKeys(
self, self,
) -> Sequence[tuple[str, Callable] | tuple[Qt.Key, Callable]]: ) -> Sequence[tuple[str, Callable] | tuple[Qt.Key, Callable]]:
def generate_default_answer_keys() -> Generator[
def generate_default_answer_keys() -> ( tuple[str, partial], None, None
Generator[tuple[str, partial], None, None] ]:
):
for ease in aqt.mw.pm.default_answer_keys: for ease in aqt.mw.pm.default_answer_keys:
key = aqt.mw.pm.get_answer_key(ease) key = aqt.mw.pm.get_answer_key(ease)
if not key: if not key:

View file

@ -101,7 +101,7 @@ def is_audio_file(fname: str) -> bool:
return ext in AUDIO_EXTENSIONS return ext in AUDIO_EXTENSIONS
class SoundOrVideoPlayer(Player): # pylint: disable=abstract-method class SoundOrVideoPlayer(Player):
default_rank = 0 default_rank = 0
def rank_for_tag(self, tag: AVTag) -> int | None: def rank_for_tag(self, tag: AVTag) -> int | None:
@ -111,7 +111,7 @@ class SoundOrVideoPlayer(Player): # pylint: disable=abstract-method
return None return None
class SoundPlayer(Player): # pylint: disable=abstract-method class SoundPlayer(Player):
default_rank = 0 default_rank = 0
def rank_for_tag(self, tag: AVTag) -> int | None: def rank_for_tag(self, tag: AVTag) -> int | None:
@ -121,7 +121,7 @@ class SoundPlayer(Player): # pylint: disable=abstract-method
return None return None
class VideoPlayer(Player): # pylint: disable=abstract-method class VideoPlayer(Player):
default_rank = 0 default_rank = 0
def rank_for_tag(self, tag: AVTag) -> int | None: def rank_for_tag(self, tag: AVTag) -> int | None:
@ -324,7 +324,7 @@ def retryWait(proc: subprocess.Popen) -> int:
########################################################################## ##########################################################################
class SimpleProcessPlayer(Player): # pylint: disable=abstract-method class SimpleProcessPlayer(Player):
"A player that invokes a new process for each tag to play." "A player that invokes a new process for each tag to play."
args: list[str] = [] args: list[str] = []

View file

@ -208,7 +208,7 @@ class CustomStyles:
button_pressed_gradient( button_pressed_gradient(
tm.var(colors.BUTTON_GRADIENT_START), tm.var(colors.BUTTON_GRADIENT_START),
tm.var(colors.BUTTON_GRADIENT_END), tm.var(colors.BUTTON_GRADIENT_END),
tm.var(colors.SHADOW) tm.var(colors.SHADOW),
) )
}; };
}} }}
@ -340,7 +340,7 @@ class CustomStyles:
}} }}
QTabBar::tab:selected:hover {{ QTabBar::tab:selected:hover {{
background: { background: {
button_gradient( button_gradient(
tm.var(colors.BUTTON_PRIMARY_GRADIENT_START), tm.var(colors.BUTTON_PRIMARY_GRADIENT_START),
tm.var(colors.BUTTON_PRIMARY_GRADIENT_END), tm.var(colors.BUTTON_PRIMARY_GRADIENT_END),
) )
@ -391,7 +391,7 @@ class CustomStyles:
button_pressed_gradient( button_pressed_gradient(
tm.var(colors.BUTTON_GRADIENT_START), tm.var(colors.BUTTON_GRADIENT_START),
tm.var(colors.BUTTON_GRADIENT_END), tm.var(colors.BUTTON_GRADIENT_END),
tm.var(colors.SHADOW) tm.var(colors.SHADOW),
) )
} }
}} }}
@ -647,10 +647,12 @@ class CustomStyles:
margin: -7px 0; margin: -7px 0;
}} }}
QSlider::handle:hover {{ QSlider::handle:hover {{
background: {button_gradient( background: {
tm.var(colors.BUTTON_GRADIENT_START), button_gradient(
tm.var(colors.BUTTON_GRADIENT_END), tm.var(colors.BUTTON_GRADIENT_START),
)} tm.var(colors.BUTTON_GRADIENT_END),
)
}
}} }}
""" """

View file

@ -44,7 +44,7 @@ def get_sync_status(
) -> None: ) -> None:
auth = mw.pm.sync_auth() auth = mw.pm.sync_auth()
if not auth: if not auth:
callback(SyncStatus(required=SyncStatus.NO_CHANGES)) # pylint:disable=no-member callback(SyncStatus(required=SyncStatus.NO_CHANGES))
return return
def on_future_done(fut: Future[SyncStatus]) -> None: def on_future_done(fut: Future[SyncStatus]) -> None:
@ -302,7 +302,6 @@ def sync_login(
username: str = "", username: str = "",
password: str = "", password: str = "",
) -> None: ) -> None:
def on_future_done(fut: Future[SyncAuth], username: str, password: str) -> None: def on_future_done(fut: Future[SyncAuth], username: str, password: str) -> None:
try: try:
auth = fut.result() auth = fut.result()
@ -374,7 +373,9 @@ def get_id_and_pass_from_user(
g.addWidget(passwd, 1, 1) g.addWidget(passwd, 1, 1)
l2.setBuddy(passwd) l2.setBuddy(passwd)
vbox.addLayout(g) vbox.addLayout(g)
bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel) # type: ignore bb = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
) # type: ignore
ok_button = bb.button(QDialogButtonBox.StandardButton.Ok) ok_button = bb.button(QDialogButtonBox.StandardButton.Ok)
assert ok_button is not None assert ok_button is not None
ok_button.setAutoDefault(True) ok_button.setAutoDefault(True)

View file

@ -187,7 +187,7 @@ class ThemeManager:
self, card_ord: int, night_mode: bool | None = None self, card_ord: int, night_mode: bool | None = None
) -> str: ) -> str:
"Returns body classes used when showing a card." "Returns body classes used when showing a card."
return f"card card{card_ord+1} {self.body_class(night_mode, reviewer=True)}" return f"card card{card_ord + 1} {self.body_class(night_mode, reviewer=True)}"
def var(self, vars: dict[str, str]) -> str: def var(self, vars: dict[str, str]) -> str:
"""Given day/night colors/props, return the correct one for the current theme.""" """Given day/night colors/props, return the correct one for the current theme."""
@ -213,13 +213,12 @@ class ThemeManager:
return False return False
elif theme == Theme.DARK: elif theme == Theme.DARK:
return True return True
elif is_win:
return get_windows_dark_mode()
elif is_mac:
return get_macos_dark_mode()
else: else:
if is_win: return get_linux_dark_mode()
return get_windows_dark_mode()
elif is_mac:
return get_macos_dark_mode()
else:
return get_linux_dark_mode()
def apply_style(self) -> None: def apply_style(self) -> None:
"Apply currently configured style." "Apply currently configured style."
@ -340,7 +339,7 @@ def get_windows_dark_mode() -> bool:
if not is_win: if not is_win:
return False return False
from winreg import ( # type: ignore[attr-defined] # pylint: disable=import-error from winreg import ( # type: ignore[attr-defined]
HKEY_CURRENT_USER, HKEY_CURRENT_USER,
OpenKey, OpenKey,
QueryValueEx, QueryValueEx,
@ -352,7 +351,7 @@ def get_windows_dark_mode() -> bool:
r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize",
) )
return not QueryValueEx(key, "AppsUseLightTheme")[0] return not QueryValueEx(key, "AppsUseLightTheme")[0]
except Exception as err: except Exception:
# key reportedly missing or set to wrong type on some systems # key reportedly missing or set to wrong type on some systems
return False return False
@ -416,12 +415,12 @@ def get_linux_dark_mode() -> bool:
capture_output=True, capture_output=True,
encoding="utf8", encoding="utf8",
) )
except FileNotFoundError as e: except FileNotFoundError:
# detection strategy failed, missing program # detection strategy failed, missing program
# print(e) # print(e)
continue continue
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError:
# detection strategy failed, command returned error # detection strategy failed, command returned error
# print(e) # print(e)
continue continue

View file

@ -166,7 +166,6 @@ class MacVoice(TTSVoice):
original_name: str original_name: str
# pylint: disable=no-member
class MacTTSPlayer(TTSProcessPlayer): class MacTTSPlayer(TTSProcessPlayer):
"Invokes a process to play the audio in the background." "Invokes a process to play the audio in the background."
@ -487,7 +486,7 @@ if is_win:
class WindowsTTSPlayer(TTSProcessPlayer): class WindowsTTSPlayer(TTSProcessPlayer):
default_rank = -1 default_rank = -1
try: try:
import win32com.client # pylint: disable=import-error import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker = win32com.client.Dispatch("SAPI.SpVoice")
except Exception as exc: except Exception as exc:

View file

@ -15,14 +15,12 @@ from functools import partial, wraps
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, Union from typing import TYPE_CHECKING, Any, Literal, Union
import requests
from send2trash import send2trash
import aqt import aqt
import requests
from anki._legacy import DeprecatedNamesMixinForModule from anki._legacy import DeprecatedNamesMixinForModule
from anki.collection import Collection, HelpPage from anki.collection import Collection, HelpPage
from anki.httpclient import HttpClient from anki.httpclient import HttpClient
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import from anki.lang import TR, tr_legacyglobal # noqa: F401
from anki.utils import ( from anki.utils import (
call, call,
invalid_filename, invalid_filename,
@ -32,9 +30,9 @@ from anki.utils import (
version_with_build, version_with_build,
) )
from aqt.qt import * from aqt.qt import *
from aqt.qt import QT_VERSION_STR # noqa: F401
from aqt.qt import ( from aqt.qt import (
PYQT_VERSION_STR, PYQT_VERSION_STR,
QT_VERSION_STR,
QAction, QAction,
QApplication, QApplication,
QCheckBox, QCheckBox,
@ -84,6 +82,7 @@ from aqt.qt import (
traceback, traceback,
) )
from aqt.theme import theme_manager from aqt.theme import theme_manager
from send2trash import send2trash
if TYPE_CHECKING: if TYPE_CHECKING:
TextFormat = Literal["plain", "rich", "markdown"] TextFormat = Literal["plain", "rich", "markdown"]
@ -340,7 +339,7 @@ def showInfo(
icon = QMessageBox.Icon.Critical icon = QMessageBox.Icon.Critical
else: else:
icon = QMessageBox.Icon.Information icon = QMessageBox.Icon.Information
mb = QMessageBox(parent_widget) # mb = QMessageBox(parent_widget)
if textFormat == "plain": if textFormat == "plain":
mb.setTextFormat(Qt.TextFormat.PlainText) mb.setTextFormat(Qt.TextFormat.PlainText)
elif textFormat == "rich": elif textFormat == "rich":
@ -1013,9 +1012,8 @@ def show_in_folder(path: str) -> None:
def _show_in_folder_win32(path: str) -> None: def _show_in_folder_win32(path: str) -> None:
import win32con # pylint: disable=import-error import win32con
import win32gui # pylint: disable=import-error import win32gui
from aqt import mw from aqt import mw
def focus_explorer(): def focus_explorer():
@ -1309,12 +1307,12 @@ def opengl_vendor() -> str | None:
# Can't use versionFunctions there # Can't use versionFunctions there
return None return None
vp = QOpenGLVersionProfile() # type: ignore # pylint: disable=undefined-variable vp = QOpenGLVersionProfile() # type: ignore
vp.setVersion(2, 0) vp.setVersion(2, 0)
try: try:
vf = ctx.versionFunctions(vp) # type: ignore vf = ctx.versionFunctions(vp) # type: ignore
except ImportError as e: except ImportError:
return None return None
if vf is None: if vf is None:

View file

@ -980,7 +980,6 @@ def _create_ankiwebview_subclass(
/, /,
**fixed_kwargs: Unpack[_AnkiWebViewKwargs], **fixed_kwargs: Unpack[_AnkiWebViewKwargs],
) -> Type[AnkiWebView]: ) -> Type[AnkiWebView]:
def __init__(self, *args: Any, **kwargs: _AnkiWebViewKwargs) -> None: def __init__(self, *args: Any, **kwargs: _AnkiWebViewKwargs) -> None:
# usersupplied kwargs override fixed kwargs # usersupplied kwargs override fixed kwargs
merged = cast(_AnkiWebViewKwargs, {**fixed_kwargs, **kwargs}) merged = cast(_AnkiWebViewKwargs, {**fixed_kwargs, **kwargs})

View file

@ -100,7 +100,7 @@ _SHGetFolderPath.restype = _err_unless_zero
def _get_path_buf(csidl): def _get_path_buf(csidl):
path_buf = ctypes.create_unicode_buffer(wintypes.MAX_PATH) path_buf = ctypes.create_unicode_buffer(wintypes.MAX_PATH)
result = _SHGetFolderPath(0, csidl, 0, 0, path_buf) _SHGetFolderPath(0, csidl, 0, 0, path_buf)
return path_buf.value return path_buf.value

View file

@ -15,7 +15,8 @@ camino.workspace = true
dirs.workspace = true dirs.workspace = true
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi.workspace = true windows.workspace = true
widestring.workspace = true
libc.workspace = true libc.workspace = true
libc-stdhandle.workspace = true libc-stdhandle.workspace = true

View file

@ -0,0 +1,135 @@
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
import contextlib
import os
import subprocess
import sys
from pathlib import Path
import aqt.sound
from anki.utils import pointVersion
from aqt import mw
from aqt.qt import QAction
from aqt.utils import askUser, is_mac, is_win, showInfo
def _anki_launcher_path() -> str | None:
return os.getenv("ANKI_LAUNCHER")
def have_launcher() -> bool:
return _anki_launcher_path() is not None
def update_and_restart() -> None:
from aqt import mw
launcher = _anki_launcher_path()
assert launcher
_trigger_launcher_run()
with contextlib.suppress(ResourceWarning):
env = os.environ.copy()
creationflags = 0
if sys.platform == "win32":
creationflags = (
subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS
)
subprocess.Popen(
[launcher],
start_new_session=True,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
env=env,
creationflags=creationflags,
)
mw.app.quit()
def _trigger_launcher_run() -> None:
"""Bump the mtime on pyproject.toml in the local data directory to trigger an update on next run."""
try:
# Get the local data directory equivalent to Rust's dirs::data_local_dir()
if is_win:
from aqt.winpaths import get_local_appdata
data_dir = Path(get_local_appdata())
elif is_mac:
data_dir = Path.home() / "Library" / "Application Support"
else: # Linux
data_dir = Path(
os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share")
)
pyproject_path = data_dir / "AnkiProgramFiles" / "pyproject.toml"
if pyproject_path.exists():
# Touch the file to update its mtime
pyproject_path.touch()
except Exception as e:
print(e)
def confirm_then_upgrade():
if not askUser("Change to a different Anki version?"):
return
update_and_restart()
# return modified command array that points to bundled command, and return
# required environment
def _packagedCmd(cmd: list[str]) -> tuple[Any, dict[str, str]]:
cmd = cmd[:]
env = os.environ.copy()
# keep LD_LIBRARY_PATH when in snap environment
if "LD_LIBRARY_PATH" in env and "SNAP" not in env:
del env["LD_LIBRARY_PATH"]
# Try to find binary in anki-audio package for Windows/Mac
if is_win or is_mac:
try:
import anki_audio
audio_pkg_path = Path(anki_audio.__file__).parent
if is_win:
packaged_path = audio_pkg_path / (cmd[0] + ".exe")
else: # is_mac
packaged_path = audio_pkg_path / cmd[0]
if packaged_path.exists():
cmd[0] = str(packaged_path)
return cmd, env
except ImportError:
# anki-audio not available, fall back to old behavior
pass
packaged_path = Path(sys.prefix) / cmd[0]
if packaged_path.exists():
cmd[0] = str(packaged_path)
return cmd, env
def setup():
if pointVersion() >= 250600:
return
if not have_launcher():
return
# Add action to tools menu
action = QAction("Upgrade/Downgrade", mw)
action.triggered.connect(confirm_then_upgrade)
mw.form.menuTools.addAction(action)
# Monkey-patch audio tools to use anki-audio
if is_win or is_mac:
aqt.sound._packagedCmd = _packagedCmd
setup()

View file

@ -0,0 +1,6 @@
{
"name": "Anki Launcher",
"package": "anki-launcher",
"min_point_version": 50,
"max_point_version": 250600
}

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