mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Make orjson optional again
While 32 bit platform support is probably not going to come back, this allows Anki to run on other architectures orjson doesn't support.
This commit is contained in:
parent
ae410fac24
commit
f9e939aaff
4 changed files with 30 additions and 9 deletions
|
@ -34,8 +34,15 @@ https://github.com/ankitects/anki/commit/db3308e788f20b188e84add40d6a1dce5bf726a
|
|||
build --action_env=PYTHON_SITE_PACKAGES=/path/to/site-packages
|
||||
```
|
||||
|
||||
- Anki uses the Python 'orjson' module. If it's not available on your system,
|
||||
you will need to [patch it out](https://github.com/ankitects/anki/pull/752#issuecomment-748861582), and remove references to it in the build scripts.
|
||||
- Anki uses the Python 'orjson' module to speed up DB access. If you're on a
|
||||
platform that can not build orjson, you can remove it from
|
||||
pip/requirements.txt to skip it during running/building, but DB operations
|
||||
will be slower.
|
||||
|
||||
The py_wheel() rule in pylib/anki/BUILD.bazel adds an orjson requirement to
|
||||
the generated Anki wheel on x86_64. If you have removed orjson, you'll want to
|
||||
remove that line. If you have successfully built orjson for another platform,
|
||||
you'll want to adjust that line to include your platform.
|
||||
|
||||
## Rust
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ load("//pylib:protobuf.bzl", "py_proto_library_typed")
|
|||
load("@rules_python//experimental/python:wheel.bzl", "py_package", "py_wheel")
|
||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||
load("//:defs.bzl", "anki_version")
|
||||
load("//pylib:orjson.bzl", "orjson_if_available")
|
||||
|
||||
copy_file(
|
||||
name = "buildinfo",
|
||||
|
@ -93,10 +94,9 @@ py_library(
|
|||
requirement("beautifulsoup4"),
|
||||
requirement("decorator"),
|
||||
requirement("distro"),
|
||||
requirement("orjson"),
|
||||
requirement("protobuf"),
|
||||
requirement("requests"),
|
||||
],
|
||||
] + orjson_if_available(),
|
||||
)
|
||||
|
||||
py_package(
|
||||
|
@ -123,7 +123,7 @@ py_wheel(
|
|||
"requests[socks]",
|
||||
"decorator",
|
||||
"protobuf",
|
||||
"orjson",
|
||||
'orjson; platform_machine == "x86_64"',
|
||||
'psutil; sys_platform == "win32"',
|
||||
'distro; sys_platform != "darwin" and sys_platform != "win32"',
|
||||
],
|
||||
|
|
|
@ -22,8 +22,6 @@ import os
|
|||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
|
||||
|
||||
import orjson
|
||||
|
||||
import anki._rsbridge
|
||||
import anki.backend_pb2 as pb
|
||||
import anki.buildinfo
|
||||
|
@ -53,8 +51,15 @@ SyncOutput = pb.SyncCollectionOut
|
|||
SyncStatus = pb.SyncStatusOut
|
||||
CountsForDeckToday = pb.CountsForDeckTodayOut
|
||||
|
||||
to_json_bytes = orjson.dumps
|
||||
from_json_bytes = orjson.loads
|
||||
try:
|
||||
import orjson
|
||||
|
||||
to_json_bytes = orjson.dumps
|
||||
from_json_bytes = orjson.loads
|
||||
except:
|
||||
print("orjson is missing; DB operations will be slower")
|
||||
to_json_bytes = lambda obj: json.dumps(obj).encode("utf8") # type: ignore
|
||||
from_json_bytes = json.loads
|
||||
|
||||
|
||||
class Interrupted(Exception):
|
||||
|
|
9
pylib/orjson.bzl
Normal file
9
pylib/orjson.bzl
Normal file
|
@ -0,0 +1,9 @@
|
|||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
|
||||
def orjson_if_available():
|
||||
"Include orjson if it's listed in requirements.txt."
|
||||
target = requirement("orjson")
|
||||
if "not_found" in target:
|
||||
return []
|
||||
else:
|
||||
return [target]
|
Loading…
Reference in a new issue