Compare commits

...

248 commits

Author SHA1 Message Date
Damien Elmes
04a0b10a15 Launcher now checks Windows version
https://forums.ankiweb.net/t/issue-with-installing-anki-launcher-into-custom-folder/66355
2025-09-23 19:50:40 +10:00
dependabot[bot]
99c67d39cb
Bump ammonia from 4.1.1 to 4.1.2 (#4355)
Bumps [ammonia](https://github.com/rust-ammonia/ammonia) from 4.1.1 to 4.1.2.
- [Release notes](https://github.com/rust-ammonia/ammonia/releases)
- [Changelog](https://github.com/rust-ammonia/ammonia/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-ammonia/ammonia/compare/v4.1.1...v4.1.2)

---
updated-dependencies:
- dependency-name: ammonia
  dependency-version: 4.1.2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-23 18:14:05 +10:00
Damien Elmes
0d31c6de4a Hard-code more mime types
If I had a dollar for all the weird and wonderful ways Windows systems
can be broken, I'd be a very rich man.

https://forums.ankiweb.net/t/the-gear-icon-in-the-anki-interface-is-not-displaying-properly/66274
2025-09-23 18:00:55 +10:00
Damien Elmes
fb332c4fe1 Add Yiddish to language list 2025-09-21 23:33:15 +10:00
Damien Elmes
48f774c711 Add Kazakh to language list 2025-09-21 22:45:11 +10:00
Damien Elmes
3890e12c9e Bump version
.1 release skipped due to missing bugfix
2025-09-17 16:50:13 +10:00
llama
80cff16250
fix: persist colour picker's custom palette in profile (#4326)
* add SaveCustomColours rpc method

* restore custom colour palette on editor init

* save custom colour palette on colour picker open and input

there doesn't seem to be an event fired when the picker is
cancelled/closed, so it's still possible for work to be lost

* save colours on `change` instead of `input`

`input` is supposed to be fired on every adjustment to the picker
whereas `change` is only fired when the picker is accepted, but qt
seems to treat both as the latter, so this is currently a no-op

* Store colors in the collection

One minor tweak to the logic while I was there: an invalid color no
longer invalidates all the rest.

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-09-17 16:46:53 +10:00
Abdo
75d9026be5
Decode images asynchronously (#4320) 2025-09-17 09:06:42 +03:00
Damien Elmes
6854d13b88 Bump version 2025-09-17 15:50:16 +10:00
Damien Elmes
29072654db Update translations 2025-09-17 15:50:02 +10:00
jcznk
ec6f09958a
(UI polish) Improved margins in Card Browser's "Previewer" (#4337)
* Improved margins in Card Browser's "Preview" pane

* Alternate approach that looks good on Mac too

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2025-09-17 15:30:22 +10:00
snowtimeglass
c2957746f4
Make timebox message translatable with flexible variable order (#4338)
* Make timebox message translatable with flexible variable order

Currently, the timebox dialog message is built from two separate strings,
each containing one variable:
"{ $count } cards studied in" + "{ $count } minutes."

As a result, translators cannot freely reorder the variables in their translations.

This change introduces a single string with both variables, allowing translators
to adjust the order for more natural expressions in their languages.

* Preserve old string for now

* Ensure message doesn't display over two lines

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-09-17 15:13:59 +10:00
Luc Mcgrady
9e415869b8
Fix/Add lower review limit to health check. (#4334) 2025-09-17 14:04:27 +10:00
Emil Hamrin
7e8a1076c1
Updated Dockerfile to use Ninja build system (#4321)
* Updated Dockerfile to support ninja build

* Install python using uv

* Bumped python version

* Add disclaimer (dae)
2025-09-17 14:02:09 +10:00
dependabot[bot]
b97fb45e06
Bump vite from 6.3.5 to 6.3.6 (#4328)
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 6.3.5 to 6.3.6.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v6.3.6/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v6.3.6/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-version: 6.3.6
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-17 12:08:11 +10:00
Damien Elmes
61094d387a Update translations 2025-09-17 09:31:47 +10:00
Damien Elmes
90ed4cc115 Disable NPM package scripts, and assert lockfile unchanged
With all the recent supply chain attacks, this seems prudent. There are
three in our current package list. esbuild's is just a performance
optimization (https://github.com/evanw/esbuild/issues/4085), and
dprint's gets done when we invoke .bin/dprint anyway. svelte-preprocess
simply prints something to the screen.
2025-09-17 09:31:23 +10:00
jcznk
4506ad0c97
Prevent clipping for QPushButton:default (#4323) 2025-09-14 20:44:16 +03:00
Damien Elmes
539054c34d Bump version 2025-09-06 21:17:08 +10:00
Damien Elmes
cf12c201d8 Update translations 2025-09-06 21:16:13 +10:00
Lukas Sommer
3b0297d14d
Update deck-config.ftl (#4319) 2025-09-06 21:15:42 +10:00
Damien Elmes
58deb14028 Ensure the newly-spawned terminal doesn't inherit the env var
It seems like the open call was leaking it into the newly spawned
process.

Follow-up fix to 2491eb0316
2025-09-04 16:18:11 +10:00
Damien Elmes
5c4d2e87a1 Bump version 2025-09-04 14:39:29 +10:00
Damien Elmes
6d31776c25 Update translations 2025-09-04 14:38:45 +10:00
Luc Mcgrady
dda730dfa2
Fix/Invalid memory states in simulator after parameters changed (#4317)
* Fix/Invalid memory states after optimization for simulator

* Update ts/routes/deck-options/FsrsOptions.svelte

* typo

* ./check
2025-09-04 14:35:00 +10:00
Damien Elmes
08431106da Exclude SSLKEYLOGFILE from Python
Closes #4308
2025-09-04 13:20:12 +10:00
Damien Elmes
b4b1c2013f Use the audio input device's preferred format
19f9afba64 broke recording for devices that
only support a single channel. Instead of hard-coding the values, we should
be using what the device prefers.

Apparently some devices may only support float formats, so conversion code
has been added to handle that case as well.

https://forums.ankiweb.net/t/cant-record-my-voice-after-upgrading-to-25-7-3/64453
2025-09-04 12:55:36 +10:00
maxr777
5280cb2f1c
Enable nc: to only search in a specific field (#4276) (#4312)
* Enable nc: to only search in a specific field

* Add FieldSearchMode enum to replace boolean fields

* Avoid magic numbers in enum

* Use standard naming so Prost can remove redundant text

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-09-04 11:52:08 +10:00
Damien Elmes
b2ab0c0830 Add an experimental new system Qt mode to the launcher
Goal is to allow users to use their system Qt libraries that have
things like fcitx support available.

For #4313
2025-09-03 23:54:27 +10:00
Damien Elmes
6a985c9fb0 Add support for custom launcher venv locations
Closes #4305 when https://github.com/ankitects/anki-manual/pull/444 is
merged, and makes it easier to maintain multiple Anki versions at once.
2025-09-03 20:54:16 +10:00
Damien Elmes
db1d04f622 Centralize uv command setup
Closes #4306
2025-09-03 19:58:45 +10:00
Damien Elmes
2491eb0316 Don't reuse existing terminal process
May possibly help with #4304
2025-09-03 17:32:30 +10:00
Damien Elmes
06f9d41a96 Bypass install_name_tool invocation on macOS
Not sure when https://github.com/astral-sh/uv/issues/14893 will be
ready, and this seems to solve the problem for now.

Closes #4227
2025-09-03 17:32:30 +10:00
llama
8d5c385c76
use existing translation instead of adding new one (#4310) (#4316)
Co-authored-by: Abdo <abdo@abdnh.net>
2025-09-02 23:54:17 +03:00
llama
153b972dfd
Show the number of cards added when adding (#4310)
* modify `generate_cards_for_note` to return count

* modify `add_note` to return count

* show the number of cards added when adding
2025-09-02 18:06:49 +10:00
Jarrett Ye
4ac80061ca
Add desired_retention field to NormalDeckSchema11 (#4292)
* Add desired_retention field to NormalDeckSchema11

* pass ci
2025-09-02 17:55:23 +10:00
Damien Elmes
01b825f7c6 Fix theme/checkboxes when path contains an apostrophe
I couldn't find a list of other characters we might need to handle too.
I tested with ", but Qt failed to start then.

https://forums.ankiweb.net/t/qt-rendering-bug-in-check-boxes/66196
2025-09-02 15:55:37 +10:00
洩氏诹诹子
157da4c7a7
Fix mirror configuration not working during launcher download (#4280)
Use environment variable instead of configuration file
2025-09-02 14:58:34 +10:00
Damien Elmes
8ef208e418 Fix importing of Mnemosyne collections with missing cards
There's no associated scheduling data, but we can at least preserve
the note.

https://forums.ankiweb.net/t/error-importing-mnemosyne-2-9-deck/65592
2025-09-01 18:25:34 +10:00
Lee Doughty
65ea013270
Update microphone icon to respect dark mode (#4297) 2025-09-01 17:56:48 +10:00
Damien Elmes
ef1a1deb9c Update translations 2025-09-01 15:13:40 +10:00
GithubAnon0000
c93e11f343
FIX gap above bury (#4298) 2025-09-01 15:09:42 +10:00
€šm̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰̰�Ř§Ů Â£╟©舐æØ¢£ðsÞ¥¿—
e3d0a30443
Fix ninja BuildAction name sanitization (#4291)
rust commit 8296ad0 changes the output of std::any::type_name to include
regions such as lifetime and generic arguments, which results in invalid
Ninja rule names being generated, such as `CargoBuild<_>`.
2025-09-01 15:08:29 +10:00
Jarrett Ye
4fdb4983dd
Fix/recompute memory state when deck-specific DR is changed (#4293) 2025-09-01 15:07:35 +10:00
Luc Mcgrady
3521da3ad6
Chore/Remove CMRR from fsrs help modal (#4290)
* Remove cmrr from fsrs help sections

* move other strings
2025-09-01 14:58:20 +10:00
Damien Elmes
ca60911e19 Update to Rust 1.89 + latest deps 2025-09-01 14:55:49 +10:00
Damien Elmes
71ec878780 Fixes for Rust 1.89
Closes #4287
2025-09-01 14:55:49 +10:00
user1823
6dd9daf074
Increase randomness in random sorting of new cards (#4286)
* Increase randomness in random sorting of new cards

Currently, the new cards appear roughly in the same order on consecutive days (if they are skipped by burying). This change aims to increase randomness by spreading out the salt across the hash space.

* Fix errors
2025-09-01 14:22:27 +10:00
user1823
3b33d20849
Fix LRT database check for cards with no usable reviews (#4284)
Fixes https://forums.ankiweb.net/t/anki-25-08-beta-3/64738/62
2025-09-01 14:19:36 +10:00
Luc Mcgrady
542c557404
Fix/Workload deck_size unset (#4283) 2025-09-01 14:18:30 +10:00
Luc Mcgrady
211cbfe660
Fix/Simulator intervals decending overflows (#4275)
* Fix/Simulator intervals decending overflows

* saturating_sub

* oops
2025-09-01 14:16:40 +10:00
Damien Elmes
359231a4d8 Update licenses after tracing-subscriber bump 2025-09-01 13:42:10 +10:00
Damien Elmes
d23764b59e Bump devalue for latest CVE 2025-09-01 13:41:00 +10:00
Damien Elmes
1dc31bb360 One step closer to tools/run-qt* on Windows
Doing the rest manually for now
2025-09-01 13:39:46 +10:00
dependabot[bot]
6fa33777db
Bump tracing-subscriber from 0.3.19 to 0.3.20 (#4296)
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.3.19 to 0.3.20.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.3.19...tracing-subscriber-0.3.20)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-version: 0.3.20
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-09-01 13:35:46 +10:00
Lee Doughty
2fee6f959b
Replace deprecated $app/stores with $app/state in SvelteKit frontend (#4282)
* Migrate frontend from /stores to /state

* Update CONTRIBUTORS
2025-08-26 21:28:49 +03:00
Expertium
3d0a408a2b
A small clarification in deck-config.ftl (#4264)
* A small clarification in deck-config.ftl

* Tweak wording (dae)

https://github.com/ankitects/anki/pull/4264#issuecomment-3188208351
2025-08-22 20:23:29 +10:00
user1823
3e846c8756
Make simulator fill missing values of DR and decay too (#4269)
* Make simulator fill missing values of DR and decay too

If a card has missing memory states, it will likely have missing DR and decay too. So, it makes sense to simultaneously update them as well.

* Fix error

* Avoid causing sync conflicts when filling in missing memory in sim

https://github.com/ankitects/anki/pull/4269#issuecomment-3201450124

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-08-20 03:03:53 +10:00
Abdo
79932aad41
Fix sync errors not being reported in some cases (#4281)
* Set parent of sync error dialog

* Explicitly mention parent arg in show_info() functions
2025-08-20 03:02:51 +10:00
Luc Mcgrady
2879dc63c3
Fix/Learn count not included in workload graph (#4274)
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2025-08-20 02:58:25 +10:00
Abdo
b92eabf4ae
Replace activeWindow() with activeModalWidget() (#4267) 2025-08-20 02:32:54 +10:00
Abdo
1660a22548
Fix Mnemosyne fact ID in error messages (#4266) 2025-08-20 02:32:03 +10:00
Siyuan Yan
a3b3b0850d
Hi res microhpone icon for the recording dialog (#4262)
* Replace media-record.png with SVG icon

- Added SVG version of the microphone icon (from Font Awesome Free v7.0.0)
- Updated sound.py to use QIcon for proper SVG support
- Icon now displays at 60x60 pixels

* Remove obsolete media-record.png icon

The PNG icon has been replaced with an SVG version

* Update CONTRIBUTORS

* Replace icon with AnkiMobile's record icon

CC-BY requires attribution, and we don't currently have a way to describe
those attributions in a way the mobile clients can also include automatically.
For now, I've switched it to an icon I authored myself to avoid the issue.

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2025-08-20 02:31:31 +10:00
Luc Mcgrady
562cef1f22
Fix #4253 (#4259)
* Reapply "Fix/Retention help button bounds (#4253)" (#4258)

This reverts commit fb2e2bd37a.

* move div up slots instead of using condition

* Avoid tabbing

---------

Co-authored-by: Abdo <abdo@abdnh.net>
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2025-08-20 01:19:25 +10:00
Damien Elmes
e676e1a484 Exclude version numbers from cargo/licenses.json
Version numbers are not required by the license, and keeping them in means
the build breaks after merging in a dependabot update.
2025-08-19 23:48:04 +10:00
Damien Elmes
37f7872565 Fix crash when disabling FSRS
https://forums.ankiweb.net/t/anki-25-08-beta-3/64738/51?u=dae
2025-08-19 23:34:09 +10:00
dependabot[bot]
5c07c899ec
Bump slab from 0.4.10 to 0.4.11 (#4265)
Bumps [slab](https://github.com/tokio-rs/slab) from 0.4.10 to 0.4.11.
- [Release notes](https://github.com/tokio-rs/slab/releases)
- [Changelog](https://github.com/tokio-rs/slab/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/slab/compare/v0.4.10...v0.4.11)

---
updated-dependencies:
- dependency-name: slab
  dependency-version: 0.4.11
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2025-08-19 19:59:48 +10:00
Damien Elmes
054740dd14 Skip licenses.json check for dependabot updates 2025-08-19 19:49:48 +10:00
Damien Elmes
78a3b3ef7b Expose control over AppNap for AnkiConnect
https://forums.ankiweb.net/t/recent-anki-updates-bundle-id-change-disabling-app-nap-macos-anki-connect/65550
2025-08-19 19:46:11 +10:00
Luc Mcgrady
f3b4284afb
Fix/System locale for simulator percentages (#4260)
Co-authored-by: Ross Brown <rbrownwsws@googlemail.com>
2025-08-11 06:44:11 +03:00
Damien Elmes
fb2e2bd37a
Revert "Fix/Retention help button bounds (#4253)" (#4258)
This reverts commit 5462d99255.
2025-08-09 16:46:25 +10:00
user1823
a0c1a398f4
Improve elapsed seconds calculation for learning cards in browser table (#4255)
* Improve calculation of elapsed seconds for learning cards in browser_table.rs

https://github.com/ankitects/anki/pull/4231/files#r2257105522

* Format
2025-08-09 16:16:36 +10:00
Damien Elmes
d4862e99da Bump version 2025-08-08 20:37:53 +10:00
Damien Elmes
34ed674869 Update translations 2025-08-08 20:31:05 +10:00
Damien Elmes
8c7cd80245 Support socks proxies when fetching versions 2025-08-08 20:30:51 +10:00
Damien Elmes
68bc4c02cf Add mirror option to launcher; stop downloading automatically
To give users a chance to choose a mirror first, we have to give up
the automatic downloading on first run.

Closes #4226
2025-08-08 20:30:51 +10:00
Luc Mcgrady
f4266f0142
Feat/Neaten dr graph x-axis (#4251)
* Remove "Plotted on x axis"

* Add: X tick format

* fix formatx

* Fix: Regular simualtor x axis
2025-08-08 20:30:10 +10:00
user1823
d3e8dc6dbf
Fix/Exclude new cards from is_due_in_days (#4249)
https://github.com/ankitects/anki/pull/4231/files#r2238901958
2025-08-08 20:28:13 +10:00
Luc Mcgrady
5462d99255
Fix/Retention help button bounds (#4253)
* Move onTitleClick

* rename variable

* Fix: Tabbing issues
2025-08-08 10:56:50 +03:00
Luc Mcgrady
2d60471f36
Use space-around for tabbed values (#4252)
* space-around

* have your cake and eat it
2025-08-07 06:36:53 +03:00
Jarrett Ye
62e01fe03a
Fix Cards with Missing Last Review Time During Database Check (#4237)
* Fix Cards with Missing Last Review Time During Database Check

* clippy

* Apply suggestions from code review

Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com>

* Apply suggestions from code review

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* Add is_reset method to RevlogEntry and update scheduling logic

This commit introduces the `is_reset` method to the `RevlogEntry` struct, which identifies entries representing reset operations. Additionally, the scheduling logic in `memory_state.rs` and `params.rs` has been updated to utilize this new method, ensuring that reset entries are handled correctly during review scheduling.

* Implement is_cramming method in RevlogEntry and update scheduling logic

This commit adds the `is_cramming` method to the `RevlogEntry` struct, which identifies entries representing cramming operations. The scheduling logic in `params.rs` has been updated to utilize this new method, improving the clarity and maintainability of the code.

* Refactor rating logic in RevlogEntry and update related scheduling functions

This commit introduces a new `has_rating` method in the `RevlogEntry` struct to encapsulate the logic for checking if an entry has a rating. The scheduling logic in `params.rs` and the calculation of normal answer counts in `card.rs` have been updated to use this new method, enhancing code clarity and maintainability.

* update revlog test helper function to assign button_chosen correctly

* Refactor card property fixing logic to use CardFixStats struct

* Add one-way sync trigger for last review time updates in dbcheck

* Update documentation for is_reset method in RevlogEntry to clarify ease_factor condition

* Apply suggestions from code review

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* Minor wording tweak

---------

Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com>
Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>
2025-08-06 19:49:30 +10:00
user1823
5c6e2188e2
Limit time studied today to minutes (#4242)
* Limit time studied today to minutes

* Update timespan.rs

* Update today.rs

* Update timespan.rs

* Update today.rs

* Update today.rs

* Update time.ts

* Update time.ts

* Update timespan.rs

* Update timespan.rs

* Update timespan.rs

* Update today.rs
2025-08-06 19:30:44 +10:00
llama
ab55440a05
Fix show_exception's messagebox always formatting as plaintext (#4246)
* fix show_exception's messagebox always formatting as plaintext

* Revert "fix show_exception's messagebox always formatting as plaintext"

This reverts commit aec6dd9be8.

* convert SearchError msg to markdown when in browser
2025-08-06 19:07:32 +10:00
llama
aae9f53e79
set min height for simulator graph (#4248) 2025-08-06 18:22:43 +10:00
Thomas Rixen
a77ffbf4a5
Statistics "Reviews" graph, make the color of "New" and "Learning" cards consistent with the color of card count (#4245)
* Statistics Reviews graph, make the color of New and Learning cards consistent with the color of card count

* removing bleu warning

* contributors
2025-08-06 18:07:10 +10:00
Luc Mcgrady
402008950c
Feat/expected_workload_with_existing_cards implementation (#4243)
* https://github.com/open-spaced-repetition/fsrs-rs/pull/355

* add is_included card

* bump version

* ./check

* update package.lock

* parallellify

* bump fsrs
2025-08-06 18:01:06 +10:00
Luc Mcgrady
f7e6e9cb0d
Feat/Card stats update review time (#4236)
* Feat/Card stats update review time

* Update rslib/src/stats/card.rs

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* fix

* self.storage.update_card

---------

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>
2025-08-06 17:55:50 +10:00
Jarrett Ye
2b55882cce
Fix/use real step count to simulate (#4240)
* Fix/use real step count to simulate

* Update licenses.json
2025-08-04 16:01:26 +10:00
Luc Mcgrady
0d0c42c6d9
"Workload" variable typo (#4239) 2025-08-04 16:00:27 +10:00
Luc Mcgrady
b76918a217
Feat/Show health check and already optimal at the same time (#4238) 2025-08-04 16:00:02 +10:00
user1823
f7974568c9
Update stale comment (#4235) 2025-08-04 15:31:22 +10:00
Damien Elmes
d13c117e80 Bump version 2025-07-28 21:54:44 +10:00
Damien Elmes
8932199513 Possible fix for launcher failing to appear on some Linux systems
While testing the previous PR, I noticed that if stdout is set to None,
the same behaviour is shown as in the following report:
https://forums.ankiweb.net/t/cannot-switch-versions/64565

This leads me to wonder whether IsTerminal is behaving differently
on that user's system, and the use of an env var may be more reliable.
2025-07-28 21:53:44 +10:00
Damien Elmes
69d54864a8 Fix launcher display on Tools>Upgrade/Downgrade on Windows 10
Thanks to abdo:
https://forums.ankiweb.net/t/anki-25-08-beta-3/64738/6
2025-07-28 21:43:11 +10:00
Damien Elmes
baeccfa3e4 Bump version 2025-07-28 19:19:04 +10:00
Damien Elmes
e99682a277 Update translations 2025-07-28 19:18:38 +10:00
Jarrett Ye
4dc00556c1
Fix/use current_retrievability_seconds in SQL to keep consistent with card info (#4231)
* Feat/use current_retrievability_seconds in SQL

* replace `days_since_last_review` with `seconds_since_last_review`

* Update is_due_in_days logic to include original or current due date check
2025-07-28 19:06:20 +10:00
llama
3dc6b6b3ca
Refactor IO fill tool target check logic (#4222)
* populate canvas.targets with subtargets during mouse events

* use canvas.targets instead of findTargetInGroup

* remove unused findTargetInGroup
2025-07-28 19:01:50 +10:00
Luc Mcgrady
c947690aeb
Feat/Use cached workload values (#4208)
* Feat/Use cached workload values

* Fix: Calculation when unchanged

* Modify constants

* Cache clearing logic

* Use function params

* use https://github.com/open-spaced-repetition/fsrs-rs/pull/352

* Revert "use https://github.com/open-spaced-repetition/fsrs-rs/pull/352"

This reverts commit 72efcf230c.

* Reapply "use https://github.com/open-spaced-repetition/fsrs-rs/pull/352"

This reverts commit 49eab2969f.

* ./check

* bump fsrs
2025-07-28 19:00:16 +10:00
Luc Mcgrady
1af3c58d40
Feat/Desired retention info graphs (#4199)
* backend part

* split memorised and cost

* slapdash frontend

* extract some simulator logic

* Add zoomed version of graph

* ./check

* Fix: Tooltip

* Fix: Simulator/workload transition

* remove "time"

* Update ts/routes/graphs/simulator.ts

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* Added: Mode toggle

* Disable Dr in workload mode

* keep button order consistant between modes

* dont clear points on mode swap

* add review count graph

* Revert "dont clear points on mode swap"

This reverts commit fc89efb1d9.

* "Help me pick" button

* unrelated title case change

* Add translation strings

* fix: missing translation string

* Fix: Layout shift

* Add: Experimental

* Fix Time / Memorized

* per day values

* set review limit to 9999 on open

* keep default at currently set value

* Do DR calculation in parallel (dae)

Approx 5x faster on my machine

---------

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>
Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-07-28 18:55:08 +10:00
Jarrett Ye
46bcf4efa6
Feat/per-deck desired retention (#4194)
* Feat/per-deck desired retention

* Refactor desired retention logic in Collection implementation

Updated the logic for retrieving deck-specific desired retention in both `memory_state.rs` and `mod.rs` to handle cases where the deck's normal state may not be available. This change ensures that the default configuration is used when necessary, improving the robustness of the retention handling.

* Refactor desired retention handling in FsrsOptions.svelte

Updated the logic for effective desired retention to use the configuration default instead of the deck-specific value. This change improves consistency in the retention value used throughout the component, ensuring that the correct value is bound to the UI elements.

* refactor the logic for obtaining deck-specific desired retention by using method chaining

* support deck-specific desired retention when rescheduling

* Refactor desired retention logic to use a dedicated method for improved clarity and maintainability.
2025-07-28 18:22:35 +10:00
Damien Elmes
60750f8e4c Update Uzbek language name
https://forums.ankiweb.net/t/uzbek-language-name/64725
2025-07-28 17:59:41 +10:00
Damien Elmes
661f78557f Fix sync server message failing to persist
It was disappearing immediately on macOS
2025-07-28 17:51:27 +10:00
Damien Elmes
7172b2d266 More launcher fixes
- The pyproject copy change broke the initial run case
- Avoid calling 'uv pip show' before venv created, as it causes
a pop-up prompting the user to install developer tools on macOS (#4227)
- Add a tip to the user about the unwanted install_name_tool pop-up
(Also tracked in #4227)
- Print 'Checking for updates...' prior to the potentially slow network
request
2025-07-25 23:34:50 +07:00
Damien Elmes
78c6db2023 Bump version 2025-07-25 19:12:06 +07:00
Damien Elmes
e2692b5ac9 Fix inability to upgrade/downgrade from a Python 3.9 version
Resolves AttributeError: module 'pip_system_certs.wrapt_requests' has no attribute 'inject_truststore'
2025-07-25 16:49:31 +07:00
Damien Elmes
177c483398 Stop copying updated pyproject/python pin on startup
The 'latest' and 'choose version' paths always read from the the
dist file these days, so the file doesn't need to be copied in advance.
The other reason for the current behaviour was so that when the user
manually installs a new launcher, it opens into the launcher on next
run, as that's probably what the user wanted. But this causes problems
when the launcher is updated automatically by things like homebrew.

https://forums.ankiweb.net/t/anki-homebrew-issues-terminal-and-crash-on-exit/64413/4
2025-07-25 15:40:00 +07:00
Damien Elmes
20b7bb66db Fix 'limits start from top' link 2025-07-25 14:45:04 +07:00
Damien Elmes
ca0459d8ee Use pip-system-certs when checking Anki versions 2025-07-24 21:56:15 +07:00
Damien Elmes
e511d63b7e Bump version to 25.07.4 2025-07-24 21:35:20 +07:00
Damien Elmes
d6e49f8ea5 Update translations 2025-07-24 21:35:05 +07:00
Damien Elmes
416e7af02b Pass --managed-python when fetching versions
Tentatively closes https://github.com/ankitects/anki/issues/4227
2025-07-24 21:32:23 +07:00
Damien Elmes
c74a97a5fa Increase default network timeout in launcher
https://forums.ankiweb.net/t/the-desktop-anki-app-cant-launch/64425/4
2025-07-24 20:34:43 +07:00
Damien Elmes
00bc0354c9 Provide better output when downloading versions fails
- include stdout/stderr when utf8_output() fails
- don't swallow the error returned by handle_Version_install_or_update
- skip codesigning when NODMG set

Closes #4224
2025-07-24 20:23:43 +07:00
llama
aee71afebe
set min size for card info dialog (#4221) 2025-07-24 18:55:47 +07:00
dependabot[bot]
ef69f424c1
Bump form-data from 4.0.1 to 4.0.4 (#4219)
Bumps [form-data](https://github.com/form-data/form-data) from 4.0.1 to 4.0.4.
- [Release notes](https://github.com/form-data/form-data/releases)
- [Changelog](https://github.com/form-data/form-data/blob/master/CHANGELOG.md)
- [Commits](https://github.com/form-data/form-data/compare/v4.0.1...v4.0.4)

---
updated-dependencies:
- dependency-name: form-data
  dependency-version: 4.0.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-24 18:51:12 +07:00
Damien Elmes
19f9afba64 Start requiring two channels for recording
Closes #4225
2025-07-24 18:49:29 +07:00
Damien Elmes
229337dbe0 Work around Conda breaking launcher
Closes #4216
2025-07-24 18:40:41 +07:00
llama
1f3d03f7f8
add io mask rotation snapping (#4214) 2025-07-22 14:32:42 +03:00
user1823
47c1094195
Add last_review_time to _to_backend_card (#4218)
Presumably, without this change, add-ons would delete the value of last_review_time from the card when they modify the card.
2025-07-22 14:26:44 +03:00
llama
35a889e1ed
Prioritise prefix matches in tag autocomplete results (#4212)
* prioritise prefix matches in tag autocomplete results

* update/add tests

* fix lint

was fine locally though?
2025-07-22 14:11:33 +03:00
Damien Elmes
65b5aefd07 Bump version to 25.07.3 2025-07-21 15:00:46 +07:00
Damien Elmes
8c72b03f4c Bump version
Preparing for another 25.07.x release
2025-07-19 00:56:16 +07:00
Damien Elmes
fc845a11a9 Update translations 2025-07-19 00:56:16 +07:00
Damien Elmes
aeaf001df7 Hack back in a fix for lack of ANSI codes on Windows 10
There must be a better way to do this, but someone more familiar
with Win32 internals than I will need to discover it.

https://forums.ankiweb.net/t/anki-25-08-beta/63645/61
2025-07-19 00:40:16 +07:00
Damien Elmes
a3da224511 Possible fix for error getting current version in launcher
https://forums.ankiweb.net/t/anki-25-08-beta/63645/68
2025-07-19 00:40:16 +07:00
Abdo
63ddd0e183
Fix wrong tab order in preferences (#4210) 2025-07-18 22:20:10 +07:00
Damien Elmes
278a84f8d2 Fix 'same cloze' shortcut on macOS
https://forums.ankiweb.net/t/mac-shortcut-for-cloze-deletion-same-card/63785
2025-07-18 18:12:30 +07:00
Danika-Dakika
0b30155c90
Adding to about.py (#4211)
Adding a Hebrew translator.
2025-07-18 04:05:01 +03:00
Damien Elmes
37fe704326 Tweak protobuf requirements
Motivated by https://forums.ankiweb.net/t/python-anki-sync-server-broken/64069

From https://protobuf.dev/support/cross-version-runtime-guarantee/:
"Python-specific Guarantees
Since the 3.20.0 release, the Protobuf Python generated code became a thin wrapper around an embedded FileDescriptorProto. Because these protos are supported on extremely long timeframes, our usual major version compatibility windows aren’t typically necessary.

Python may break generated code compatibility in specific future major version releases, but it will be coupled with poison pill warnings and errors in advance. As of 6.32.0, all generated code since 3.20.0 will be supported until at least 8.x.y."
2025-07-16 14:15:25 +07:00
Damien Elmes
e77cd791de Bump version 2025-07-15 22:26:46 +07:00
Damien Elmes
4e29440d6a Version the launcher 2025-07-15 22:26:46 +07:00
Damien Elmes
cc4b0a825e Update translations 2025-07-15 20:45:38 +07:00
Damien Elmes
15bbcdd568 Downgrade Chromium as potential rendering fix
https://forums.ankiweb.net/t/anki-25-08-beta/63645/57
2025-07-15 18:26:02 +07:00
Damien Elmes
12635f4cd2 Show Chromium version in About instead of PyQt version 2025-07-15 18:25:11 +07:00
Damien Elmes
834fb41015 Exclude VIRTUAL_ENV from environ as well
https://forums.ankiweb.net/t/anki-25-08-beta/63645/51
2025-07-15 17:03:51 +07:00
user1823
5a19027185
Minor tweak in simulator string (#4204) 2025-07-15 16:59:06 +07:00
llama
0375b4aac0
fix default-coloured io masks not following css var (#4202) 2025-07-14 01:22:14 +03:00
sorata
a1934ae9e4
update preferences.ftl (#4196) 2025-07-13 22:35:21 +03:00
Bradley Szoke
58a8aa7353
fix: set cursor to pointer when on range (#4197)
* set cursor to pointer when on range

* chore: white space removal

* chore: update contributors file
2025-07-13 22:29:23 +03:00
jcznk
4604bc7567
Add margin to QPushButton to prevent clipping (#4201)
* Update CONTRIBUTORS

* Add margin to QPushButton to prevent clipping
2025-07-13 22:21:31 +03:00
Damien Elmes
3b18097550 Support user pyproject modifications again
This changes 'keep existing version' to 'sync project changes'
when changes to the pyproject.toml file have been detected that
are newer than the installer's version.

Also adds a way to temporarily enable the launcher, as we needed some
other trigger than the pyproject.toml file anyway, and this approach
also solves #4165.

And removes the 'quit' option, since it's an uncommon operation, and
the user can just close the window instead.

Short-term caveat: users with older launchers/addon will trigger the old
pyproject.toml mtime bump, leading to a 'sync project changes' message
that will not make much sense to a typical user.
2025-07-13 00:58:13 +07:00
GithubAnon0000
c56fd3ee28
FIX Graph Tooltip uses wrong font (#4193) 2025-07-12 13:41:22 +07:00
Damien Elmes
f4e587256c Retention rate -> retention
https://forums.ankiweb.net/t/rename-true-retention-retention-rate/63446/5

Closes #4190
2025-07-12 13:38:16 +07:00
Damien Elmes
51cf09daf3 Strip only UV_* env vars
If we don't preserve env vars like TEMP, it results in run failures
on Windows:
https://forums.ankiweb.net/t/anki-25-08-beta/63645/28
2025-07-09 21:38:45 +07:00
Kevin Nakamura
dfbb7302e8
set UV_PYTHON_DOWNLOADS=auto when doing uv sync (#4191)
* set UV_PYTHON_DOWNLOADS=auto when doing `uv sync`

* Clear env vars prior to invoking uv, and add --no-config

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-07-09 17:57:37 +07:00
Jarrett Ye
1f7f7bc8a3
Fix/FSRS simulator fallback to memory_state_from_sm2 when converting cards (#4189)
* Fix/FSRS simulator fallback to memory_state_from_sm2 for after setting “Ignore cards reviewed before”

* add comment to fsrs_item_for_memory_state

* Add historical retention field to FSRS review request and update related logic

- Added `historical_retention` field to `SimulateFsrsReviewRequest` in `scheduler.proto`.
- Updated `simulator.rs` to use `req.historical_retention` instead of the removed `desired_retention`.
- Modified `FsrsOptions.svelte` to include `historicalRetention` in the options passed to the component.

* Update rslib/src/scheduler/fsrs/memory_state.rs

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* Update rslib/src/scheduler/fsrs/simulator.rs

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* pass ci

* Update rslib/src/scheduler/fsrs/simulator.rs

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>

* format

* Update rslib/src/scheduler/fsrs/simulator.rs

Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com>

* format

* Fix condition in is_included_card function to check CardType instead of CardQueue

---------

Co-authored-by: user1823 <92206575+user1823@users.noreply.github.com>
Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com>
2025-07-09 16:22:59 +07:00
Jarrett Ye
208729fa3e
Skip unnecessary computations when the load balancer is disabled (#4184)
* Only get_deck_config when load balancer is enabled

* Refactor load balancer card addition logic to use pre-fetched deckconfig_id

* Refactor get_scheduling_states to use context for deck configuration
2025-07-08 16:29:36 +07:00
Kevin Nakamura
6744a0a31a
Re-order terminals, again, for better UX. (#4186)
* Re-order terminals, again, for better UX.

* Move x-terminal-emulator up (dae)
2025-07-08 16:29:07 +07:00
Damien Elmes
1ad82ea8b5 Avoid UV_PRERELEASE=allow
It had some downsides:
- the lockfile was discarded when switching between beta/non-beta
- it could result in beta versions of transitory dependencies

By adding 'anki' and 'aqt' as first-party packages with explicit
version numbers (validated by the version list we get from PyPi),
we can allow them to be installed without breaking other deps.

https://forums.ankiweb.net/t/bundling-numpy-in-an-add-on/62669/15
2025-07-08 15:32:54 +07:00
Damien Elmes
1098d9ac2a enter -> Enter 2025-07-08 12:51:08 +07:00
Damien Elmes
778ab76586 Work around gnome-terminal failing to appear 2025-07-08 12:51:07 +07:00
Damien Elmes
c57b7c496d Bump version 2025-07-08 01:15:30 +07:00
Damien Elmes
fabed12f4b Update to Qt 6.9.1 2025-07-08 01:14:40 +07:00
Damien Elmes
84658e9cec Rename tarball folder to match tarball name 2025-07-08 01:11:55 +07:00
llama
11c3e60615
Debounce mathjax rendering via cooldown instead (#4173)
* add cooldown timer

* debounce mathjax rendering via cooldown instead
2025-07-08 00:56:13 +07:00
GithubAnon0000
3d9fbfd97f
Use system font for webviews instead of bootstrap font stack and add exception for note editor (#4163)
* Revert "Revert "Use system font for webviews instead of bootstrap font stack …"

This reverts commit d1793550b0.

* Update editor-base.scss
2025-07-08 00:51:44 +07:00
llama
80ff9a120c
Allow creating deck via #deck:... if non-existent when importing (#4154)
* add deck name field to metadata protobuf msg

* fallback to creating new deck specified in `#deck:...`

* update tests

* create deck if it doesn't exist

* plumbing

* allow creating deck via `#deck:...`

* apply suggestion for protobuf
2025-07-08 00:46:04 +07:00
Jarrett Ye
037dfa1bc1
Add last_review_time to card data for performance and accuracy (#4124)
* Add `last_review_time` to card data

* cargo clippy

* Calculate days elapsed since last review time in add_extract_fsrs_relative_retrievability

* expose last_review_time to Card in Python

* Fix last_review_time assignment in Card class to use last_review_time_secs

* format

* Update last_review_time assignment to exclude filtered preview state in Card class
2025-07-08 00:41:01 +07:00
Damien Elmes
3adcf05ca6 Bump version to 25.07.2 2025-07-07 23:49:54 +07:00
Damien Elmes
3bd725b6be Add Uzbek to the list of available languages 2025-07-07 23:49:37 +07:00
Damien Elmes
0009e798e1 Update translations 2025-07-07 23:47:02 +07:00
Damien Elmes
436a1d78bc On first run, automatically download the latest version 2025-07-07 23:46:33 +07:00
Damien Elmes
2e74101ca4 Show recent versions in launcher
Did it with Python to avoid bloating the launcher binary with
network code
2025-07-07 23:46:33 +07:00
Lucio Sauer
7fe201d6bd
aqt wheel: fix unintended inclusion of qt/aqt/data (#4180)
The inclusion of files under qt/aqt is handled by qt/pyproject.toml,
not qt/hatch_build.py, which works with the files under out/qt/_aqt.

Excluding qt/aqt/data and all files ending in .ui in qt/pyproject.toml
fixes the issue, since the other unwanted files (**/*.scss, **/*.ts, and
**/tsconfig*) all reside under qt/aqt/data.

Fixes: 04996c77f3
2025-07-07 23:44:08 +07:00
Luc Mcgrady
8a3b72e6e5
Fix/Help modal appears behind simulator modal (#4171)
* Fix/Help modal appears behind simulator modal

* Correct help modal keys (Doesn't work)
2025-07-07 16:21:46 +07:00
Luc Mcgrady
d3e1fd1f80
Feat/Replace easy day table with display:grid (#4179)
* Feat/Replace easy day table with grid

* Add max width
2025-07-07 15:46:52 +07:00
Kevin Nakamura
3d6b4761e4
Try unix terminals in roughly most specific to least specific. (#4177) 2025-07-07 15:44:39 +07:00
GithubAnon0000
1ca31413f7
FIX revert button is visible for screenreaders (#4174) 2025-07-07 15:23:39 +07:00
Alexander Bocken
b205008a5e
respect env var UV_BINARY with OFFLINE_BUILD being set (#4170)
* respect env var UV_BINARY with OFFLINE_BUILD being set

* cleanup formatting, fix import

* Fix build error (dae)
2025-07-07 15:16:00 +07:00
Luc Mcgrady
b16439fc9c
Feat/Confirmation box for save options to preset (#4172) 2025-07-07 15:10:24 +07:00
Kevin Nakamura
f927aa5788
Statically link MSVC runtime, removing the need to install the redistributable (#4166)
* Statically link MSVC runtime, removing the need to install the redistributable.

* CONTRIBUTORS I've already contributed and added my email, but the last commit got mangled.
2025-07-05 15:03:14 +03:00
Damien Elmes
a83a6b5928 Update translations 2025-07-05 01:39:33 +07:00
sorata
052b9231ec
rename: true retention > retention rate (#4164) 2025-07-05 01:39:12 +07:00
Damien Elmes
1b51c16e26 Bump version to 25.07.1 2025-07-05 01:37:43 +07:00
Damien Elmes
de2d1477de Hack in a message about the launcher add-on
We can't show an AnkiWeb page for a locally-installed add-on, and
having a custom config action is the only way we can easily expose
this for older clients as well.

Re: #4158
2025-07-05 01:37:42 +07:00
Damien Elmes
ccc0c7cdbb Add --managed-python to uv python install invocation
https://github.com/ankitects/anki/pull/4162#issuecomment-3036984410
2025-07-05 01:36:39 +07:00
Damien Elmes
deaf25f757 Add an ankiw script to make running on Windows easier 2025-07-05 01:36:35 +07:00
Damien Elmes
93dbd6e4cf Update translations
(cherry picked from commit 09495d3a8b,
as #4162 accidentally reverted them)
2025-07-04 23:57:32 +07:00
Damien Elmes
7b0289b5d3 Use a (soon-to-be) real version number in example
Closes #4160
2025-07-04 23:53:44 +07:00
GithubAnon0000
08a8b6691c
ADD a Contributor to about.py (#4161)
* ADD a Contributor to CONTRIBUTORS

As requested in https://forums.ankiweb.net/t/anki-contributors-list/63493

* RM contrib from CONTRIBUTORS

* Add contrib to about.py
2025-07-04 23:47:56 +07:00
Kevin Nakamura
fc6447a938
Launcher: Run uv python install before running uv sync (#4162)
* Launcher: Run `uv python install` before running `uv sync`

* Less copy/paste.

* Minor readability improvements

* Make sure we check file presence before attempting to read

---------

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2025-07-04 23:35:50 +07:00
Damien Elmes
d1793550b0
Revert "Use system font for webviews instead of bootstrap font stack (#4147)" (#4159)
This reverts commit 0b5218706a.
2025-07-04 21:22:30 +07:00
Damien Elmes
cedece5cae Fix glibc version check in Linux installer
I'd changed it for testing, and accidentally committed it.
2025-07-04 17:20:05 +07:00
Damien Elmes
2594dcb2bb Bump version to 25.07
I'd normally do an RC before a stable release, but this is going to
be a "soft release", and with beta updates off by default in the launcher,
jumping straight to a stable release avoids the initial install problems.
2025-07-04 15:49:17 +07:00
Damien Elmes
09495d3a8b Update translations 2025-07-04 15:47:06 +07:00
Luc Mcgrady
f5285f359a
Feat/Add legacy evaluate config bool (#4149)
* Feat/Add legacy evaluate config bool

* Minor tweaks based on PR suggestions (dae)

New enabling command:

from anki.config import Config
mw.col.set_config_bool(Config.Bool.FSRS_LEGACY_EVALUATE, True)
2025-07-04 15:32:09 +07:00
llama
fba1d7b4b0
reuse blank deck created while importing if deck column is empty (#4150) 2025-07-04 14:48:35 +07:00
Luc Mcgrady
4232185735
Feat/Add globe to help tooltip (#4148)
* Add global option to HelpItem

* Fix: Spacing

* add to more sections

* Fix: Spacing again
2025-07-04 14:42:40 +07:00
GithubAnon0000
0b5218706a
Use system font for webviews instead of bootstrap font stack (#4147) 2025-07-04 14:41:58 +07:00
Damien Elmes
bb1b289690 Add some helpers to allow add-ons to install packages into the venv
While something we probably don't want to encourage much of, this
may enable some previously-unshared add-ons.

https://forums.ankiweb.net/t/bundling-numpy-in-an-add-on/62669/5

The 'uv add' command is transaction, so if an add-on tries to inject
incompatible dependencies into the environment, the venv will be
left as-is. And each Anki upgrade/downgrade resets the requirements,
so the requested packages shouldn't cause errors down the line.

Sample add-on:

import subprocess
from aqt import mw
from aqt.operations import QueryOp
from aqt.qt import QAction
from aqt.utils import showInfo

def ensure_spacy(col):
    print("trying to import spacy")
    try:
        import spacy
        print("successful import")
        return
    except Exception as e:
        print("error importing:", e)

    print("attempting add")
    try:
        from aqt.package import add_python_requirements as add
    except Exception as e:
        raise Exception(f"package unavailable, can't install: {e}")
    # be explicit about version, or Anki beta users will get
    # a beta wheel that may break
    (success, output) = add(["spacy==3.8.7", "https://github.com/explosion/spacy-models/releases/download/ko_core_news_sm-3.8.0/ko_core_news_sm-3.8.0-py3-none-any.whl"])
    if not success:
        raise Exception(f"adding failed: {output}")

    print("success")

    # alterantively:
    # from aqt.package import venv_binary
    # subprocess.run([venv_binary("spacy"), "download", "ko_core_news_sm"], check=True)
    # print("model added")

    # large packages will freeze for a while on first import on macOS
    import spacy
    print("spacy import successful")

def activate_spacy():
    def on_success(res):
        mw.progress.single_shot(1000, lambda: showInfo("Spacy installed"))

    QueryOp(parent=mw, op=ensure_spacy, success=on_success).with_progress("Installing spacy...").run_in_background()

action = QAction("Activate Spacy", mw)
action.triggered.connect(activate_spacy)
mw.form.menuTools.addAction(action)
2025-07-04 14:23:04 +07:00
Damien Elmes
e81a7e8b1a Stop enabling betas by default 2025-07-02 12:57:02 +07:00
Damien Elmes
da90705346 Re-expose legacy RMSE calculations
Closes #4143
2025-07-01 18:22:55 +07:00
Damien Elmes
9e1690774c Update svelte/vite/esbuild for CWEs 2025-07-01 18:01:48 +07:00
Damien Elmes
ee5e8c9230 Update to latest node LTS; add update helper 2025-07-01 17:06:27 +07:00
llama
b6c70f7b75
Add search keyword to strip clozes beforehand (#4145)
* add strip_clozes fn

* add test

* replace without_combining with process_text

* update write_unqualified

* update write_regex

* add `sc:...` search option

* add test

* strip clozes before stripping combining characters

find_notes_sc           time:   [1.0398 s 1.0405 s 1.0412 s]
                        change: [-6.1276% -6.0323% -5.9401%] (p = 0.00 < 0.05)
                        Performance has improved.

* add bitflags crate

* add and use ProcessTextFlags

* update sqlwriter.rs to use bitflags
2025-07-01 16:35:21 +07:00
Lukas Sommer
944e453419
Comments for translators (#4137)
* Update deck-config.ftl

* Update ftl/core/deck-config.ftl

Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com>

---------

Co-authored-by: Luc Mcgrady <lucmcgrady@gmail.com>
2025-07-01 16:10:34 +07:00
llama
14eb297bbf
add "copy debug info" button to show_exception's dialog (#4146) 2025-07-01 15:35:50 +07:00
Damien Elmes
a07370f565 Add a trademark symbol to the readme and about screens 2025-07-01 11:40:03 +07:00
Damien Elmes
bf36e10519 Hide CMRR
https://forums.ankiweb.net/t/anki-25-06-beta/62271/156
2025-07-01 11:20:28 +07:00
Damien Elmes
b22b3310d6 Revert "Feat/Cmrr target selector (#4116)"
This reverts commit ad0dbb563a.

https://forums.ankiweb.net/t/anki-25-06-beta/62271/156
2025-07-01 11:20:20 +07:00
Matt Brubeck
7720c7de1a
Only run empty_filtered_deck on filtered decks. (#4139)
Fixes #4138.
2025-06-30 16:47:14 +07:00
Damien Elmes
0be87b887e Add category type
Unsure if this helps; the app is not even showing in the screen time
list for me at the moment.

https://forums.ankiweb.net/t/correct-apple-screen-time-category-macos-ios/62962
2025-06-30 14:28:37 +07:00
Damien Elmes
bce3cabf9b Friendlier error when glibc too old, and properly declare min macOS 2025-06-30 14:20:42 +07:00
Damien Elmes
ad34b76fa9 Do anki_release upload last 2025-06-29 22:30:20 +07:00
Damien Elmes
e0727b1bc8 Bump version 2025-06-29 22:17:01 +07:00
Damien Elmes
18cac8bbe5 Update translations 2025-06-29 22:17:01 +07:00
Damien Elmes
045e571edf Support hidden local Claude config 2025-06-29 22:16:59 +07:00
Damien Elmes
469fd763c7 Fix taskbar pinning on Windows
Closes #4107
2025-06-29 20:53:43 +07:00
Damien Elmes
6eb1db0f5d Switch to the windows crate 2025-06-29 16:49:20 +07:00
Damien Elmes
349a696f93 Fix transient console pop-ups on Windows 2025-06-29 16:46:45 +07:00
Damien Elmes
66f34da7ef Fix lint, and ensure Rust checks get re-run on launcher change 2025-06-29 15:54:31 +07:00
Damien Elmes
3d7dc32777 Add a 'revert to previous version' action + more
- Show current version
- Ensure uv builds switch to python 3.13
2025-06-29 15:51:15 +07:00
llama
58dfb9cdd3
fix deck options page being scrollable while simulator modal is open (#4133) 2025-06-29 14:42:52 +07:00
GithubAnon0000
185fdebb63
Followup to #4122 (make text selectable) (#4132) 2025-06-29 14:42:19 +07:00
Luc Mcgrady
0739ea58f8
Add disclaimer to workload tooltip (#4131) 2025-06-29 14:41:35 +07:00
Damien Elmes
5c23ac5a86
Revert "Fix/unapplied scss (#4103)" (#4136)
This reverts commit ae6cf98f40.
2025-06-29 14:40:56 +07:00
Abdo
f94d05bcbe
Switch to Ruff (#4119)
* Add check:ruff build action

* Add fix:ruff action

* Add Ruff config

Mostly generated by Cursor

* Handle rest of lints

* Fix formatting

* Replace black and isort with ruff-format

* Run ruff-format

* Fix lint errors

* Remove pylint disables

* Remove .pylintrc

* Update docs

* Fix check:format not just checking

* Fix isort rule being ignored

* Sort imports

* Ensure ./ninja format also handles import sorting

* Remove unused isort cfg

* Enable unsafe fixes in fix:ruff, and enable unused var warning

* Re-run on config change; enable unnecessary ARG ignores

* Use all pycodestyle errors, and add some more commented-out ones

Latter logged on https://github.com/ankitects/anki/issues/4135
2025-06-29 14:38:35 +07:00
Damien Elmes
b8963b463e Fix Windows CI and minor display tweak 2025-06-29 13:54:17 +07:00
Damien Elmes
bdb3c714dc Put Python install inside uv root as well 2025-06-29 13:42:15 +07:00
Damien Elmes
731e7d5b5c Add uninstall support to launcher 2025-06-29 13:32:06 +07:00
Damien Elmes
f89ab00236 Update to Rust 1.88
We'll need to handle https://github.com/ankitects/anki/issues/4134 before
we get access to let chains.
2025-06-29 11:50:49 +07:00
Damien Elmes
b872852afe Store uv cache inside AnkiProgramFiles, and allow disabling 2025-06-29 11:50:49 +07:00
Damien Elmes
aa8dfe1cf4 Fix icon/menu entries on macOS after update
We need to exec() Python from a GUI context so that the app name and
icon are inherited from our launcher bundle. And we need to munge
sys.argv[0] prior to main window instantiation so that we don't get
app menu entries like "Hide -c". We do that in the launcher instead
of __init__.py so that older versions display correctly too.
2025-06-29 11:50:49 +07:00
Damien Elmes
f5073b402a Inject Upgrade/Downgrade menu item and audio support into older versions 2025-06-29 11:50:49 +07:00
GithubAnon0000
a587343f29
FIX: Margin between icon was selectable but shouldn't be (#4122) 2025-06-28 21:47:29 +03:00
GithubAnon0000
cfeb71724d
CHANGE right-click in the editor to show option to open folder in linux (#4125)
* CHANGE right-click in the editor to show option to open folder in linux

* FIX checks

* Use heuristics

* ./ninja format

* Use fallback from main instead of xdg-open
2025-06-28 21:33:17 +03:00
Damien Elmes
aae970bed9 Bump version 2025-06-27 21:08:56 +07:00
Damien Elmes
63dcfde005 Update translations 2025-06-27 21:08:56 +07:00
Jarrett Ye
fe5dfe9ec2
Fix/update card.decay in card_state_updater (#4127) 2025-06-27 16:50:29 +07:00
David Allison
5f73725a64
Remove newline: 'Restore to default confirmation' (#4128) 2025-06-27 16:50:06 +07:00
Luc Mcgrady
ad0dbb563a
Feat/Cmrr target selector (#4116)
* backend

* Add: Frontend

* us

* Added: Loss aversion

* change proto format

* Added: Loss aversion

* Added: Future retention targets

* update default fail cost multiplier

* Future Retention -> Post Abandon Memorized

* superfluous as const

* Fix: Wrong default

* Fix: Wrong import order
2025-06-27 16:44:19 +07:00
Luc Mcgrady
e505ca032b
Fix/Add check_output_timestamps to PythonEnvironment (#4113)
* Fix/explicitly set restat

* Revert "Fix/explicitly set restat"

This reverts commit ace2e5ef6a.

* add check_output_timestamps to python.rs
2025-06-27 16:41:50 +07:00
Abdo
fdce765861
Make PYTHONPYCACHEPREFIX point to an absolute path (#4111) 2025-06-27 16:36:27 +07:00
Luc Mcgrady
ae6cf98f40
Fix/unapplied scss (#4103)
* deck options + change notetype

* graphs

* image occlusion

* congrats

* imports

* ./check

* style

* $lib

* delete unused index.ts files
2025-06-27 16:28:35 +07:00
Damien Elmes
bedab0a54b Drop psutil from wheel requirements
We're not using it ourselves, and usage appears isolated to a couple of
add-ons (notably ankirestart)
2025-06-27 16:10:12 +07:00
Damien Elmes
de7de82f76 Refactor launcher + various tweaks
- Launcher can now be accessed via Tools>Upgrade/Downgrade
- Anki closes automatically on update
- When launcher not available, show update link like in the past
- It appears that access to the modern console host requires an app
to be built with the windows console subsystem, so we introduce an
extra anki-console.exe binary to relaunch ourselves with. Solves
https://forums.ankiweb.net/t/new-online-installer-launcher/62745/50
- Windows now requires you to close the terminal like on a Mac,
as I couldn't figure out how to have it automatically close. Suggestions
welcome!
- Reduce the amount of duplicate/near-duplicate code in the various
platform files, and improve readability
- Add a helper to install the current code into the launcher env
- Fix cargo test failing to build on ARM64 Windows
2025-06-27 16:10:12 +07:00
Damien Elmes
73edf23954 Drop Pauker and SuperMemo importers from legacy importer
The legacy importer has only been kept around to support some add-ons,
and these are so infrequently used that they're better off shifted
to add-ons (even they even still work)
2025-06-27 16:10:12 +07:00
Damien Elmes
9b287dc51a Python dependency/wheel tweaks
- Use --locked to assert that the lockfile won't change, so we need
to explicitly 'uv lock' when making changes. Still trying to get to
the bottom of why the lockfile sometimes has editable entries, which
break things when switching between platforms.
- Exclude __pycache__ from wheels
- Move the typing stubs to our dev deps
(https://github.com/ankitects/anki/pull/4074#pullrequestreview-2948088436)
2025-06-27 16:10:12 +07:00
Damien Elmes
7edd9221ac Avoid Qt's automatic About labeling
It gets confused by our launcher process, and provides no way to
alter the default assigned text while keeping the About role on a Mac.
2025-06-27 16:10:12 +07:00
Luc Mcgrady
630bdd3189
Fix/Optimize button alignment (#4117)
* Fix/Button alignment

* add hr
2025-06-25 16:44:47 +03:00
Jarrett Ye
992fb054bd
Refactor FSRS data clearing into Card::clear_fsrs_data (#4123)
Extracted repeated logic for clearing FSRS-related fields into a new Card::clear_fsrs_data() method. Updated set_deck and FSRS disabling code paths to use this method for improved code reuse and maintainability.
2025-06-25 16:40:51 +03:00
llama
d6f93fab76
adjust top toolbar height on body class update (#4120) 2025-06-25 14:20:31 +03:00
llama
06195d1268
add bottom and right margins to account for focus outline (#4115) 2025-06-25 14:15:45 +03:00
llama
a73f1507ba
use KeyboardEvent.key instead of code (#4114) 2025-06-25 14:08:25 +03:00
Damien Elmes
b250a2f724 Add terminal support for *nix 2025-06-22 21:52:44 +07:00
Damien Elmes
d2f818fad2 macOS launcher improvements
- do mpv initial run in parallel
- improve messages, show dots regularly
2025-06-22 21:03:02 +07:00
Damien Elmes
eb6c977e08 Add menu to launcher, and improve terminal display on Windows 2025-06-22 20:25:15 +07:00
340 changed files with 9966 additions and 7848 deletions

View file

@ -10,3 +10,6 @@ PYTHONDONTWRITEBYTECODE = "1" # prevent junk files on Windows
[term]
color = "always"
[target.'cfg(all(target_env = "msvc", target_os = "windows"))']
rustflags = ["-C", "target-feature=+crt-static"]

2
.gitignore vendored
View file

@ -19,4 +19,4 @@ yarn-error.log
ts/.svelte-kit
.yarn
.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"
extend-exclude = []
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"]

View file

@ -1 +1 @@
25.06b5
25.09.2

View file

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

View file

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

View file

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

View file

@ -21,7 +21,7 @@ Please do this as a final step before marking a task as completed.
During development, you can build/check subsections of our code:
- Rust: 'cargo check'
- Python: './tools/dmypy'
- 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
@ -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 build scripts/tests is fine.
## Individual preferences
See @.claude/user.md

View file

@ -49,6 +49,7 @@ 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>
@ -63,6 +64,7 @@ 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>
@ -232,6 +234,16 @@ 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:

1124
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -33,9 +33,8 @@ git = "https://github.com/ankitects/linkcheck.git"
rev = "184b2ca50ed39ca43da13f0b830a463861adb9ca"
[workspace.dependencies.fsrs]
version = "4.1.1"
version = "5.1.0"
# git = "https://github.com/open-spaced-repetition/fsrs-rs.git"
# rev = "a7f7efc10f0a26b14ee348cc7402155685f2a24f"
# path = "../open-spaced-repetition/fsrs-rs"
[workspace.dependencies]
@ -52,7 +51,7 @@ ninja_gen = { "path" = "build/ninja_gen" }
unicase = "=2.6.0" # any changes could invalidate sqlite indexes
# normal
ammonia = "4.1.0"
ammonia = "4.1.2"
anyhow = "1.0.98"
async-compression = { version = "0.4.24", features = ["zstd", "tokio"] }
async-stream = "0.3.6"
@ -60,6 +59,7 @@ 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"
@ -109,6 +109,7 @@ 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"] }
@ -132,14 +133,15 @@ 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"] }
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", features = ["fmt", "env-filter"] }
tracing-subscriber = { version = "0.3.20", features = ["fmt", "env-filter"] }
unic-langid = { version = "0.9.6", features = ["macros"] }
unic-ucd-category = "0.9.0"
unicode-normalization = "0.1.24"
walkdir = "2.5.0"
which = "8.0.0"
winapi = { version = "0.3", features = ["wincon"] }
windows = { version = "0.61.3", features = ["Media_SpeechSynthesis", "Media_Core", "Foundation_Collections", "Storage_Streams"] }
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"
xz2 = "0.1.7"
zip = { version = "4.1.0", default-features = false, features = ["deflate", "time"] }

View file

@ -6,8 +6,6 @@ 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

@ -342,7 +342,12 @@ fn build_wheel(build: &mut Build) -> Result<()> {
name: "aqt",
version: anki_version(),
platform: None,
deps: inputs![":qt:aqt", glob!("qt/aqt/**"), "qt/pyproject.toml"],
deps: inputs![
":qt:aqt",
glob!("qt/aqt/**"),
"qt/pyproject.toml",
"qt/hatch_build.py"
],
},
)
}

View file

@ -68,7 +68,8 @@ pub fn build_pylib(build: &mut Build) -> Result<()> {
deps: inputs![
":pylib:anki",
glob!("pylib/anki/**"),
"pylib/pyproject.toml"
"pylib/pyproject.toml",
"pylib/hatch_build.py"
],
},
)?;

View file

@ -1,23 +1,18 @@
// 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::rsync::RsyncFiles;
use ninja_gen::python::RuffCheck;
use ninja_gen::Build;
/// Normalize version string by removing leading zeros from numeric parts
@ -51,7 +46,7 @@ fn normalize_version(version: &str) -> String {
part.to_string()
} else {
let normalized_prefix = numeric_prefix.parse::<u32>().unwrap_or(0).to_string();
format!("{}{}", normalized_prefix, rest)
format!("{normalized_prefix}{rest}")
}
}
})
@ -60,14 +55,7 @@ fn normalize_version(version: &str) -> String {
}
pub fn setup_venv(build: &mut Build) -> Result<()> {
let extra_binary_exports = &[
"mypy",
"black",
"isort",
"pylint",
"pytest",
"protoc-gen-mypy",
];
let extra_binary_exports = &["mypy", "ruff", "pytest", "protoc-gen-mypy"];
build.add_action(
"pyenv",
PythonEnvironment {
@ -135,7 +123,14 @@ impl BuildAction for BuildWheel {
}
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("", &self.deps);
// Set the project directory based on which package we're building
@ -200,60 +195,26 @@ pub fn check_python(build: &mut Build) -> Result<()> {
},
)?;
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
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"
];
build.add_action(
"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",
"check:ruff",
RuffCheck {
folders: ruff_folders,
deps: ruff_deps.clone(),
check_only: true,
},
)?;
build.add_action(
"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")
],
"fix:ruff",
RuffCheck {
folders: ruff_folders,
deps: ruff_deps,
check_only: false,
},
)?;
@ -266,15 +227,19 @@ struct Sphinx {
impl BuildAction for Sphinx {
fn command(&self) -> &str {
if env::var("OFFLINE_BUILD").is_err() {
"$uv sync --extra sphinx && $python python/sphinx/build.py"
} else {
if std::env::var("OFFLINE_BUILD").ok().as_deref() == Some("1") {
"$python python/sphinx/build.py"
} else {
"$uv sync --extra sphinx && $python python/sphinx/build.py"
}
}
fn files(&mut self, build: &mut impl FilesHandle) {
if env::var("OFFLINE_BUILD").is_err() {
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");

View file

@ -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/**,tools/workspace-hack/**}"),
glob!("{rslib/**,pylib/rsbridge/**,ftl/**,build/**,qt/launcher/**,tools/minilints/**}"),
"Cargo.lock",
"Cargo.toml",
"rust-toolchain.toml",

View file

@ -35,3 +35,7 @@ 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,6 +49,46 @@ pub trait BuildAction {
}
fn name(&self) -> &'static str {
std::any::type_name::<Self>().split("::").last().unwrap()
std::any::type_name::<Self>()
.split("::")
.last()
.unwrap()
.split('<')
.next()
.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

@ -67,7 +67,7 @@ impl Platform {
}
/// 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

@ -0,0 +1,268 @@
// 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

@ -72,12 +72,11 @@ fn fetch_protoc_release_info() -> Result<String, Box<dyn Error>> {
"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),
_ => &format!("Platform::{platform}"),
};
match_blocks.push(format!(
" {} => {{\n OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }}\n }}",
match_pattern, download_url, sha256
" {match_pattern} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}"
));
}

View file

@ -53,7 +53,7 @@ fn fetch_uv_release_info() -> Result<String, Box<dyn Error>> {
// Find the corresponding .sha256 or .sha256sum asset
let sha_asset = assets.iter().find(|a| {
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() {
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("");
match_blocks.push(format!(
" Platform::{} => {{\n OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }}\n }}",
platform, download_url, sha256
" Platform::{platform} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}"
));
}
@ -135,10 +134,7 @@ mod tests {
assert_eq!(
updated_lines,
original_lines - EXPECTED_LINES_REMOVED,
"Expected line count to decrease by exactly {} lines (original: {}, updated: {})",
EXPECTED_LINES_REMOVED,
original_lines,
updated_lines
"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

@ -19,28 +19,28 @@ use crate::input::BuildInput;
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: "822780369d0ea309e7d218e41debbd1a03f8cdf354ebf8a4420e89f39cc2e612",
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz",
sha256: "325c0f1261e0c61bcae369a1274028e9cfb7ab7949c05512c5b1e630f7e80e12",
},
Platform::LinuxArm => OnlineArchive {
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-linux-arm64.tar.xz",
sha256: "f6df68c6793244071f69023a9b43a0cf0b13d65cbe86d55925c28e4134d9aafb",
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-arm64.tar.xz",
sha256: "140aee84be6774f5fb3f404be72adbe8420b523f824de82daeb5ab218dab7b18",
},
Platform::MacX64 => OnlineArchive {
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-x64.tar.xz",
sha256: "d4b4ab81ebf1f7aab09714f834992f27270ad0079600da00c8110f8950ca6c5a",
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-darwin-x64.tar.xz",
sha256: "f79de1f64df4ac68493a344bb5ab7d289d0275271e87b543d1278392c9de778a",
},
Platform::MacArm => OnlineArchive {
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-darwin-arm64.tar.xz",
sha256: "f18a7438723d48417f5e9be211a2f3c0520ffbf8e02703469e5153137ca0f328",
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-darwin-arm64.tar.xz",
sha256: "cc9cc294eaf782dd93c8c51f460da610cc35753c6a9947411731524d16e97914",
},
Platform::WindowsX64 => OnlineArchive {
url: "https://nodejs.org/dist/v20.11.0/node-v20.11.0-win-x64.zip",
sha256: "893115cd92ad27bf178802f15247115e93c0ef0c753b93dca96439240d64feb5",
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/v20.11.0/node-v20.11.0-win-arm64.zip",
sha256: "89c1f7034dcd6ff5c17f2af61232a96162a1902f862078347dcf274a938b6142",
url: "https://nodejs.org/dist/v22.17.0/node-v22.17.0-win-arm64.zip",
sha256: "78355dc9ca117bb71d3f081e4b1b281855e2b134f3939bb0ca314f7567b0e621",
},
}
}
@ -98,7 +98,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

@ -148,7 +148,7 @@ impl BuildAction for PythonEnvironment {
// 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);
args = format!("--python {python_binary} {args}");
}
build.add_variable("extra_args", args);
}
@ -159,6 +159,10 @@ impl BuildAction for PythonEnvironment {
}
build.add_output_stamp(format!("{}/.stamp", self.venv_folder));
}
fn check_output_timestamps(&self) -> bool {
true
}
}
pub struct PythonTypecheck {
@ -189,31 +193,19 @@ 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 {
"$black -t py39 -q $check --color $in && $
$isort --color --settings-path $isort_ini $check $in"
"$ruff format $mode $in && $ruff check --select I --fix $in"
}
fn files(&mut self, build: &mut impl crate::build::FilesHandle) {
build.add_inputs("in", self.inputs);
build.add_inputs("black", inputs![":pyenv:black"]);
build.add_inputs("isort", inputs![":pyenv:isort"]);
build.add_inputs("ruff", inputs![":pyenv:ruff"]);
let hash = simple_hash(self.inputs);
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_variable("mode", if self.check_only { "--check" } else { "" });
build.add_output_stamp(format!(
"tests/python_format.{}.{hash}",
@ -223,13 +215,11 @@ 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,
},
)?;
@ -238,34 +228,39 @@ pub fn python_format(build: &mut Build, group: &str, inputs: BuildInput) -> Resu
PythonFormat {
inputs: &inputs,
check_only: false,
isort_ini,
},
)?;
Ok(())
}
pub struct PythonLint {
pub struct RuffCheck {
pub folders: &'static [&'static str],
pub pylint_ini: BuildInput,
pub deps: BuildInput,
pub check_only: bool,
}
impl BuildAction for PythonLint {
impl BuildAction for RuffCheck {
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) {
build.add_inputs("", &self.deps);
build.add_inputs("pylint", inputs![":pyenv:pylint"]);
build.add_inputs("pylint_ini", &self.pylint_ini);
build.add_inputs("", inputs![".ruff.toml"]);
build.add_inputs("ruff", inputs![":pyenv:ruff"]);
build.add_variable("folders", self.folders.join(" "));
// 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());
build.add_variable(
"mode",
if self.check_only {
""
} else {
"--fix --unsafe-fixes"
},
);
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();
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 {}\n depth = {}", key, value).unwrap();
writeln!(&mut buf, "pool {key}\n depth = {value}").unwrap();
}
buf.push('\n');

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!("{:x}", result)
format!("{result:x}")
}
enum CompressionKind {

View file

@ -67,7 +67,10 @@ pub fn run_build(args: BuildArgs) {
"MYPY_CACHE_DIR",
build_root.join("tests").join("mypy").into_string(),
)
.env("PYTHONPYCACHEPREFIX", build_root.join("pycache"))
.env(
"PYTHONPYCACHEPREFIX",
std::path::absolute(build_root.join("pycache")).unwrap(),
)
// commands will not show colors by default, as we do not provide a tty
.env("FORCE_COLOR", "1")
.env("MYPY_FORCE_COLOR", "1")
@ -135,7 +138,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

@ -32,10 +32,19 @@ pub fn setup_pyenv(args: PyenvArgs) {
}
}
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::new(args.uv_bin)
command
.env("UV_PROJECT_ENVIRONMENT", args.pyenv_folder.clone())
.args(["sync", "--frozen"])
.args(["sync", "--locked", "--no-config"])
.args(args.extra_args),
);

View file

@ -83,7 +83,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,7 +28,11 @@ pub fn setup_yarn(args: YarnArgs) {
.arg("--ignore-scripts"),
);
} else {
run_command(Command::new(&args.yarn_bin).arg("install"));
run_command(
Command::new(&args.yarn_bin)
.arg("install")
.arg("--immutable"),
);
}
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 eslint/copyright header issues
## Fixing ruff/eslint/copyright header issues
```
./ninja fix

View file

@ -1,35 +1,78 @@
# 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.
# This is a user-contributed Dockerfile. No official support is available.
ARG PYTHON_VERSION="3.9"
ARG DEBIAN_FRONTEND="noninteractive"
# 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
FROM ubuntu:24.04 AS build
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:${PYTHON_VERSION}-slim as installer
FROM python:3.13-slim AS installer
WORKDIR /opt/anki/
COPY --from=build /opt/anki/wheels/ wheels/
COPY --from=build /opt/anki/out/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:${PYTHON_VERSION}-slim as final
FROM python:3.13-slim AS final
COPY --from=installer /opt/anki/venv /opt/anki/venv
ENV PATH=/opt/anki/venv/bin:$PATH
# Install run-time dependencies.
@ -59,9 +102,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

@ -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).
- 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

@ -1 +1 @@
Subproject commit 2f8c9d9566aef8b86e3326fe9ff007d594b7ec83
Subproject commit 480ef0da728c7ea3485c58529ae7ee02be3e5dba

View file

@ -60,7 +60,6 @@ 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,6 +5,11 @@ 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

@ -384,8 +384,6 @@ 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.
@ -394,7 +392,6 @@ 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)
@ -407,7 +404,6 @@ 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
@ -425,6 +421,8 @@ 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
@ -466,12 +464,7 @@ 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)
@ -503,7 +496,10 @@ 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-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-additional-new-cards-to-simulate = Additional new cards to simulate
deck-config-simulate = Simulate
deck-config-clear-last-simulate = Clear Last Simulation
@ -512,10 +508,14 @@ 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.
@ -525,7 +525,7 @@ deck-config-health-check = Check health when optimizing
deck-config-fsrs-bad-fit-warning = Health Check:
Your memory is difficult for FSRS to predict. Recommendations:
- Suspend or reformulate leeches.
- 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.
@ -536,6 +536,17 @@ deck-config-fsrs-good-fit = Health Check:
## 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.

View file

@ -48,6 +48,7 @@ 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 }
@ -65,7 +66,6 @@ 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,7 +78,6 @@ 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 (*)
@ -252,3 +251,5 @@ 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 = eg. 'deck:current '
preferences-default-search-text-example = e.g. "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} memorized
statistics-memorized = {$memorized} cards 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
## 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
## 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
## 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 = True Retention
statistics-true-retention-title = Retention
statistics-true-retention-subtitle = Pass rate of cards with an interval ≥ 1 day.
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-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-range = Range
statistics-true-retention-pass = Pass
statistics-true-retention-fail = Fail

View file

@ -46,6 +46,20 @@ 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
@ -56,5 +70,3 @@ studying-minute =
[one] { $count } minute.
*[other] { $count } minutes.
}
studying-question-time-elapsed = Question time elapsed
studying-answer-time-elapsed = Answer time elapsed

@ -1 +1 @@
Subproject commit 69f2dbaeba6f72ac62da0b35881f320603da5124
Subproject commit fd5f984785ad07a0d3dbd893ee3d7e3671eaebd6

View file

@ -1,4 +1,5 @@
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
@ -45,3 +46,4 @@ 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,7 @@ 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-please-restart-to-update-anki = Please restart Anki to update to the latest version.
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()

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.20.7",
"@sveltejs/vite-plugin-svelte": "4.0.0",
"@sveltejs/kit": "^2.22.2",
"@sveltejs/vite-plugin-svelte": "5.1",
"@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": "^20",
"@types/node": "^22",
"@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.17.3",
"svelte-check": "^3.4.4",
"svelte-preprocess": "^5.0.4",
"svelte": "^5.34.9",
"svelte-check": "^4.2.2",
"svelte-preprocess": "^6.0.3",
"svelte-preprocess-esbuild": "^3.0.1",
"svgo": "^3.2.0",
"tslib": "^2.0.3",
"tsx": "^3.12.0",
"tsx": "^4.8.1",
"typescript": "^5.0.4",
"vite": "5.4.19",
"vitest": "^2"
"vite": "6",
"vitest": "^3"
},
"dependencies": {
"@bufbuild/protobuf": "^1.2.1",
@ -81,7 +81,9 @@
},
"resolutions": {
"canvas": "npm:empty-npm-package@1.0.0",
"cookie": "0.7.0"
"cookie": "0.7.0",
"devalue": "^5.3.2",
"vite": "6"
},
"browserslist": [
"defaults",

View file

@ -51,6 +51,7 @@ 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,6 +56,7 @@ 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,12 +40,10 @@ message DeckConfigId {
message GetRetentionWorkloadRequest {
repeated float w = 1;
string search = 2;
float before = 3;
float after = 4;
}
message GetRetentionWorkloadResponse {
float factor = 1;
map<uint32, float> costs = 1;
}
message GetIgnoredBeforeCountRequest {
@ -219,6 +217,8 @@ 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,6 +236,7 @@ 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,6 +83,8 @@ 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,6 +27,9 @@ 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,9 +176,12 @@ 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.OpChanges changes = 1;
collection.OpChangesWithCount changes = 1;
int64 note_id = 2;
}

View file

@ -55,7 +55,11 @@ 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.
@ -402,6 +406,9 @@ 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 {
@ -411,6 +418,12 @@ 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;
}
@ -442,6 +455,12 @@ 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;

View file

@ -74,10 +74,15 @@ 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;
bool is_re = 3;
FieldSearchMode mode = 3;
}
oneof filter {

View file

@ -46,7 +46,6 @@ 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:
@ -164,7 +163,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()
@ -247,7 +246,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(markdown(err.message), help_page, context, backtrace)
return SearchError(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 # pylint: disable=unused-import
import anki
import anki.collection
import anki.decks
import anki.notes
@ -49,6 +49,7 @@ class Card(DeprecatedNamesMixin):
memory_state: FSRSMemoryState | None
desired_retention: float | None
decay: float | None
last_review_time: int | None
def __init__(
self,
@ -103,6 +104,11 @@ 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
@ -127,6 +133,7 @@ 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

@ -158,7 +158,7 @@ class Collection(DeprecatedNamesMixin):
self.tags = TagManager(self)
self.conf = ConfigManager(self)
self._load_scheduler()
self._startReps = 0 # pylint: disable=invalid-name
self._startReps = 0
def name(self) -> Any:
return os.path.splitext(os.path.basename(self.path))[0]
@ -511,9 +511,7 @@ class Collection(DeprecatedNamesMixin):
# Utils
##########################################################################
def nextID( # pylint: disable=invalid-name
self, type: str, inc: bool = True
) -> Any:
def nextID(self, type: str, inc: bool = True) -> Any:
type = f"next{type.capitalize()}"
id = self.conf.get(type, 1)
if inc:
@ -530,7 +528,7 @@ class Collection(DeprecatedNamesMixin):
def new_note(self, notetype: NotetypeDict) -> Note:
return Note(self, notetype)
def add_note(self, note: Note, deck_id: DeckId) -> OpChanges:
def add_note(self, note: Note, deck_id: DeckId) -> OpChangesWithCount:
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)
@ -849,7 +847,6 @@ 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:
@ -867,7 +864,9 @@ 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,
@ -1212,8 +1211,6 @@ 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,7 +1,6 @@
# 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
@ -351,7 +350,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,7 +1,6 @@
# 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

@ -175,8 +175,8 @@ class MnemoFact:
def fact_view(self) -> type[MnemoFactView]:
try:
fact_view = self.cards[0].fact_view_id
except IndexError as err:
raise Exception(f"Fact {id} has no cards") from err
except IndexError:
return FrontOnly
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 {id} has unknown fact view: {fact_view}")
raise Exception(f"Fact {self.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,7 +1,6 @@
# 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,8 +11,6 @@ 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
@ -24,8 +22,6 @@ 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,7 +1,6 @@
# 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
@ -144,7 +143,6 @@ 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,7 +1,6 @@
# 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
@ -35,7 +34,6 @@ f._id=d._fact_id"""
):
if id != curid:
if note:
# pylint: disable=unsubscriptable-object
notes[note["_id"]] = note
note = {"_id": _id}
curid = id
@ -185,7 +183,6 @@ 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,7 +1,6 @@
# 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,94 +0,0 @@
# Copyright: Andreas Klauer <Andreas.Klauer@metamorpher.de>
# License: BSD-3
# pylint: disable=invalid-name
import gzip
import html
import math
import random
import time
import xml.etree.ElementTree as ET
from anki.importing.noteimp import ForeignCard, ForeignNote, NoteImporter
from anki.stdmodels import _legacy_add_forward_reverse
ONE_DAY = 60 * 60 * 24
class PaukerImporter(NoteImporter):
"""Import Pauker 1.8 Lesson (*.pau.gz)"""
needMapper = False
allowHTML = True
def run(self):
model = _legacy_add_forward_reverse(self.col)
model["name"] = "Pauker"
self.col.models.save(model, updateReqs=False)
self.col.models.set_current(model)
self.model = model
self.initMapping()
NoteImporter.run(self)
def fields(self):
"""Pauker is Front/Back"""
return 2
def foreignNotes(self):
"""Build and return a list of notes."""
notes = []
try:
f = gzip.open(self.file)
tree = ET.parse(f) # type: ignore
lesson = tree.getroot()
assert lesson.tag == "Lesson"
finally:
f.close()
index = -4
for batch in lesson.findall("./Batch"):
index += 1
for card in batch.findall("./Card"):
# Create a note for this card.
front = card.findtext("./FrontSide/Text")
back = card.findtext("./ReverseSide/Text")
note = ForeignNote()
assert front and back
note.fields = [
html.escape(x.strip())
.replace("\n", "<br>")
.replace(" ", " &nbsp;")
for x in [front, back]
]
notes.append(note)
# Determine due date for cards.
frontdue = card.find("./FrontSide[@LearnedTimestamp]")
backdue = card.find("./ReverseSide[@Batch][@LearnedTimestamp]")
if frontdue is not None:
note.cards[0] = self._learnedCard(
index, int(frontdue.attrib["LearnedTimestamp"])
)
if backdue is not None:
note.cards[1] = self._learnedCard(
int(backdue.attrib["Batch"]),
int(backdue.attrib["LearnedTimestamp"]),
)
return notes
def _learnedCard(self, batch, timestamp):
ivl = math.exp(batch)
now = time.time()
due = ivl - (now - timestamp / 1000.0) / ONE_DAY
fc = ForeignCard()
fc.due = self.col.sched.today + int(due + 0.5)
fc.ivl = random.randint(int(ivl * 0.90), int(ivl + 0.5))
fc.factor = random.randint(1500, 2500)
return fc

View file

@ -1,484 +0,0 @@
# Copyright: petr.michalec@gmail.com
# License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
# pytype: disable=attribute-error
# type: ignore
# pylint: disable=C
from __future__ import annotations
import re
import sys
import time
import unicodedata
from string import capwords
from xml.dom import minidom
from xml.dom.minidom import Element, Text
from anki.collection import Collection
from anki.importing.noteimp import ForeignCard, ForeignNote, NoteImporter
from anki.stdmodels import _legacy_add_basic_model
class SmartDict(dict):
"""
See http://www.peterbe.com/plog/SmartDict
Copyright 2005, Peter Bengtsson, peter@fry-it.com
0BSD
A smart dict can be instantiated either from a pythonic dict
or an instance object (eg. SQL recordsets) but it ensures that you can
do all the convenient lookups such as x.first_name, x['first_name'] or
x.get('first_name').
"""
def __init__(self, *a, **kw) -> None:
if a:
if isinstance(type(a[0]), dict):
kw.update(a[0])
elif isinstance(type(a[0]), object):
kw.update(a[0].__dict__)
elif hasattr(a[0], "__class__") and a[0].__class__.__name__ == "SmartDict":
kw.update(a[0].__dict__)
dict.__init__(self, **kw)
self.__dict__ = self
class SuperMemoElement(SmartDict):
"SmartDict wrapper to store SM Element data"
def __init__(self, *a, **kw) -> None:
SmartDict.__init__(self, *a, **kw)
# default content
self.__dict__["lTitle"] = None
self.__dict__["Title"] = None
self.__dict__["Question"] = None
self.__dict__["Answer"] = None
self.__dict__["Count"] = None
self.__dict__["Type"] = None
self.__dict__["ID"] = None
self.__dict__["Interval"] = None
self.__dict__["Lapses"] = None
self.__dict__["Repetitions"] = None
self.__dict__["LastRepetiton"] = None
self.__dict__["AFactor"] = None
self.__dict__["UFactor"] = None
# This is an AnkiImporter
class SupermemoXmlImporter(NoteImporter):
needMapper = False
allowHTML = True
"""
Supermemo XML export's to Anki parser.
Goes through a SM collection and fetch all elements.
My SM collection was a big mess where topics and items were mixed.
I was unable to parse my content in a regular way like for loop on
minidom.getElementsByTagName() etc. My collection had also an
limitation, topics were splited into branches with max 100 items
on each. Learning themes were in deep structure. I wanted to have
full title on each element to be stored in tags.
Code should be upgrade to support importing of SM2006 exports.
"""
def __init__(self, col: Collection, file: str) -> None:
"""Initialize internal variables.
Pameters to be exposed to GUI are stored in self.META"""
NoteImporter.__init__(self, col, file)
m = _legacy_add_basic_model(self.col)
m["name"] = "Supermemo"
self.col.models.save(m)
self.initMapping()
self.lines = None
self.numFields = int(2)
# SmXmlParse VARIABLES
self.xmldoc = None
self.pieces = []
self.cntBuf = [] # to store last parsed data
self.cntElm = [] # to store SM Elements data
self.cntCol = [] # to store SM Colections data
# store some meta info related to parse algorithm
# SmartDict works like dict / class wrapper
self.cntMeta = SmartDict()
self.cntMeta.popTitles = False
self.cntMeta.title = []
# META stores controls of import script, should be
# exposed to import dialog. These are default values.
self.META = SmartDict()
self.META.resetLearningData = False # implemented
self.META.onlyMemorizedItems = False # implemented
self.META.loggerLevel = 2 # implemented 0no,1info,2error,3debug
self.META.tagAllTopics = True
self.META.pathsToBeTagged = [
"English for beginners",
"Advanced English 97",
"Phrasal Verbs",
] # path patterns to be tagged - in gui entered like 'Advanced English 97|My Vocablary'
self.META.tagMemorizedItems = True # implemented
self.META.logToStdOutput = False # implemented
self.notes = []
## TOOLS
def _fudgeText(self, text: str) -> str:
"Replace sm syntax to Anki syntax"
text = text.replace("\n\r", "<br>")
text = text.replace("\n", "<br>")
return text
def _unicode2ascii(self, str: str) -> str:
"Remove diacritic punctuation from strings (titles)"
return "".join(
[
c
for c in unicodedata.normalize("NFKD", str)
if not unicodedata.combining(c)
]
)
def _decode_htmlescapes(self, html: str) -> str:
"""Unescape HTML code."""
# In case of bad formatted html you can import MinimalSoup etc.. see BeautifulSoup source code
from bs4 import BeautifulSoup
# my sm2004 also ecaped & char in escaped sequences.
html = re.sub("&amp;", "&", html)
# https://anki.tenderapp.com/discussions/ankidesktop/39543-anki-is-replacing-the-character-by-when-i-exit-the-html-edit-mode-ctrlshiftx
if html.find(">") < 0:
return html
# unescaped solitary chars < or > that were ok for minidom confuse btfl soup
# html = re.sub(u'>',u'&gt;',html)
# html = re.sub(u'<',u'&lt;',html)
return str(BeautifulSoup(html, "html.parser"))
def _afactor2efactor(self, af: float) -> float:
# Adapted from <http://www.supermemo.com/beta/xml/xml-core.htm>
# Ranges for A-factors and E-factors
af_min = 1.2
af_max = 6.9
ef_min = 1.3
ef_max = 3.3
# Sanity checks for the A-factor
if af < af_min:
af = af_min
elif af > af_max:
af = af_max
# Scale af to the range 0..1
af_scaled = (af - af_min) / (af_max - af_min)
# Rescale to the interval ef_min..ef_max
ef = ef_min + af_scaled * (ef_max - ef_min)
return ef
## DEFAULT IMPORTER METHODS
def foreignNotes(self) -> list[ForeignNote]:
# Load file and parse it by minidom
self.loadSource(self.file)
# Migrating content / time consuming part
# addItemToCards is called for each sm element
self.logger("Parsing started.")
self.parse()
self.logger("Parsing done.")
# Return imported cards
self.total = len(self.notes)
self.log.append("%d cards imported." % self.total)
return self.notes
def fields(self) -> int:
return 2
## PARSER METHODS
def addItemToCards(self, item: SuperMemoElement) -> None:
"This method actually do conversion"
# new anki card
note = ForeignNote()
# clean Q and A
note.fields.append(self._fudgeText(self._decode_htmlescapes(item.Question)))
note.fields.append(self._fudgeText(self._decode_htmlescapes(item.Answer)))
note.tags = []
# pre-process scheduling data
# convert learning data
if (
not self.META.resetLearningData
and int(item.Interval) >= 1
and getattr(item, "LastRepetition", None)
):
# migration of LearningData algorithm
tLastrep = time.mktime(time.strptime(item.LastRepetition, "%d.%m.%Y"))
tToday = time.time()
card = ForeignCard()
card.ivl = int(item.Interval)
card.lapses = int(item.Lapses)
card.reps = int(item.Repetitions) + int(item.Lapses)
nextDue = tLastrep + (float(item.Interval) * 86400.0)
remDays = int((nextDue - time.time()) / 86400)
card.due = self.col.sched.today + remDays
card.factor = int(
self._afactor2efactor(float(item.AFactor.replace(",", "."))) * 1000
)
note.cards[0] = card
# categories & tags
# it's worth to have every theme (tree structure of sm collection) stored in tags, but sometimes not
# you can deceide if you are going to tag all toppics or just that containing some pattern
tTaggTitle = False
for pattern in self.META.pathsToBeTagged:
if (
item.lTitle is not None
and pattern.lower() in " ".join(item.lTitle).lower()
):
tTaggTitle = True
break
if tTaggTitle or self.META.tagAllTopics:
# normalize - remove diacritic punctuation from unicode chars to ascii
item.lTitle = [self._unicode2ascii(topic) for topic in item.lTitle]
# Transform xyz / aaa / bbb / ccc on Title path to Tag xyzAaaBbbCcc
# clean things like [999] or [111-2222] from title path, example: xyz / [1000-1200] zyx / xyz
# clean whitespaces
# set Capital letters for first char of the word
tmp = list(
{re.sub(r"(\[[0-9]+\])", " ", i).replace("_", " ") for i in item.lTitle}
)
tmp = list({re.sub(r"(\W)", " ", i) for i in tmp})
tmp = list({re.sub("^[0-9 ]+$", "", i) for i in tmp})
tmp = list({capwords(i).replace(" ", "") for i in tmp})
tags = [j[0].lower() + j[1:] for j in tmp if j.strip() != ""]
note.tags += tags
if self.META.tagMemorizedItems and int(item.Interval) > 0:
note.tags.append("Memorized")
self.logger("Element tags\t- " + repr(note.tags), level=3)
self.notes.append(note)
def logger(self, text: str, level: int = 1) -> None:
"Wrapper for Anki logger"
dLevels = {0: "", 1: "Info", 2: "Verbose", 3: "Debug"}
if level <= self.META.loggerLevel:
# self.deck.updateProgress(_(text))
if self.META.logToStdOutput:
print(
self.__class__.__name__
+ " - "
+ dLevels[level].ljust(9)
+ " -\t"
+ text
)
# OPEN AND LOAD
def openAnything(self, source):
"""Open any source / actually only opening of files is used
@return an open handle which must be closed after use, i.e., handle.close()"""
if source == "-":
return sys.stdin
# try to open with urllib (if source is http, ftp, or file URL)
import urllib.error
import urllib.parse
import urllib.request
try:
return urllib.request.urlopen(source)
except OSError:
pass
# try to open with native open function (if source is pathname)
try:
return open(source, encoding="utf8")
except OSError:
pass
# treat source as string
import io
return io.StringIO(str(source))
def loadSource(self, source: str) -> None:
"""Load source file and parse with xml.dom.minidom"""
self.source = source
self.logger("Load started...")
sock = open(self.source, encoding="utf8")
self.xmldoc = minidom.parse(sock).documentElement
sock.close()
self.logger("Load done.")
# PARSE
def parse(self, node: Text | Element | None = None) -> None:
"Parse method - parses document elements"
if node is None and self.xmldoc is not None:
node = self.xmldoc
_method = "parse_%s" % node.__class__.__name__
if hasattr(self, _method):
parseMethod = getattr(self, _method)
parseMethod(node)
else:
self.logger("No handler for method %s" % _method, level=3)
def parse_Document(self, node):
"Parse XML document"
self.parse(node.documentElement)
def parse_Element(self, node: Element) -> None:
"Parse XML element"
_method = "do_%s" % node.tagName
if hasattr(self, _method):
handlerMethod = getattr(self, _method)
handlerMethod(node)
else:
self.logger("No handler for method %s" % _method, level=3)
# print traceback.print_exc()
def parse_Text(self, node: Text) -> None:
"Parse text inside elements. Text is stored into local buffer."
text = node.data
self.cntBuf.append(text)
# def parse_Comment(self, node):
# """
# Source can contain XML comments, but we ignore them
# """
# pass
# DO
def do_SuperMemoCollection(self, node: Element) -> None:
"Process SM Collection"
for child in node.childNodes:
self.parse(child)
def do_SuperMemoElement(self, node: Element) -> None:
"Process SM Element (Type - Title,Topics)"
self.logger("=" * 45, level=3)
self.cntElm.append(SuperMemoElement())
self.cntElm[-1]["lTitle"] = self.cntMeta["title"]
# parse all child elements
for child in node.childNodes:
self.parse(child)
# strip all saved strings, just for sure
for key in list(self.cntElm[-1].keys()):
if hasattr(self.cntElm[-1][key], "strip"):
self.cntElm[-1][key] = self.cntElm[-1][key].strip()
# pop current element
smel = self.cntElm.pop()
# Process cntElm if is valid Item (and not an Topic etc..)
# if smel.Lapses != None and smel.Interval != None and smel.Question != None and smel.Answer != None:
if smel.Title is None and smel.Question is not None and smel.Answer is not None:
if smel.Answer.strip() != "" and smel.Question.strip() != "":
# migrate only memorized otherway skip/continue
if self.META.onlyMemorizedItems and not (int(smel.Interval) > 0):
self.logger("Element skipped \t- not memorized ...", level=3)
else:
# import sm element data to Anki
self.addItemToCards(smel)
self.logger("Import element \t- " + smel["Question"], level=3)
# print element
self.logger("-" * 45, level=3)
for key in list(smel.keys()):
self.logger(
"\t{} {}".format((key + ":").ljust(15), smel[key]), level=3
)
else:
self.logger("Element skipped \t- no valid Q and A ...", level=3)
else:
# now we know that item was topic
# parsing of whole node is now finished
# test if it's really topic
if smel.Title is not None:
# remove topic from title list
t = self.cntMeta["title"].pop()
self.logger("End of topic \t- %s" % (t), level=2)
def do_Content(self, node: Element) -> None:
"Process SM element Content"
for child in node.childNodes:
if hasattr(child, "tagName") and child.firstChild is not None:
self.cntElm[-1][child.tagName] = child.firstChild.data
def do_LearningData(self, node: Element) -> None:
"Process SM element LearningData"
for child in node.childNodes:
if hasattr(child, "tagName") and child.firstChild is not None:
self.cntElm[-1][child.tagName] = child.firstChild.data
# It's being processed in do_Content now
# def do_Question(self, node):
# for child in node.childNodes: self.parse(child)
# self.cntElm[-1][node.tagName]=self.cntBuf.pop()
# It's being processed in do_Content now
# def do_Answer(self, node):
# for child in node.childNodes: self.parse(child)
# self.cntElm[-1][node.tagName]=self.cntBuf.pop()
def do_Title(self, node: Element) -> None:
"Process SM element Title"
t = self._decode_htmlescapes(node.firstChild.data)
self.cntElm[-1][node.tagName] = t
self.cntMeta["title"].append(t)
self.cntElm[-1]["lTitle"] = self.cntMeta["title"]
self.logger("Start of topic \t- " + " / ".join(self.cntMeta["title"]), level=2)
def do_Type(self, node: Element) -> None:
"Process SM element Type"
if len(self.cntBuf) >= 1:
self.cntElm[-1][node.tagName] = self.cntBuf.pop()
# if __name__ == '__main__':
# for testing you can start it standalone
# file = u'/home/epcim/hg2g/dev/python/sm2anki/ADVENG2EXP.xxe.esc.zaloha_FINAL.xml'
# file = u'/home/epcim/hg2g/dev/python/anki/libanki/tests/importing/supermemo/original_ENGLISHFORBEGGINERS_noOEM.xml'
# file = u'/home/epcim/hg2g/dev/python/anki/libanki/tests/importing/supermemo/original_ENGLISHFORBEGGINERS_oem_1250.xml'
# file = str(sys.argv[1])
# impo = SupermemoXmlImporter(Deck(),file)
# impo.foreignCards()
# sys.exit(1)
# vim: ts=4 sts=2 ft=python

View file

@ -18,7 +18,7 @@ from anki._legacy import DeprecatedNamesMixinForModule
TR = anki._fluent.LegacyTranslationEnum
FormatTimeSpan = _pb.FormatTimespanRequest
# When adding new languages here, check lang_to_disk_lang() below
langs = sorted(
[
("Afrikaans", "af_ZA"),
@ -38,6 +38,7 @@ langs = sorted(
("Italiano", "it_IT"),
("lo jbobau", "jbo_EN"),
("Lenga d'òc", "oc_FR"),
("Қазақша", "kk_KZ"),
("Magyar", "hu_HU"),
("Nederlands", "nl_NL"),
("Norsk", "nb_NO"),
@ -64,6 +65,7 @@ langs = sorted(
("Українська мова", "uk_UA"),
("Հայերեն", "hy_AM"),
("עִבְרִית", "he_IL"),
("ייִדיש", "yi"),
("العربية", "ar_SA"),
("فارسی", "fa_IR"),
("ภาษาไทย", "th_TH"),
@ -73,6 +75,7 @@ langs = sorted(
("ଓଡ଼ିଆ", "or_OR"),
("Filipino", "tl"),
("ئۇيغۇر", "ug"),
("Oʻzbekcha", "uz_UZ"),
]
)
@ -103,6 +106,7 @@ compatMap = {
"it": "it_IT",
"ja": "ja_JP",
"jbo": "jbo_EN",
"kk": "kk_KZ",
"ko": "ko_KR",
"la": "la_LA",
"mn": "mn_MN",
@ -123,7 +127,9 @@ compatMap = {
"th": "th_TH",
"tr": "tr_TR",
"uk": "uk_UA",
"uz": "uz_UZ",
"vi": "vi_VN",
"yi": "yi",
}
@ -157,13 +163,13 @@ def lang_to_disk_lang(lang: str) -> str:
# the currently set interface language
current_lang = "en" # pylint: disable=invalid-name
current_lang = "en"
# the current Fluent translation instance. Code in pylib/ should
# not reference this, and should use col.tr instead. The global
# instance exists for legacy reasons, and as a convenience for the
# 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)
@ -178,7 +184,7 @@ def ngettext(single: str, plural: str, num: int) -> str:
def set_lang(lang: str) -> None:
global current_lang, current_i18n # pylint: disable=invalid-name
global current_lang, current_i18n
current_lang = lang
current_i18n = anki._backend.RustBackend(langs=[lang])
tr_legacyglobal.backend = weakref.ref(current_i18n)
@ -198,9 +204,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
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
(sys_lang, enc) = (
locale.getdefaultlocale() # pylint: disable=deprecated-method
)
(sys_lang, enc) = locale.getdefaultlocale()
except AttributeError:
# this will return a different format on Windows (e.g. Italian_Italy), resulting in us falling back to en_US
# further below
@ -233,7 +237,7 @@ def get_def_lang(user_lang: str | None = None) -> tuple[int, str]:
def is_rtl(lang: str) -> bool:
return lang in ("he", "ar", "fa", "ug")
return lang in ("he", "ar", "fa", "ug", "yi")
# strip off unicode isolation markers from a translated string

View file

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

View file

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

View file

@ -4,10 +4,8 @@
# 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
# future.
#
# pylint: disable=unused-import
# pylint: enable=invalid-name
# ruff: noqa: F401
from anki.decks import DeckTreeNode
from anki.errors import InvalidInput, NotFoundError
from anki.lang import TR

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
# pylint: disable=invalid-name
from __future__ import annotations

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
# pylint: disable=invalid-name
from __future__ import annotations

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
# pylint: disable=invalid-name
"""
The V3/2021 scheduler.
@ -184,7 +183,7 @@ class Scheduler(SchedulerBaseWithLegacy):
return self._interval_for_filtered_state(state.filtered)
else:
assert_exhaustive(kind)
return 0 # pylint: disable=unreachable
return 0
def _interval_for_normal_state(
self, normal: scheduler_pb2.SchedulingState.Normal
@ -200,7 +199,7 @@ class Scheduler(SchedulerBaseWithLegacy):
return normal.relearning.learning.scheduled_secs
else:
assert_exhaustive(kind)
return 0 # pylint: disable=unreachable
return 0
def _interval_for_filtered_state(
self, filtered: scheduler_pb2.SchedulingState.Filtered
@ -212,7 +211,7 @@ class Scheduler(SchedulerBaseWithLegacy):
return self._interval_for_normal_state(filtered.rescheduling.original_state)
else:
assert_exhaustive(kind)
return 0 # pylint: disable=unreachable
return 0
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."

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
# pylint: disable=C
from __future__ import annotations
@ -27,7 +26,7 @@ def _legacy_card_stats(
col: anki.collection.Collection, card_id: anki.cards.CardId, include_revlog: bool
) -> str:
"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("-", "")
return f"""
<div id="{random_id}"></div>
@ -324,7 +323,6 @@ group by day order by day"""
yaxes=[dict(min=0), dict(position="right", min=0)],
)
if days is not None:
# pylint: disable=invalid-unary-operand-type
conf["xaxis"]["min"] = -days + 0.5
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)],
)
if days is not None:
# pylint: disable=invalid-unary-operand-type
conf["xaxis"]["min"] = -days + 0.5
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.
# by Daniel Beaton
# 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.utils import from_json_bytes
# pylint: disable=no-member
StockNotetypeKind = notetypes_pb2.StockNotetype.Kind
# add-on authors can add ("note type name", function)

View file

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

View file

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

View file

@ -35,8 +35,16 @@ class CustomBuildHook(BuildHookInterface):
assert generated_root.exists(), "you should build with --wheel"
for path in generated_root.rglob("*"):
if path.is_file():
if path.is_file() and not self._should_exclude(path):
relative_path = path.relative_to(generated_root)
# Place files under anki/ in the distribution
dist_path = "anki" / relative_path
force_include[str(path)] = str(dist_path)
def _should_exclude(self, path: Path) -> bool:
"""Check if a file should be excluded from the wheel."""
# Exclude __pycache__
path_str = str(path)
if "/__pycache__/" in path_str:
return True
return False

View file

@ -4,19 +4,15 @@ dynamic = ["version"]
requires-python = ">=3.9"
license = "AGPL-3.0-or-later"
dependencies = [
"beautifulsoup4",
"decorator",
"markdown",
"orjson",
"protobuf>=4.21",
"protobuf>=6.0,<8.0",
"requests[socks]",
# remove after we update to min python 3.11+
"typing_extensions",
"types-protobuf",
"types-requests",
"types-orjson",
# platform-specific dependencies
"distro; sys_platform != 'darwin' and sys_platform != 'win32'",
"psutil; sys_platform == 'win32'",
]
[build-system]

View file

@ -28,6 +28,6 @@ fn main() {
.to_string();
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
id = col.db.scalar("select id from cards limit 1")
col.db.execute(
"update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 "
"where id = ?",
"update cards set queue=2, ivl=10, reps=20, due=30, factor=2200 where id = ?",
id,
)
assert len(col.find_cards("prop:ivl>5")) == 1

View file

@ -13,7 +13,6 @@ from anki.importing import (
Anki2Importer,
AnkiPackageImporter,
MnemosyneImporter,
SupermemoXmlImporter,
TextImporter,
)
from tests.shared import getEmptyCol, getUpgradeDeckPath
@ -306,22 +305,6 @@ def test_csv_tag_only_if_modified():
col.close()
@pytest.mark.filterwarnings("ignore:Using or importing the ABCs")
def test_supermemo_xml_01_unicode():
col = getEmptyCol()
file = str(os.path.join(testDir, "support", "supermemo1.xml"))
i = SupermemoXmlImporter(col, file)
# i.META.logToStdOutput = True
i.run()
assert i.total == 1
cid = col.db.scalar("select id from cards")
c = col.get_card(cid)
# Applies A Factor-to-E Factor conversion
assert c.factor == 2879
assert c.reps == 7
col.close()
def test_mnemo():
col = getEmptyCol()
file = str(os.path.join(testDir, "support", "mnemo.db"))

View file

@ -551,12 +551,10 @@ def test_bury():
col.addNote(note)
c2 = note.cards()[0]
# burying
col.sched.bury_cards([c.id], manual=True) # pylint: disable=unexpected-keyword-arg
col.sched.bury_cards([c.id], manual=True)
c.load()
assert c.queue == QUEUE_TYPE_MANUALLY_BURIED
col.sched.bury_cards(
[c2.id], manual=False
) # pylint: disable=unexpected-keyword-arg
col.sched.bury_cards([c2.id], manual=False)
c2.load()
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:
# 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"buildhash = '{buildhash}'\n")

View file

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

View file

@ -7,7 +7,6 @@ Code for generating hooks.
from __future__ import annotations
import os
import subprocess
import sys
from dataclasses import dataclass
@ -204,9 +203,6 @@ def write_file(path: str, hooks: list[Hook], prefix: str, suffix: str):
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:
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,16 +7,23 @@ classifiers = ["Private :: Do Not Upload"]
[dependency-groups]
dev = [
"black",
"isort",
"mypy",
"mypy-protobuf",
"pylint",
"ruff",
"pytest",
"PyChromeDevTools",
"colorama", # for isort --color
"wheel",
"hatchling", # for type checking hatch_build.py files
"mock",
"types-protobuf",
"types-requests",
"types-orjson",
"types-decorator",
"types-flask",
"types-flask-cors",
"types-markdown",
"types-waitress",
"types-pywin32",
]
[project.optional-dependencies]

View file

@ -2,6 +2,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os
import subprocess
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-build", "out/python/sphinx", "out/python/sphinx/html"], check=True)

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