Commit graph

87 commits

Author SHA1 Message Date
Damien Elmes
5d72f008f9 vendor stringcase
It's a tiny library that has not been updated in years, and it was
leading to a warning on startup:

 DeprecationWarning: invalid escape sequence \W
  return re.sub("\W+", "", string)
2021-10-22 08:56:44 +10:00
Damien Elmes
3c1729e91b run pyupgrade over codebase [python upgrade required]
This adds Python 3.9 and 3.10 typing syntax to files that import
attributions from __future___. Python 3.9 should be able to cope with
the 3.10 syntax, but Python 3.8 will no longer work.

On Windows/Mac, install the latest Python 3.9 version from python.org.
There are currently no orjson wheels for Python 3.10 on Windows/Mac,
which will break the build unless you have Rust installed separately.

On Linux, modern distros should have Python 3.9 available already. If
you're on an older distro, you'll need to build Python from source first.
2021-10-04 15:05:48 +10:00
Damien Elmes
98ff2102b7 apply some f-string updates via flynt 2021-10-02 23:52:02 +10:00
Damien Elmes
f0ce1cfc9d rename workspace
I'd forgotten that Bazel "helpfully" adds __init__.py files into folders
that match the workspace name, breaking imports.
2021-07-10 23:58:53 +10:00
Damien Elmes
e3b53fc078 split out remaining tags, stats, media and rendering 2021-07-10 23:16:18 +10:00
Damien Elmes
5255409093 refactor protobuf handling for split/import
In order to split backend.proto into a more manageable size, the protobuf
handling needed to be updated. This took more time than I would have
liked, as each language handles protobuf differently:

