mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
move backend.proto into rslib/
This commit is contained in:
parent
45ed97c56c
commit
e0817c004d
12 changed files with 117 additions and 102 deletions
2
proto/.gitignore
vendored
2
proto/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
fluent.proto
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
load("@rules_python//python:defs.bzl", "py_binary")
|
||||
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
|
||||
py_binary(
|
||||
name = "mypy_protobuf",
|
||||
srcs = [requirement("mypy-protobuf").replace(":pkg", ":mypy_protobuf.py")],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
deps = [requirement("mypy-protobuf")],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "protoc_wrapper",
|
||||
srcs = ["protoc_wrapper.py"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
deps = [
|
||||
":mypy_protobuf",
|
||||
"@rules_python//python/runfiles",
|
||||
],
|
||||
)
|
||||
|
||||
proto_library(
|
||||
name = "backend_proto_lib",
|
||||
srcs = ["backend.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
exports_files(["backend.proto"])
|
|
@ -1,44 +1,6 @@
|
|||
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
|
||||
py_binary(
|
||||
name = "genbackend",
|
||||
srcs = [
|
||||
"tools/genbackend.py",
|
||||
"//pylib/anki:backend_pb2",
|
||||
],
|
||||
imports = [
|
||||
".",
|
||||
],
|
||||
visibility = [":__subpackages__"],
|
||||
deps = [
|
||||
requirement("black"),
|
||||
requirement("stringcase"),
|
||||
requirement("protobuf"),
|
||||
],
|
||||
)
|
||||
|
||||
py_library(
|
||||
name = "hookslib",
|
||||
srcs = ["tools/hookslib.py"],
|
||||
imports = ["tools"],
|
||||
visibility = ["//qt:__pkg__"],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "genhooks",
|
||||
srcs = [
|
||||
"tools/genhooks.py",
|
||||
"tools/hookslib.py",
|
||||
],
|
||||
imports = ["."],
|
||||
visibility = [":__subpackages__"],
|
||||
deps = [
|
||||
requirement("black"),
|
||||
requirement("stringcase"),
|
||||
],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "pytest",
|
||||
srcs = glob(["tests/*.py"]),
|
||||
|
@ -86,10 +48,11 @@ py_test(
|
|||
|
||||
py_test(
|
||||
name = "format",
|
||||
srcs = glob([
|
||||
"anki/**/*.py",
|
||||
srcs = [
|
||||
"//pylib/tools:py_files",
|
||||
"//pylib/anki:py_files",
|
||||
] + glob([
|
||||
"tests/**/*.py",
|
||||
"tools/*.py",
|
||||
]),
|
||||
args = [
|
||||
"$(location .isort.cfg)",
|
||||
|
@ -97,7 +60,6 @@ py_test(
|
|||
data = [".isort.cfg"],
|
||||
main = "tests/run_format.py",
|
||||
deps = [
|
||||
"//pylib/anki",
|
||||
requirement("black"),
|
||||
requirement("isort"),
|
||||
],
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||
load("@rules_python//python:defs.bzl", "py_library")
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
load("//proto:defs.bzl", "py_proto_library_typed")
|
||||
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("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
||||
|
||||
copy_file(
|
||||
name = "buildinfo",
|
||||
|
@ -15,20 +14,20 @@ copy_file(
|
|||
genrule(
|
||||
name = "rsbackend_gen",
|
||||
outs = ["rsbackend_gen.py"],
|
||||
cmd = "$(location //pylib:genbackend) > $@",
|
||||
tools = ["//pylib:genbackend"],
|
||||
cmd = "$(location //pylib/tools:genbackend) > $@",
|
||||
tools = ["//pylib/tools:genbackend"],
|
||||
)
|
||||
|
||||
genrule(
|
||||
name = "hooks_gen",
|
||||
outs = ["hooks_gen.py"],
|
||||
cmd = "$(location //pylib:genhooks) $@",
|
||||
tools = ["//pylib:genhooks"],
|
||||
cmd = "$(location //pylib/tools:genhooks) $@",
|
||||
tools = ["//pylib/tools:genhooks"],
|
||||
)
|
||||
|
||||
py_proto_library_typed(
|
||||
name = "backend_pb2",
|
||||
src = "//proto:backend.proto",
|
||||
src = "//rslib:backend.proto",
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
|
@ -114,3 +113,9 @@ py_wheel(
|
|||
version = "0.0.1",
|
||||
deps = [":anki_pkg"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "py_files",
|
||||
srcs = glob(["**/*.py"]),
|
||||
visibility = ["//pylib:__subpackages__"],
|
||||
)
|
||||
|
|
|
@ -33,7 +33,7 @@ py_proto_library_typed = rule(
|
|||
"protoc_wrapper": attr.label(
|
||||
executable = True,
|
||||
cfg = "exec",
|
||||
default = Label("//proto:protoc_wrapper"),
|
||||
default = Label("//pylib/tools:protoc_wrapper"),
|
||||
),
|
||||
"protoc": attr.label(
|
||||
executable = True,
|
||||
|
@ -44,7 +44,7 @@ py_proto_library_typed = rule(
|
|||
"mypy_protobuf": attr.label(
|
||||
executable = True,
|
||||
cfg = "exec",
|
||||
default = Label("//proto:mypy_protobuf"),
|
||||
default = Label("//pylib/tools:mypy_protobuf"),
|
||||
),
|
||||
},
|
||||
)
|
|
@ -12,6 +12,7 @@ if __name__ == "__main__":
|
|||
args = []
|
||||
else:
|
||||
folder = os.path.join(os.path.dirname(__file__), "..")
|
||||
print(folder)
|
||||
os.chdir(folder)
|
||||
args = ["--diff", "--check"]
|
||||
|
||||
|
|
70
pylib/tools/BUILD.bazel
Normal file
70
pylib/tools/BUILD.bazel
Normal file
|
@ -0,0 +1,70 @@
|
|||
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
|
||||
load("@py_deps//:requirements.bzl", "requirement")
|
||||
|
||||
py_binary(
|
||||
name = "mypy_protobuf",
|
||||
srcs = [requirement("mypy-protobuf").replace(":pkg", ":mypy_protobuf.py")],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
deps = [requirement("mypy-protobuf")],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "protoc_wrapper",
|
||||
srcs = ["protoc_wrapper.py"],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
deps = [
|
||||
":mypy_protobuf",
|
||||
"@rules_python//python/runfiles",
|
||||
],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "genbackend",
|
||||
srcs = [
|
||||
"genbackend.py",
|
||||
"//pylib/anki:backend_pb2",
|
||||
],
|
||||
imports = [
|
||||
".",
|
||||
],
|
||||
visibility = ["//pylib:__subpackages__"],
|
||||
deps = [
|
||||
requirement("black"),
|
||||
requirement("stringcase"),
|
||||
requirement("protobuf"),
|
||||
],
|
||||
)
|
||||
|
||||
py_library(
|
||||
name = "hookslib",
|
||||
srcs = ["hookslib.py"],
|
||||
imports = ["."],
|
||||
visibility = [
|
||||
"//pylib:__subpackages__",
|
||||
"//qt:__pkg__",
|
||||
],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "genhooks",
|
||||
srcs = [
|
||||
"genhooks.py",
|
||||
"hookslib.py",
|
||||
],
|
||||
imports = ["."],
|
||||
visibility = ["//pylib:__subpackages__"],
|
||||
deps = [
|
||||
requirement("black"),
|
||||
requirement("stringcase"),
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "py_files",
|
||||
srcs = glob(["*.py"]),
|
||||
visibility = ["//pylib:__subpackages__"],
|
||||
)
|
|
@ -3,10 +3,10 @@
|
|||
# Wrapper for protoc that strips the dirname from the output files,
|
||||
# and generates mypy typechecking info.
|
||||
|
||||
import sys
|
||||
import subprocess
|
||||
import shutil
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
(protoc, mypy_protobuf, proto, outdir) = sys.argv[1:]
|
||||
|
||||
|
@ -20,15 +20,18 @@ pb2_py = without_ext + "_pb2.py"
|
|||
pb2_pyi = without_ext + "_pb2.pyi"
|
||||
|
||||
# invoke protoc
|
||||
subprocess.run([
|
||||
subprocess.run(
|
||||
[
|
||||
protoc,
|
||||
"--plugin=protoc-gen-mypy=" + mypy_protobuf,
|
||||
"--python_out=.",
|
||||
"--mypy_out=.",
|
||||
basename],
|
||||
basename,
|
||||
],
|
||||
# mypy prints to stderr on success :-(
|
||||
stderr=subprocess.DEVNULL,
|
||||
check=True)
|
||||
check=True,
|
||||
)
|
||||
|
||||
# move files into output
|
||||
shutil.move(pb2_py, outdir + "/" + pb2_py)
|
|
@ -9,7 +9,7 @@ py_binary(
|
|||
imports = ["."],
|
||||
visibility = [":__subpackages__"],
|
||||
deps = [
|
||||
"//pylib:hookslib",
|
||||
"//pylib/tools:hookslib",
|
||||
requirement("black"),
|
||||
requirement("stringcase"),
|
||||
],
|
||||
|
|
|
@ -25,15 +25,15 @@ cargo_build_script(
|
|||
name = "build_script",
|
||||
srcs = glob(["build/*.rs"]),
|
||||
build_script_env = {
|
||||
"BACKEND_PROTO": "$(execpath //proto:backend.proto)",
|
||||
"PROTOC": "$(execpath @com_google_protobuf//:protoc)",
|
||||
"FTL_FILES": "$(execpath ftl_files.list)",
|
||||
"BUILDINFO": "$(execpath //:buildinfo.txt)",
|
||||
"BACKEND_PROTO": "$(location backend.proto)",
|
||||
"PROTOC": "$(location @com_google_protobuf//:protoc)",
|
||||
"FTL_FILES": "$(location ftl_files.list)",
|
||||
"BUILDINFO": "$(location //:buildinfo.txt)",
|
||||
},
|
||||
crate_root = "build/main.rs",
|
||||
data = all_ftl_files + [
|
||||
"ftl_files.list",
|
||||
"//proto:backend.proto",
|
||||
"backend.proto",
|
||||
"//:buildinfo.txt",
|
||||
"@com_google_protobuf//:protoc",
|
||||
],
|
||||
|
@ -182,3 +182,11 @@ proto_library(
|
|||
srcs = ["fluent.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
proto_library(
|
||||
name = "backend_proto_lib",
|
||||
srcs = ["backend.proto"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
exports_files(["backend.proto"])
|
||||
|
|
|
@ -16,7 +16,7 @@ protobufjs_ts_library(
|
|||
protobufjs_ts_library(
|
||||
name = "backend_proto",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//proto:backend_proto_lib"],
|
||||
deps = ["//rslib:backend_proto_lib"],
|
||||
)
|
||||
|
||||
# Anki Library
|
||||
|
|
Loading…
Reference in a new issue