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
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
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
* 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>
* 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)
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)
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.
* 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
- 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
- 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)
- Handle beta/rc tags in .version when launching Anki
- Update pyproject.toml/.python_version if distributed version newer
- Support prerelease marker to opt in to betas
- Check for updates when using uv sync
- Avoid system Python by default, as it can cause breakages
(e.g. ARM Python installed on Windows)