- The Python Protobuf code ignores "package" directives, and relies
solely on how the files are laid out on disk. While it would have been
nice to keep the generated files in a private subpackage, Protobuf gets
confused if the files are located in a location that does not match
their original .proto layout, so the old approach of storing them in
_backend/ will not work. They now clutter up pylib/anki instead. I'm
rather annoyed by that, but alternatives seem to be having to add an extra
level to the Protobuf path, making the other languages suffer, or trying
to hack around the issue by munging sys.modules.
- Protobufjs fails to expose packages if they don't start with a capital
letter, despite the fact that lowercase packages are the norm in most
languages :-( This required a patch to fix.
- Rust was the easiest, as Prost is relatively straightforward compared
to Google's tools.

The Protobuf files are now stored in /proto/anki, with a separate package
for each file. I've split backend.proto into a few files as a test, but
the majority of that work is still to come.

The Python Protobuf building is a bit of a hack at the moment, hard-coding
"proto" as the top level folder, but it seems to get the job done for now.

Also changed the workspace name, as there seems to be a number of Bazel
repos moving away from the more awkward reverse DNS naming style.
2021-07-10 19:17:05 +10:00
Damien Elmes
fba156ec93 PEP8 models.py 2021-06-27 14:30:00 +10:00
RumovZ
f220165c0f Fix black workaround for format calls 2021-05-18 22:19:09 +02:00
Damien Elmes
78b431cbf1 work around Windows issue on latest Black
Thanks Rumo!
552a53495e
2021-05-13 20:15:51 +10:00
Damien Elmes
6f3225fb2a drop leech hook in test scheduler
The explicit flush was clearing undo history, and the hook will need
re-working to support propagating OpChanges correctly. It will likely
come back as a GUI hook, instead of one in pylib.
2021-05-10 16:18:29 +10:00
Damien Elmes
926fc2e492 add missing copyright headers to *.py 2021-04-13 18:45:35 +10:00
Damien Elmes
b251843da6 add Dict suffix to Dict aliases in models.py 2021-03-27 21:46:49 +10:00
Damien Elmes
6b72aaf8c2 ID -> Id in protobuf and Python
follow-up to a90d5aa359
2021-03-27 21:38:20 +10:00
Damien Elmes
cf32bb034a update remaining TR references in rslib 2021-03-27 11:18:34 +10:00
Damien Elmes
d7005803bc update 1 arg tr strings in rslib 2021-03-27 10:39:53 +10:00
Damien Elmes
51f5df600f update no-arg TR references in rslib/ 2021-03-26 23:16:08 +10:00
Damien Elmes
7a7cb7402d update most no-arg TR references in *.svelte 2021-03-26 19:13:30 +10:00
Damien Elmes
1ed1902933 update TR references with args in *.svelte 2021-03-26 19:13:30 +10:00
Damien Elmes
0e50259e6b update TR references with args in *.ts; fix average answer time 2021-03-26 19:10:39 +10:00
Damien Elmes
2ab7a30b7b convert no-arg TR references to method invocations in *.ts 2021-03-26 19:10:27 +10:00
Damien Elmes
3d0e5248aa update TR references that crossed multiple lines 2021-03-26 14:38:15 +10:00
Damien Elmes
5d164bea7f update TR references that contain arguments 2021-03-26 14:21:04 +10:00
Damien Elmes
568bd54a61 update some more TR references in pylib; update tr_legacyglobal 2021-03-26 13:33:46 +10:00
Damien Elmes
bd59e41f73 update some no-arg TR constants 2021-03-26 12:37:18 +10:00
Arthur Milchior
575c1d32ec NF: NoteID type 2021-03-26 11:14:08 +10:00
Damien Elmes
53f8e06172 rename&simplify the deck/config type aliases
- QueueConfig is only used by the scheduler
- DeckConfig was being used in places that Config should have been used
- Add "Dict" to the name so that the bare name is free for use with a
stronger type.
2021-03-24 16:29:02 +10:00
Damien Elmes
708f60ee1b update to latest mypy_protobuf
The handling of enum types has improved - we no longer need to import
separate types at typechecking time.
2021-02-03 13:31:52 +10:00
Damien Elmes
0697e197cb update mypy and other Python deps
latest mypy_protobuf can no longer be run directly, so we need
to run a wrapper instead
2021-02-01 15:50:04 +10:00
Damien Elmes
39f253f125 always quote types in generated hooks 2021-02-01 08:36:33 +10:00
Damien Elmes
a6be0f493b start work on more clearly defining backend/protobuf boundaries
- anki._backend stores the protobuf files and rsbackend.py code
- pylib modules import protobuf messages directly from the
_pb2 files, and explicitly export any will be returned or consumed
by public pylib functions, so that calling code can import from pylib
- the "rsbackend" no longer imports and re-exports protobuf messages
- pylib can just consume them directly.
- move errors to errors.py

Still todo:

- rsbridge
- finishing the work on rsbackend, and check what we need to add
back to the original file location to avoid breaking add-ons
2021-01-31 18:55:45 +10:00
Damien Elmes
387be76c00 minor wording tweak: GraphsPreferences -> GraphPreferences 2021-01-23 20:47:45 +10:00
Henrik Giesel
25eee0e704 Change the function name in genbackend.py 2021-01-22 20:05:28 +01:00
Henrik Giesel
1516f5c37e Add GraphsPreferences endpoint to backend 2021-01-22 13:13:48 +01:00
Damien Elmes
2b5ef0b9a8 fix qt/ pylints 2021-01-07 16:21:50 +10:00
Damien Elmes
1781e83252 merge pylib references 2020-11-17 19:23:06 +10:00
Damien Elmes
ad5cbf195f use full path in backend_pb2 import 2020-11-13 14:21:21 +10:00
Damien Elmes
c62e6e61c2 update i18n scripts
- export updated .po files for consumption
- add a script to pull and push translations
2020-11-11 21:08:06 +10:00
ianki
28ad68d490 Add hooks for filtering media. 2020-11-09 02:12:23 -08:00
Damien Elmes
ad809943bf fix backend_pb2 race 2020-11-05 11:02:40 +10:00
Damien Elmes
7c27c4b9a0 move backend.proto into rslib/ 2020-11-02 16:28:31 +10:00
Damien Elmes
ce3b08ac58 initial Bazel conversion
Running and testing should be working on the three platforms, but
there's still a fair bit that needs to be done:

- Wheel building + testing in a venv still needs to be implemented.
- Python requirements still need to be compiled with piptool and pinned;
need to compile on all platforms then merge
- Cargo deps in cargo/ and rslib/ need to be cleaned up, and ideally
unified into one place
- Currently using rustls to work around openssl compilation issues
on Linux, but this will break corporate proxies with custom SSL
authorities; need to conditionally use openssl or use
https://github.com/seanmonstar/reqwest/pull/1058
- Makefiles and docs still need cleaning up
- It may make sense to reparent ts/* to the top level, as we don't
nest the other modules under a specific language.
- rspy and pylib must always be updated in lock-step, so merging
rspy into pylib as a private module would simplify things.
- Merging desktop-ftl and mobile-ftl into the core ftl would make
managing and updating translations easier.
- Obsolete scripts need removing.
- And probably more.
2020-11-01 14:26:58 +10:00
Damien Elmes
8729edffbb update to latest black 2020-08-31 13:29:28 +10:00
Arthur Milchior
110f4c664f Any removed 2020-08-12 01:37:21 +02:00
Damien Elmes
1e9901e9bd experiment with exposing raw card/revlog data to frontend 2020-06-29 15:48:00 +10:00
Damien Elmes
df8be64da3 protobuf package should be in PascalCase 2020-06-29 15:48:00 +10:00
Damien Elmes
80987a34ab add .count() to hooks, and list->sequence in note deletion 2020-06-04 18:20:03 +10:00
Damien Elmes
d7a2e78c0b change sync label to indicate sync state
- blue for normal sync, red for full sync required
- refactor status fetching code so we don't hold a collection lock
during the network request, which slows things down
- fix sync spinner restarting when returning to deck list
2020-06-02 13:23:01 +10:00
Damien Elmes
0787381a99 login/full up/full down plugged in 2020-06-01 13:57:10 +10:00
Damien Elmes
aaed0464e5 rework progress handling
- client now polls status instead of backend pushing it
- supports multiple threads
- update throttling happens in one place
2020-06-01 13:57:10 +10:00
Damien Elmes
9e5dad86a8 fix typechecking breaking with latest mypy_protobuf
the change that caused it:
https://github.com/dropbox/mypy-protobuf/issues/118

This is more awkward to handle now, as the types are only available
at type-checking time. Python's static typing is such a mess :-(
2020-05-27 09:14:02 +10:00