mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
move rsbridge into _backend
This commit is contained in:
parent
9d853bbb03
commit
67cb147493
7 changed files with 48 additions and 35 deletions
|
@ -2,7 +2,6 @@ load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||||
load("@rules_python//python:defs.bzl", "py_library")
|
load("@rules_python//python:defs.bzl", "py_library")
|
||||||
load("@py_deps//:requirements.bzl", "requirement")
|
load("@py_deps//:requirements.bzl", "requirement")
|
||||||
load("@rules_python//experimental/python:wheel.bzl", "py_package", "py_wheel")
|
load("@rules_python//experimental/python:wheel.bzl", "py_package", "py_wheel")
|
||||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
|
||||||
load("//:defs.bzl", "anki_version")
|
load("//:defs.bzl", "anki_version")
|
||||||
load("//pylib:orjson.bzl", "orjson_if_available")
|
load("//pylib:orjson.bzl", "orjson_if_available")
|
||||||
|
|
||||||
|
@ -19,29 +18,6 @@ genrule(
|
||||||
tools = ["//pylib/tools:genhooks"],
|
tools = ["//pylib/tools:genhooks"],
|
||||||
)
|
)
|
||||||
|
|
||||||
copy_file(
|
|
||||||
name = "rsbridge_unix",
|
|
||||||
src = "//pylib/rsbridge",
|
|
||||||
out = "_rsbridge.so",
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_file(
|
|
||||||
name = "rsbridge_win",
|
|
||||||
src = "//pylib/rsbridge",
|
|
||||||
out = "_rsbridge.pyd",
|
|
||||||
)
|
|
||||||
|
|
||||||
alias(
|
|
||||||
name = "rsbridge",
|
|
||||||
actual = selects.with_or({
|
|
||||||
(
|
|
||||||
"@io_bazel_rules_rust//rust/platform:x86_64-pc-windows-msvc",
|
|
||||||
): ":rsbridge_win",
|
|
||||||
"//conditions:default": ":rsbridge_unix",
|
|
||||||
}),
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
||||||
|
|
||||||
_py_srcs = glob(
|
_py_srcs = glob(
|
||||||
["**/*.py"],
|
["**/*.py"],
|
||||||
exclude = [
|
exclude = [
|
||||||
|
@ -56,7 +32,6 @@ py_library(
|
||||||
"py.typed",
|
"py.typed",
|
||||||
":buildinfo",
|
":buildinfo",
|
||||||
":hooks_gen",
|
":hooks_gen",
|
||||||
":rsbridge",
|
|
||||||
"//pylib/anki/_backend",
|
"//pylib/anki/_backend",
|
||||||
],
|
],
|
||||||
imports = [
|
imports = [
|
||||||
|
@ -122,6 +97,5 @@ filegroup(
|
||||||
srcs = _py_srcs,
|
srcs = _py_srcs,
|
||||||
visibility = [
|
visibility = [
|
||||||
"//pylib:__subpackages__",
|
"//pylib:__subpackages__",
|
||||||
"//qt/po:__pkg__",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
load("@rules_python//python:defs.bzl", "py_binary")
|
load("@rules_python//python:defs.bzl", "py_binary")
|
||||||
load("@py_deps//:requirements.bzl", "requirement")
|
load("@py_deps//:requirements.bzl", "requirement")
|
||||||
load("//pylib:protobuf.bzl", "py_proto_library_typed")
|
load("//pylib:protobuf.bzl", "py_proto_library_typed")
|
||||||
|
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||||
|
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||||
|
|
||||||
py_proto_library_typed(
|
py_proto_library_typed(
|
||||||
name = "backend_pb2",
|
name = "backend_pb2",
|
||||||
|
@ -38,13 +40,51 @@ genrule(
|
||||||
tools = ["genbackend"],
|
tools = ["genbackend"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
copy_file(
|
||||||
|
name = "rsbridge_unix",
|
||||||
|
src = "//pylib/rsbridge",
|
||||||
|
out = "rsbridge.so",
|
||||||
|
)
|
||||||
|
|
||||||
|
copy_file(
|
||||||
|
name = "rsbridge_win",
|
||||||
|
src = "//pylib/rsbridge",
|
||||||
|
out = "rsbridge.pyd",
|
||||||
|
)
|
||||||
|
|
||||||
|
alias(
|
||||||
|
name = "rsbridge",
|
||||||
|
actual = selects.with_or({
|
||||||
|
(
|
||||||
|
"@io_bazel_rules_rust//rust/platform:x86_64-pc-windows-msvc",
|
||||||
|
): ":rsbridge_win",
|
||||||
|
"//conditions:default": ":rsbridge_unix",
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
_py_srcs = [
|
||||||
|
"genbackend.py",
|
||||||
|
"__init__.py",
|
||||||
|
]
|
||||||
|
|
||||||
|
# for format check
|
||||||
|
filegroup(
|
||||||
|
name = "py_source_files",
|
||||||
|
srcs = _py_srcs,
|
||||||
|
visibility = [
|
||||||
|
"//pylib:__subpackages__",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "_backend",
|
name = "_backend",
|
||||||
srcs = [
|
srcs = [
|
||||||
"__init__.py",
|
"__init__.py",
|
||||||
|
"rsbridge.pyi",
|
||||||
":backend_pb2",
|
":backend_pb2",
|
||||||
":fluent_pb2",
|
":fluent_pb2",
|
||||||
":rsbackend_gen",
|
":rsbackend_gen",
|
||||||
|
":rsbridge",
|
||||||
],
|
],
|
||||||
visibility = ["//pylib:__subpackages__"],
|
visibility = ["//pylib:__subpackages__"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,9 +22,9 @@ import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
|
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
|
||||||
|
|
||||||
import anki._backend.backend_pb2 as pb
|
|
||||||
import anki._rsbridge
|
|
||||||
import anki.buildinfo
|
import anki.buildinfo
|
||||||
|
from . import backend_pb2 as pb
|
||||||
|
from . import rsbridge
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
from anki._backend.generated import RustBackendGenerated
|
from anki._backend.generated import RustBackendGenerated
|
||||||
from anki.dbproxy import Row as DBRow
|
from anki.dbproxy import Row as DBRow
|
||||||
|
@ -36,7 +36,7 @@ from anki.utils import from_json_bytes, to_json_bytes
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from anki.lang import FormatTimeSpanContextValue, TRValue
|
from anki.lang import FormatTimeSpanContextValue, TRValue
|
||||||
|
|
||||||
assert anki._rsbridge.buildhash() == anki.buildinfo.buildhash
|
assert rsbridge.buildhash() == anki.buildinfo.buildhash
|
||||||
|
|
||||||
# FIXME: rather than adding new items here, items intended to be consumed
|
# FIXME: rather than adding new items here, items intended to be consumed
|
||||||
# by external libraries (eg aqt) should be exported in the module that
|
# by external libraries (eg aqt) should be exported in the module that
|
||||||
|
@ -71,7 +71,7 @@ class RustBackend(RustBackendGenerated):
|
||||||
preferred_langs=langs,
|
preferred_langs=langs,
|
||||||
server=server,
|
server=server,
|
||||||
)
|
)
|
||||||
self._backend = anki._rsbridge.open_backend(init_msg.SerializeToString())
|
self._backend = rsbridge.open_backend(init_msg.SerializeToString())
|
||||||
|
|
||||||
def db_query(
|
def db_query(
|
||||||
self, sql: str, args: Sequence[ValueForDB], first_row_only: bool
|
self, sql: str, args: Sequence[ValueForDB], first_row_only: bool
|
||||||
|
|
|
@ -27,7 +27,7 @@ ignore_missing_imports = True
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-bs4]
|
[mypy-bs4]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-anki._rsbridge]
|
[mypy-anki._backend.rsbridge]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-stringcase]
|
[mypy-stringcase]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
|
|
|
@ -11,12 +11,12 @@ use std::convert::TryFrom;
|
||||||
// Regular backend
|
// Regular backend
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
#[pyclass(module = "_rsbridge")]
|
#[pyclass(module = "rsbridge")]
|
||||||
struct Backend {
|
struct Backend {
|
||||||
backend: RustBackend,
|
backend: RustBackend,
|
||||||
}
|
}
|
||||||
|
|
||||||
create_exception!(_rsbridge, BackendError, PyException);
|
create_exception!(rsbridge, BackendError, PyException);
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn buildhash() -> &'static str {
|
fn buildhash() -> &'static str {
|
||||||
|
@ -97,7 +97,7 @@ impl Backend {
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn _rsbridge(_py: Python, m: &PyModule) -> PyResult<()> {
|
fn rsbridge(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
m.add_class::<Backend>()?;
|
m.add_class::<Backend>()?;
|
||||||
m.add_wrapped(wrap_pyfunction!(buildhash)).unwrap();
|
m.add_wrapped(wrap_pyfunction!(buildhash)).unwrap();
|
||||||
m.add_wrapped(wrap_pyfunction!(open_backend)).unwrap();
|
m.add_wrapped(wrap_pyfunction!(open_backend)).unwrap();
|
||||||
|
|
|
@ -13,7 +13,6 @@ compile_all(
|
||||||
group = "forms",
|
group = "forms",
|
||||||
visibility = [
|
visibility = [
|
||||||
"//qt/aqt:__pkg__",
|
"//qt/aqt:__pkg__",
|
||||||
"//qt/po:__pkg__",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue