mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
rspy -> pylib/rsbridge
This commit is contained in:
parent
ef5cd9f551
commit
45ed97c56c
22 changed files with 117 additions and 136 deletions
|
@ -42,9 +42,7 @@ py_binary(
|
||||||
py_test(
|
py_test(
|
||||||
name = "pytest",
|
name = "pytest",
|
||||||
srcs = glob(["tests/*.py"]),
|
srcs = glob(["tests/*.py"]),
|
||||||
data = glob(["tests/support/**"]) + [
|
data = glob(["tests/support/**"]),
|
||||||
"//rspy:ankirspy",
|
|
||||||
],
|
|
||||||
main = "tests/run_pytest.py",
|
main = "tests/run_pytest.py",
|
||||||
deps = [
|
deps = [
|
||||||
"//pylib/anki",
|
"//pylib/anki",
|
||||||
|
|
|
@ -3,6 +3,8 @@ load("@rules_python//python:defs.bzl", "py_library")
|
||||||
load("@py_deps//:requirements.bzl", "requirement")
|
load("@py_deps//:requirements.bzl", "requirement")
|
||||||
load("//proto:defs.bzl", "py_proto_library_typed")
|
load("//proto:defs.bzl", "py_proto_library_typed")
|
||||||
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("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||||
|
|
||||||
copy_file(
|
copy_file(
|
||||||
name = "buildinfo",
|
name = "buildinfo",
|
||||||
|
@ -40,6 +42,30 @@ py_proto_library_typed(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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",
|
||||||
|
"@io_bazel_rules_rust//rust/platform:i686-pc-windows-msvc",
|
||||||
|
): ":rsbridge_win",
|
||||||
|
"//conditions:default": ":rsbridge_unix",
|
||||||
|
}),
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
py_library(
|
py_library(
|
||||||
name = "anki",
|
name = "anki",
|
||||||
srcs = glob([
|
srcs = glob([
|
||||||
|
@ -52,11 +78,10 @@ py_library(
|
||||||
":fluent_pb2",
|
":fluent_pb2",
|
||||||
":hooks_gen",
|
":hooks_gen",
|
||||||
":rsbackend_gen",
|
":rsbackend_gen",
|
||||||
"//rspy:ankirspy",
|
":rsbridge",
|
||||||
],
|
],
|
||||||
imports = [
|
imports = [
|
||||||
"..",
|
"..",
|
||||||
"../../rspy",
|
|
||||||
],
|
],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -80,7 +105,6 @@ py_wheel(
|
||||||
distribution = "anki",
|
distribution = "anki",
|
||||||
python_tag = "py3",
|
python_tag = "py3",
|
||||||
requires = [
|
requires = [
|
||||||
"ankirspy (==2.1.35)",
|
|
||||||
"distro ; sys_platform != \"darwin\" and sys_platform != \"win32\"",
|
"distro ; sys_platform != \"darwin\" and sys_platform != \"win32\"",
|
||||||
],
|
],
|
||||||
strip_path_prefixes = [
|
strip_path_prefixes = [
|
||||||
|
|
|
@ -22,8 +22,7 @@ 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 ankirspy # pytype: disable=import-error
|
import anki._rsbridge
|
||||||
|
|
||||||
import anki.backend_pb2 as pb
|
import anki.backend_pb2 as pb
|
||||||
import anki.buildinfo
|
import anki.buildinfo
|
||||||
from anki import hooks
|
from anki import hooks
|
||||||
|
@ -45,7 +44,7 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
FormatTimeSpanContextValue = pb.FormatTimespanIn.ContextValue
|
FormatTimeSpanContextValue = pb.FormatTimespanIn.ContextValue
|
||||||
|
|
||||||
assert ankirspy.buildhash() == anki.buildinfo.buildhash
|
assert anki._rsbridge.buildhash() == anki.buildinfo.buildhash
|
||||||
|
|
||||||
SchedTimingToday = pb.SchedTimingTodayOut
|
SchedTimingToday = pb.SchedTimingTodayOut
|
||||||
BuiltinSortKind = pb.BuiltinSearchOrder.BuiltinSortKind
|
BuiltinSortKind = pb.BuiltinSearchOrder.BuiltinSortKind
|
||||||
|
@ -216,7 +215,7 @@ class RustBackend(RustBackendGenerated):
|
||||||
preferred_langs=langs,
|
preferred_langs=langs,
|
||||||
server=server,
|
server=server,
|
||||||
)
|
)
|
||||||
self._backend = ankirspy.open_backend(init_msg.SerializeToString())
|
self._backend = anki._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
|
||||||
|
|
|
@ -29,7 +29,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-ankirspy]
|
[mypy-anki._rsbridge]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-stringcase]
|
[mypy-stringcase]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
mypy==0.790
|
|
|
@ -1,4 +0,0 @@
|
||||||
[build-system]
|
|
||||||
# Minimum requirements for the build system to execute.
|
|
||||||
# https://stackoverflow.com/questions/48048745/setup-py-require-a-recent-version-of-setuptools-before-trying-to-install
|
|
||||||
requires = ["setuptools", "wheel"]
|
|
|
@ -1 +0,0 @@
|
||||||
protobuf==3.13.0
|
|
|
@ -1,8 +0,0 @@
|
||||||
wheel
|
|
||||||
mypy
|
|
||||||
mypy_protobuf>=1.21
|
|
||||||
black>=20.1b0
|
|
||||||
pytest>=6.0.1
|
|
||||||
pylint>=2.6.0
|
|
||||||
isort>=5.4.2
|
|
||||||
stringcase==1.2.0
|
|
1
rspy/.gitignore → pylib/rsbridge/.gitignore
vendored
1
rspy/.gitignore → pylib/rsbridge/.gitignore
vendored
|
@ -1,3 +1,2 @@
|
||||||
.build
|
|
||||||
target
|
target
|
||||||
Cargo.lock
|
Cargo.lock
|
50
pylib/rsbridge/BUILD.bazel
Normal file
50
pylib/rsbridge/BUILD.bazel
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_test")
|
||||||
|
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
||||||
|
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||||
|
load("//rslib:rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
|
||||||
|
|
||||||
|
cargo_build_script(
|
||||||
|
name = "build_script",
|
||||||
|
srcs = ["build.rs"],
|
||||||
|
)
|
||||||
|
|
||||||
|
rust_library(
|
||||||
|
name = "rsbridge",
|
||||||
|
srcs = ["lib.rs"],
|
||||||
|
crate_type = "cdylib",
|
||||||
|
data = [
|
||||||
|
"//:buildinfo.txt",
|
||||||
|
],
|
||||||
|
rustc_flags = selects.with_or({
|
||||||
|
(
|
||||||
|
"@io_bazel_rules_rust//rust/platform:x86_64-apple-darwin",
|
||||||
|
): [
|
||||||
|
"-Clink-arg=-undefined",
|
||||||
|
"-Clink-arg=dynamic_lookup",
|
||||||
|
"-Clink-arg=-mmacosx-version-min=10.7",
|
||||||
|
],
|
||||||
|
"//conditions:default": [],
|
||||||
|
}),
|
||||||
|
visibility = [
|
||||||
|
"//pylib:__subpackages__",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":build_script",
|
||||||
|
"//cargo:pyo3",
|
||||||
|
"//rslib:anki",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
rustfmt_test(
|
||||||
|
name = "format",
|
||||||
|
srcs = glob([
|
||||||
|
"*.rs",
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
|
||||||
|
rustfmt_fix(
|
||||||
|
name = "format_fix",
|
||||||
|
srcs = glob([
|
||||||
|
"*.rs",
|
||||||
|
]),
|
||||||
|
)
|
|
@ -1,14 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ankirspy"
|
name = "rsbackend"
|
||||||
version = "2.1.36" # automatically updated
|
version = "0.0.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
authors = ["Ankitects Pty Ltd and contributors <https://help.ankiweb.net>"]
|
authors = ["Ankitects Pty Ltd and contributors <https://help.ankiweb.net>"]
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
description = "Anki's Rust library code Python bindings"
|
description = "Anki's Rust library code Python bindings"
|
||||||
readme = "README.md"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anki = { path = "../rslib" }
|
anki = { path = "../../rslib" }
|
||||||
|
|
||||||
[dependencies.pyo3]
|
[dependencies.pyo3]
|
||||||
version = "0.11.0"
|
version = "0.11.0"
|
||||||
|
@ -17,12 +16,13 @@ features = ["extension-module"]
|
||||||
[lib]
|
[lib]
|
||||||
name = "ankirspy"
|
name = "ankirspy"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
path = "lib.rs"
|
||||||
|
|
||||||
[profile.dev]
|
#[profile.dev]
|
||||||
opt-level = 2
|
#opt-level = 2
|
||||||
debug = 0
|
#debug = 0
|
||||||
codegen-units = 256
|
#codegen-units = 256
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
#[profile.dev.package."*"]
|
||||||
opt-level = 3
|
#opt-level = 3
|
||||||
codegen-units = 16
|
#codegen-units = 16
|
|
@ -6,4 +6,4 @@ fn main() {
|
||||||
let path = std::path::Path::new(&path).with_file_name("libs");
|
let path = std::path::Path::new(&path).with_file_name("libs");
|
||||||
println!("cargo:rustc-link-search={}", path.to_str().unwrap());
|
println!("cargo:rustc-link-search={}", path.to_str().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ struct Backend {
|
||||||
backend: RustBackend,
|
backend: RustBackend,
|
||||||
}
|
}
|
||||||
|
|
||||||
create_exception!(ankirspy, BackendError, Exception);
|
create_exception!(_rsbridge, BackendError, Exception);
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn buildhash() -> &'static str {
|
fn buildhash() -> &'static str {
|
||||||
|
@ -33,25 +33,27 @@ fn open_backend(init_msg: &PyBytes) -> PyResult<Backend> {
|
||||||
|
|
||||||
fn want_release_gil(method: u32) -> bool {
|
fn want_release_gil(method: u32) -> bool {
|
||||||
if let Ok(method) = BackendMethod::try_from(method) {
|
if let Ok(method) = BackendMethod::try_from(method) {
|
||||||
!matches!(method,
|
!matches!(
|
||||||
|
method,
|
||||||
BackendMethod::ExtractAVTags
|
BackendMethod::ExtractAVTags
|
||||||
| BackendMethod::ExtractLatex
|
| BackendMethod::ExtractLatex
|
||||||
| BackendMethod::RenderExistingCard
|
| BackendMethod::RenderExistingCard
|
||||||
| BackendMethod::RenderUncommittedCard
|
| BackendMethod::RenderUncommittedCard
|
||||||
| BackendMethod::StripAVTags
|
| BackendMethod::StripAVTags
|
||||||
| BackendMethod::LocalMinutesWest
|
| BackendMethod::LocalMinutesWest
|
||||||
| BackendMethod::SchedTimingToday
|
| BackendMethod::SchedTimingToday
|
||||||
| BackendMethod::AddOrUpdateDeckLegacy
|
| BackendMethod::AddOrUpdateDeckLegacy
|
||||||
| BackendMethod::NewDeckLegacy
|
| BackendMethod::NewDeckLegacy
|
||||||
| BackendMethod::NewDeckConfigLegacy
|
| BackendMethod::NewDeckConfigLegacy
|
||||||
| BackendMethod::GetStockNotetypeLegacy
|
| BackendMethod::GetStockNotetypeLegacy
|
||||||
| BackendMethod::SetLocalMinutesWest
|
| BackendMethod::SetLocalMinutesWest
|
||||||
| BackendMethod::StudiedToday
|
| BackendMethod::StudiedToday
|
||||||
| BackendMethod::TranslateString
|
| BackendMethod::TranslateString
|
||||||
| BackendMethod::FormatTimespan
|
| BackendMethod::FormatTimespan
|
||||||
| BackendMethod::LatestProgress
|
| BackendMethod::LatestProgress
|
||||||
| BackendMethod::SetWantsAbort
|
| BackendMethod::SetWantsAbort
|
||||||
| BackendMethod::I18nResources)
|
| BackendMethod::I18nResources
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -92,7 +94,7 @@ impl Backend {
|
||||||
//////////////////////////////////
|
//////////////////////////////////
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
fn ankirspy(_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();
|
|
@ -29,7 +29,6 @@ py_test(
|
||||||
srcs = glob(["tests/*.py"]),
|
srcs = glob(["tests/*.py"]),
|
||||||
data = [
|
data = [
|
||||||
"//qt/aqt_data",
|
"//qt/aqt_data",
|
||||||
"//rspy:ankirspy",
|
|
||||||
],
|
],
|
||||||
main = "tests/run_pytest.py",
|
main = "tests/run_pytest.py",
|
||||||
deps = [
|
deps = [
|
||||||
|
|
|
@ -41,10 +41,6 @@ py_library(
|
||||||
"py.typed",
|
"py.typed",
|
||||||
":hooks_gen",
|
":hooks_gen",
|
||||||
],
|
],
|
||||||
imports = [
|
|
||||||
# "..",
|
|
||||||
"../../rspy",
|
|
||||||
],
|
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
requirement("protobuf"),
|
requirement("protobuf"),
|
||||||
|
|
|
@ -42,7 +42,7 @@ ignore_missing_imports = True
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-jsonschema.*]
|
[mypy-jsonschema.*]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-ankirspy]
|
[mypy-anki._rsbridge]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
[mypy-PyQt5.sip]
|
[mypy-PyQt5.sip]
|
||||||
ignore_missing_imports = True
|
ignore_missing_imports = True
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
[target.'cfg(target_os="macos")']
|
|
||||||
rustflags = ["-Clink-arg=-mmacosx-version-min=10.7"]
|
|
|
@ -1,67 +0,0 @@
|
||||||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library", "rust_test")
|
|
||||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
|
||||||
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
|
||||||
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
|
||||||
|
|
||||||
cargo_build_script(
|
|
||||||
name = "build_script",
|
|
||||||
srcs = ["build.rs"],
|
|
||||||
)
|
|
||||||
|
|
||||||
rust_library(
|
|
||||||
name = "ankirspy_lib",
|
|
||||||
srcs = glob([
|
|
||||||
"src/**/*.rs",
|
|
||||||
]),
|
|
||||||
crate_type = "cdylib",
|
|
||||||
data = [
|
|
||||||
"//:buildinfo.txt",
|
|
||||||
],
|
|
||||||
rustc_flags = selects.with_or({
|
|
||||||
(
|
|
||||||
"@io_bazel_rules_rust//rust/platform:x86_64-apple-darwin",
|
|
||||||
): [
|
|
||||||
"-Clink-arg=-undefined",
|
|
||||||
"-Clink-arg=dynamic_lookup",
|
|
||||||
"-Clink-arg=-mmacosx-version-min=10.7",
|
|
||||||
],
|
|
||||||
"//conditions:default": [],
|
|
||||||
}),
|
|
||||||
deps = [
|
|
||||||
":build_script",
|
|
||||||
"//cargo:pyo3",
|
|
||||||
"//rslib:anki",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
# a binary target so that test //rspy/... runs clippy
|
|
||||||
rust_test(
|
|
||||||
name = "rspy_test",
|
|
||||||
srcs = ["empty.rs"],
|
|
||||||
deps = [":ankirspy_lib"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# rename lib file for Python
|
|
||||||
copy_file(
|
|
||||||
name = "ankirspy_unix",
|
|
||||||
src = ":ankirspy_lib",
|
|
||||||
out = "ankirspy.so",
|
|
||||||
)
|
|
||||||
|
|
||||||
copy_file(
|
|
||||||
name = "ankirspy_win",
|
|
||||||
src = ":ankirspy_lib",
|
|
||||||
out = "ankirspy.pyd",
|
|
||||||
)
|
|
||||||
|
|
||||||
alias(
|
|
||||||
name = "ankirspy",
|
|
||||||
actual = selects.with_or({
|
|
||||||
(
|
|
||||||
"@io_bazel_rules_rust//rust/platform:x86_64-pc-windows-msvc",
|
|
||||||
"@io_bazel_rules_rust//rust/platform:i686-pc-windows-msvc",
|
|
||||||
): ":ankirspy_win",
|
|
||||||
"//conditions:default": ":ankirspy_unix",
|
|
||||||
}),
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
|
@ -1 +0,0 @@
|
||||||
To build from scratch, please see https://github.com/ankitects/anki
|
|
|
@ -1 +0,0 @@
|
||||||
maturin>=0.8.0
|
|
|
@ -1 +0,0 @@
|
||||||
stable
|
|
Loading…
Reference in a new issue