move rsbridge into _backend
This commit is contained in:
parent
9d853bbb03
commit
67cb147493
@ -2,7 +2,6 @@ load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||
load("@rules_python//python:defs.bzl", "py_library")
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
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")
|
||||
|
||||
@ -19,29 +18,6 @@ genrule(
|
||||
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"],
|
||||
exclude = [
|
||||
@ -56,7 +32,6 @@ py_library(
|
||||
"py.typed",
|
||||
":buildinfo",
|
||||
":hooks_gen",
|
||||
":rsbridge",
|
||||
"//pylib/anki/_backend",
|
||||
],
|
||||
imports = [
|
||||
@ -122,6 +97,5 @@ filegroup(
|
||||
srcs = _py_srcs,
|
||||
visibility = [
|
||||
"//pylib:__subpackages__",
|
||||
"//qt/po:__pkg__",
|
||||
],
|
||||
)
|
||||
|
@ -1,6 +1,8 @@
|
||||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
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(
|
||||
name = "backend_pb2",
|
||||
@ -38,13 +40,51 @@ genrule(
|
||||
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(
|
||||
name = "_backend",
|
||||
srcs = [
|
||||
"__init__.py",
|
||||
"rsbridge.pyi",
|
||||
":backend_pb2",
|
||||
":fluent_pb2",
|
||||
":rsbackend_gen",
|
||||
":rsbridge",
|
||||
],
|
||||
visibility = ["//pylib:__subpackages__"],
|
||||
)
|
||||
|
@ -22,9 +22,9 @@ import os
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Union
|
||||
|
||||
import anki._backend.backend_pb2 as pb
|
||||
import anki._rsbridge
|
||||
import anki.buildinfo
|
||||
from . import backend_pb2 as pb
|
||||
from . import rsbridge
|
||||
from anki import hooks
|
||||
from anki._backend.generated import RustBackendGenerated
|
||||
from anki.dbproxy import Row as DBRow
|
||||
@ -36,7 +36,7 @@ from anki.utils import from_json_bytes, to_json_bytes
|
||||
if TYPE_CHECKING:
|
||||
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
|
||||
# by external libraries (eg aqt) should be exported in the module that
|
||||
@ -71,7 +71,7 @@ class RustBackend(RustBackendGenerated):
|
||||
preferred_langs=langs,
|
||||
server=server,
|
||||
)
|
||||
self._backend = anki._rsbridge.open_backend(init_msg.SerializeToString())
|
||||
self._backend = rsbridge.open_backend(init_msg.SerializeToString())
|
||||
|
||||
def db_query(
|
||||
self, sql: str, args: Sequence[ValueForDB], first_row_only: bool
|
||||
|
@ -27,7 +27,7 @@ ignore_missing_imports = True
|
||||
ignore_missing_imports = True
|
||||
[mypy-bs4]
|
||||
ignore_missing_imports = True
|
||||
[mypy-anki._rsbridge]
|
||||
[mypy-anki._backend.rsbridge]
|
||||
ignore_missing_imports = True
|
||||
[mypy-stringcase]
|
||||
ignore_missing_imports = True
|
||||
|
@ -11,12 +11,12 @@ use std::convert::TryFrom;
|
||||
// Regular backend
|
||||
//////////////////////////////////
|
||||
|
||||
#[pyclass(module = "_rsbridge")]
|
||||
#[pyclass(module = "rsbridge")]
|
||||
struct Backend {
|
||||
backend: RustBackend,
|
||||
}
|
||||
|
||||
create_exception!(_rsbridge, BackendError, PyException);
|
||||
create_exception!(rsbridge, BackendError, PyException);
|
||||
|
||||
#[pyfunction]
|
||||
fn buildhash() -> &'static str {
|
||||
@ -97,7 +97,7 @@ impl Backend {
|
||||
//////////////////////////////////
|
||||
|
||||
#[pymodule]
|
||||
fn _rsbridge(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
fn rsbridge(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_class::<Backend>()?;
|
||||
m.add_wrapped(wrap_pyfunction!(buildhash)).unwrap();
|
||||
m.add_wrapped(wrap_pyfunction!(open_backend)).unwrap();
|
||||
|
@ -13,7 +13,6 @@ compile_all(
|
||||
group = "forms",
|
||||
visibility = [
|
||||
"//qt/aqt:__pkg__",
|
||||
"//qt/po:__pkg__",
|
||||
],
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user