2020-11-01 05:26:58 +01:00
|
|
|
# Anki development
|
2020-08-03 07:31:22 +02:00
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
## Packaged betas
|
2020-08-03 07:31:22 +02:00
|
|
|
|
2020-12-07 02:22:31 +01:00
|
|
|
For non-developers who want to try beta versions, the easiest way is to use a
|
|
|
|
packaged version - please see:
|
2020-01-02 10:55:27 +01:00
|
|
|
|
2021-06-03 08:48:20 +02:00
|
|
|
https://betas.ankiweb.net/
|
2020-01-02 10:55:27 +01:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Pre-built Python wheels
|
2020-08-03 07:31:22 +02:00
|
|
|
|
2020-12-07 02:22:31 +01:00
|
|
|
Pre-built Python packages are available on PyPI. They are useful if you wish to:
|
|
|
|
|
|
|
|
- Run Anki from a local Python installation without building it yourself
|
|
|
|
- Get code completion when developing add-ons
|
|
|
|
- Make command line scripts that modify .anki2 files via Anki's Python libraries
|
|
|
|
|
2021-01-31 11:54:43 +01:00
|
|
|
You will need the 64 bit version of Python 3.8 or 3.9 installed. If you do not
|
|
|
|
have Python yet, please see the platform-specific instructions in the "Building
|
|
|
|
from source" section below for more info.
|
2020-08-03 07:31:22 +02:00
|
|
|
|
2020-12-07 02:22:31 +01:00
|
|
|
**Mac/Linux**:
|
2020-11-04 05:01:14 +01:00
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
```
|
2020-12-07 02:22:31 +01:00
|
|
|
$ python3.8 -m venv ~/pyenv
|
|
|
|
$ ~/pyenv/bin/pip install --upgrade pip
|
|
|
|
$ ~/pyenv/bin/pip install aqt
|
2020-11-01 05:26:58 +01:00
|
|
|
```
|
|
|
|
|
2020-12-07 02:22:31 +01:00
|
|
|
Then to run Anki:
|
2020-11-04 05:01:14 +01:00
|
|
|
|
|
|
|
```
|
2020-12-07 02:22:31 +01:00
|
|
|
$ ~/pyenv/bin/anki
|
|
|
|
```
|
|
|
|
|
|
|
|
**Windows**:
|
|
|
|
|
|
|
|
```
|
|
|
|
c:\> python -m venv \pyenv
|
|
|
|
c:\> \pyenv\scripts\pip install --upgrade pip
|
|
|
|
c:\> \pyenv\scripts\pip install aqt
|
|
|
|
```
|
|
|
|
|
|
|
|
Then to run Anki:
|
|
|
|
|
|
|
|
```
|
|
|
|
c:\> \pyenv\scripts\anki
|
2020-11-04 05:01:14 +01:00
|
|
|
```
|
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
## Building from source
|
2020-08-03 07:31:22 +02:00
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
Platform-specific instructions:
|
|
|
|
|
|
|
|
- [Windows](./windows.md)
|
|
|
|
- [Mac](./mac.md)
|
|
|
|
- [Linux](./linux.md)
|
2020-12-31 05:03:38 +01:00
|
|
|
- [Other Platforms](./new-platform.md)
|
2020-01-02 10:55:27 +01:00
|
|
|
|
2020-09-07 08:03:21 +02:00
|
|
|
Don't name the Git checkout ~/Anki or ~/Documents/Anki, as those folders
|
|
|
|
were used on old Anki versions and will be automatically moved.
|
|
|
|
|
2020-11-01 05:26:58 +01:00
|
|
|
Before contributing code, please see [Contributing](./contributing.md).
|
2020-01-02 10:55:27 +01:00
|
|
|
|
2021-06-03 08:48:20 +02:00
|
|
|
If you'd like to contribute translations, please see <https://translating.ankiweb.net/>.
|
2020-01-02 10:55:27 +01:00
|
|
|
|
2020-12-07 02:22:31 +01:00
|
|
|
## Building redistributable wheels
|
|
|
|
|
2020-12-10 11:27:21 +01:00
|
|
|
Run the following command to create Python packages that can be redistributed
|
2020-12-07 02:22:31 +01:00
|
|
|
and installed:
|
|
|
|
|
2020-12-10 11:27:21 +01:00
|
|
|
On Mac/Linux:
|
|
|
|
|
|
|
|
```
|
|
|
|
./scripts/build
|
|
|
|
```
|
|
|
|
|
|
|
|
On Windows:
|
|
|
|
|
2020-12-07 02:22:31 +01:00
|
|
|
```
|
2020-12-10 11:27:21 +01:00
|
|
|
.\scripts\build.bat
|
2020-12-07 02:22:31 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
The generated wheel paths will be printed as the build completes.
|
|
|
|
|
|
|
|
You can then install them by copying the paths into a pip install command.
|
|
|
|
Follow the steps in the "Pre-built Python wheels" section above, but replace the
|
|
|
|
"pip install aqt" line with something like:
|
|
|
|
|
|
|
|
```
|
2020-12-10 11:27:21 +01:00
|
|
|
pip install --upgrade bazel-dist/*.whl
|
2020-12-07 02:22:31 +01:00
|
|
|
```
|
|
|
|
|
2020-12-10 11:27:21 +01:00
|
|
|
On Windows you'll need to list out the filenames manually.
|
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Running tests
|
2020-01-02 10:55:27 +01:00
|
|
|
|
2021-01-19 01:26:00 +01:00
|
|
|
You can run all tests at once. From the top level project folder:
|
2020-11-01 05:26:58 +01:00
|
|
|
|
2020-04-16 10:19:56 +02:00
|
|
|
```
|
2021-01-19 01:26:00 +01:00
|
|
|
bazel test ...
|
2020-04-16 10:19:56 +02:00
|
|
|
```
|
|
|
|
|
2021-01-19 01:26:00 +01:00
|
|
|
If you're in a subfolder, `...` will run the tests in that folder.
|
|
|
|
To run all tests, use `//...` instead.
|
|
|
|
|
2020-12-02 02:23:01 +01:00
|
|
|
Pylint will currently fail if you're using Python 3.9.
|
|
|
|
|
2021-01-19 01:26:00 +01:00
|
|
|
To run a single Rust unit test with output, eg 'unbury':
|
|
|
|
|
|
|
|
```
|
|
|
|
bazel run rslib:unit_tests -- --nocapture unbury
|
|
|
|
```
|
|
|
|
|
2020-12-16 05:16:08 +01:00
|
|
|
To run a single Python library test, eg test_bury:
|
|
|
|
|
|
|
|
```
|
2021-01-19 01:26:00 +01:00
|
|
|
PYTEST=test_bury bazel run //pylib:pytest
|
2020-12-16 05:16:08 +01:00
|
|
|
```
|
|
|
|
|
2021-04-14 10:06:16 +02:00
|
|
|
On Mac/Linux, after installing 'fswatch', you can run mypy on
|
|
|
|
each file save automatically with:
|
|
|
|
|
|
|
|
```
|
|
|
|
./scripts/mypy-watch
|
|
|
|
```
|
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Fixing formatting
|
2020-11-01 05:26:58 +01:00
|
|
|
|
2020-11-12 11:11:40 +01:00
|
|
|
If the format tests fail, most can be fixed by running `format`
|
|
|
|
in the relevant package:
|
2020-04-11 06:36:05 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
```
|
2020-11-12 11:11:40 +01:00
|
|
|
bazel run //rslib:format
|
2021-01-09 05:16:26 +01:00
|
|
|
bazel run //rslib:sql_format
|
2021-01-09 08:42:26 +01:00
|
|
|
bazel run //rslib:proto_format
|
2020-11-12 11:11:40 +01:00
|
|
|
bazel run //pylib:format
|
|
|
|
bazel run //qt:format
|
2020-11-12 11:49:00 +01:00
|
|
|
bazel run //ts:format
|
|
|
|
bazel run //pylib/rsbridge:format
|
2020-11-12 11:11:40 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
If you're in one of those folders, you can use the short form:
|
|
|
|
|
|
|
|
```
|
|
|
|
bazel run format
|
2020-11-04 05:01:14 +01:00
|
|
|
```
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-12-11 12:04:06 +01:00
|
|
|
## Development speedups
|
|
|
|
|
|
|
|
If you're frequently switching between Anki versions, you can create
|
|
|
|
a user.bazelrc file in the top level folder with the following, which will
|
|
|
|
cache build products and downloads:
|
|
|
|
|
|
|
|
```
|
|
|
|
build --disk_cache=~/bazel/ankidisk --repository_cache=~/bazel/ankirepo
|
|
|
|
```
|
|
|
|
|
|
|
|
If you're frequently modifying the Rust parts of Anki, you can place the
|
2021-03-30 09:01:59 +02:00
|
|
|
following in your user.bazelrc file to enable incremental compilation
|
|
|
|
when using ./run.
|
2020-12-11 12:04:06 +01:00
|
|
|
|
|
|
|
```
|
2021-04-09 04:48:24 +02:00
|
|
|
build --@rules_rust//:experimental_incremental_base=/home/myuser/bazel/incremental
|
2020-12-11 12:04:06 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
The worker support is experimental, so you may need to remove it in future
|
|
|
|
updates.
|
|
|
|
|
2020-12-16 05:16:08 +01:00
|
|
|
## Python editing
|
|
|
|
|
|
|
|
PyCharm or IntelliJ IDEA seems to give the best Python editing experience. Make sure
|
|
|
|
you build/run Anki first, as code completion depends on the build process to generate
|
|
|
|
a bunch of files.
|
|
|
|
|
2020-12-16 06:10:01 +01:00
|
|
|
After telling PyCharm to create a new virtual environment for your project, locate
|
|
|
|
pip in the virtual environment, and run `pip install -r pip/requirements.txt` to install
|
|
|
|
all of Anki's dependencies into the environment, so that code completion works for them.
|
|
|
|
Then run `pip install pyqt5 pyqtwebengine` to install PyQt.
|
|
|
|
|
2020-12-16 05:16:08 +01:00
|
|
|
Visual Studio Code + the Python extension does support code completion, but
|
|
|
|
currently seems to frequently freeze for multiple seconds while pinning the CPU
|
|
|
|
at 100%. Switching from the default Jedi language server to Pylance improves the
|
|
|
|
CPU usage, but Pylance doesn't do a great job understanding the type annotations.
|
|
|
|
|
|
|
|
## Rust editing
|
|
|
|
|
|
|
|
Rust editor support is still fairly new, but currently Visual Studio Code + Rust
|
|
|
|
Analyzer seems to be the least-bad option. Once Rust Analyzer is installed,
|
|
|
|
you'll want to enable the options to expand proc macros, and run cargo check on
|
|
|
|
startup.
|
|
|
|
|
|
|
|
After running 'code rslib' from the project root, it may take Rust Analyzer a
|
|
|
|
while to become ready - if you check the running processes on your machine you should
|
|
|
|
see it running in the background for a while.
|
|
|
|
|
|
|
|
## TypeScript editing
|
|
|
|
|
|
|
|
Visual Studio Code seems to give the best experience. Use 'code ts' from the project
|
|
|
|
root to start it up.
|
|
|
|
|
|
|
|
IntelliJ IDEA works reasonably well, but doesn't seem to do as good a job at offering
|
|
|
|
useful completions for things like i18n.TR.
|
|
|
|
|
2020-11-13 00:14:12 +01:00
|
|
|
## Audio
|
|
|
|
|
|
|
|
Audio playing requires `mpv` or `mplayer` to be in your system path.
|
|
|
|
|
|
|
|
Recording also requires `lame` to be in your system path.
|
|
|
|
|
2020-12-22 00:29:30 +01:00
|
|
|
## Build errors and cleaning
|
|
|
|
|
|
|
|
If you get errors with @npm and node_modules in the message, try deleting the
|
|
|
|
ts/node_modules folder.
|
|
|
|
|
|
|
|
Unlike the old Make system, a "clean build" should almost never be required
|
|
|
|
unless you are debugging issues with the build system. But if you need to get
|
|
|
|
things to a fresh state, you can run `bazel clean --expunge`. Afte doing so,
|
|
|
|
make sure you remove the ts/node_modules folder, or subsequent build commands
|
|
|
|
will fail with a "no such file or directory node_modules/anki" message.
|
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Tracing build problems
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
You can run bazel with '-s' to print the commands that are being executed.
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Subcomponents
|
2020-11-01 05:26:58 +01:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
- pylib contains a Python module (anki) with the non-GUI Python code,
|
|
|
|
and a bridge to the Rust code.
|
|
|
|
- qt contains the Qt GUI implementation (aqt).
|
|
|
|
- rslib contains the parts of the code implemented in Rust.
|
2020-12-16 05:16:08 +01:00
|
|
|
- ts and qt/aqt/data/web contain Anki's typescript and sass files.
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Environmental Variables
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
If ANKIDEV is set before starting Anki, some extra log messages will be printed on stdout,
|
|
|
|
and automatic backups will be disabled - so please don't use this except on a test profile.
|
2020-11-01 05:26:58 +01:00
|
|
|
|
2020-12-16 05:16:08 +01:00
|
|
|
If TRACESQL is set, all sql statements will be printed as they are executed.
|
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
If LOGTERM is set before starting Anki, warnings and error messages that are normally placed
|
|
|
|
in the collection2.log file will also be printed on stdout.
|
2020-10-09 11:19:54 +02:00
|
|
|
|
2020-12-17 03:03:24 +01:00
|
|
|
If ANKI_PROFILE_CODE is set, Python profiling data will be written on exit.
|
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
## Mixing development and study
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
You may wish to create a separate profile with File>Switch Profile for use
|
|
|
|
during development. You can pass the arguments "-p [profile name]" when starting
|
|
|
|
Anki to load a specific profile.
|
2020-11-01 05:26:58 +01:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
If you're using PyCharm:
|
2020-10-03 07:26:34 +02:00
|
|
|
|
2020-11-04 05:01:14 +01:00
|
|
|
- right click on the "run" file in the root of the PyCharm Anki folder
|
|
|
|
- click "Edit 'run'..." - in Script options and enter:
|
|
|
|
"-p [dev profile name]" without the quotes
|
|
|
|
- click "Ok"
|