Anki is a smart spaced repetition flashcard program
Find a file
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
.buildkite Auto-expand bundle progress in Buildkite on Linux 2025-01-26 19:37:34 +11:00
.cargo Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
.config Drop workspace-hack in favor of workspace deps 2023-06-23 17:41:31 +10:00
.cursor/rules Make URL schemes dialog more ergonomic (#4002) 2025-05-15 16:17:33 +10:00
.github/ISSUE_TEMPLATE Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
.vscode.dist Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
build Update to latest node LTS; add update helper 2025-07-01 17:06:27 +07:00
cargo Upgrade to nom 8.0.0 (#4105) 2025-06-21 19:15:19 +07:00
docs Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
ftl Comments for translators (#4137) 2025-07-01 16:10:34 +07:00
proto Re-expose legacy RMSE calculations 2025-07-01 18:22:55 +07:00
pylib Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
python Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
qt Add some helpers to allow add-ons to install packages into the venv 2025-07-04 14:23:04 +07:00
rslib Re-expose legacy RMSE calculations 2025-07-01 18:22:55 +07:00
tools Do anki_release upload last 2025-06-29 22:30:20 +07:00
ts Update svelte/vite/esbuild for CWEs 2025-07-01 18:01:48 +07:00
.deny.toml Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
.dockerignore Add distroless Dockerfile and implement internal health check (#3366) 2024-08-29 17:05:33 +07:00
.dprint.json Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
.eslintrc.cjs Include error message text on page 2024-06-24 15:35:47 +07:00
.gitattributes try again to improve GitHub's language stats 2021-01-20 13:20:45 +10:00
.gitignore Support hidden local Claude config 2025-06-29 22:16:59 +07:00
.gitmodules Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
.mypy.ini Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
.prettierrc Switch back to Prettier for Svelte formatting 2025-01-13 15:53:55 +11:00
.python-version Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
.ruff.toml Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
.rustfmt-empty.toml Move away from Bazel (#2202) 2022-11-27 15:24:20 +10:00
.rustfmt.toml Move ascii_percent_encoding into a separate repo 2023-04-12 08:45:23 +10:00
.version Bump version 2025-06-29 22:17:01 +07:00
.yarnrc.yml Yarn 4 (#3772) 2025-01-26 14:40:17 +11:00
Cargo.lock Add search keyword to strip clozes beforehand (#4145) 2025-07-01 16:35:21 +07:00
Cargo.toml Add search keyword to strip clozes beforehand (#4145) 2025-07-01 16:35:21 +07:00
check Add a shortcut to auto-format before running checks 2023-07-02 09:59:05 +10:00
CLAUDE.md Support hidden local Claude config 2025-06-29 22:16:59 +07:00
CONTRIBUTORS Remove newline: 'Restore to default confirmation' (#4128) 2025-06-27 16:50:06 +07:00
LICENSE Drop Pauker and SuperMemo importers from legacy importer 2025-06-27 16:10:12 +07:00
ninja Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
package.json Update svelte/vite/esbuild for CWEs 2025-07-01 18:01:48 +07:00
pkgkey.asc add public key for release signing 2018-09-18 10:40:45 +10:00
pyproject.toml Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
README.md Add a trademark symbol to the readme and about screens 2025-07-01 11:40:03 +07:00
run Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
run.bat Migrate build system to uv (#4074) 2025-06-19 14:03:16 +07:00
rust-toolchain.toml Update to Rust 1.88 2025-06-29 11:50:49 +07:00
SECURITY.md add SECURITY.md 2021-09-22 22:55:19 +10:00
uv.lock Switch to Ruff (#4119) 2025-06-29 14:38:35 +07:00
yarn Switch to SvelteKit (#3077) 2024-03-31 09:16:31 +01:00
yarn.bat Switch to SvelteKit (#3077) 2024-03-31 09:16:31 +01:00
yarn.lock Update svelte/vite/esbuild for CWEs 2025-07-01 18:01:48 +07:00

Anki®

Build status

This repo contains the source code for the computer version of Anki.

About

Anki is a spaced repetition program. Please see the website to learn more.

Getting Started

Anki Betas

If you'd like to try development builds of Anki but don't feel comfortable building the code, please see Anki betas

Developing

For more information on building and developing, please see Development.

Contributing

Want to contribute to Anki? Check out the Contribution Guidelines.

Anki Contributors

CONTRIBUTORS

License

Anki's license: LICENSE