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("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
|
||||||
load("@py_deps//:requirements.bzl", "requirement")
|
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(
|
py_test(
|
||||||
name = "pytest",
|
name = "pytest",
|
||||||
srcs = glob(["tests/*.py"]),
|
srcs = glob(["tests/*.py"]),
|
||||||
|
@ -86,10 +48,11 @@ py_test(
|
||||||
|
|
||||||
py_test(
|
py_test(
|
||||||
name = "format",
|
name = "format",
|
||||||
srcs = glob([
|
srcs = [
|
||||||
"anki/**/*.py",
|
"//pylib/tools:py_files",
|
||||||
|
"//pylib/anki:py_files",
|
||||||
|
] + glob([
|
||||||
"tests/**/*.py",
|
"tests/**/*.py",
|
||||||
"tools/*.py",
|
|
||||||
]),
|
]),
|
||||||
args = [
|
args = [
|
||||||
"$(location .isort.cfg)",
|
"$(location .isort.cfg)",
|
||||||
|
@ -97,7 +60,6 @@ py_test(
|
||||||
data = [".isort.cfg"],
|
data = [".isort.cfg"],
|
||||||
main = "tests/run_format.py",
|
main = "tests/run_format.py",
|
||||||
deps = [
|
deps = [
|
||||||
"//pylib/anki",
|
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("isort"),
|
requirement("isort"),
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
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("//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("@rules_python//experimental/python:wheel.bzl", "py_package", "py_wheel")
|
||||||
load("@bazel_skylib//lib:selects.bzl", "selects")
|
load("@bazel_skylib//lib:selects.bzl", "selects")
|
||||||
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
|
|
||||||
|
|
||||||
copy_file(
|
copy_file(
|
||||||
name = "buildinfo",
|
name = "buildinfo",
|
||||||
|
@ -15,20 +14,20 @@ copy_file(
|
||||||
genrule(
|
genrule(
|
||||||
name = "rsbackend_gen",
|
name = "rsbackend_gen",
|
||||||
outs = ["rsbackend_gen.py"],
|
outs = ["rsbackend_gen.py"],
|
||||||
cmd = "$(location //pylib:genbackend) > $@",
|
cmd = "$(location //pylib/tools:genbackend) > $@",
|
||||||
tools = ["//pylib:genbackend"],
|
tools = ["//pylib/tools:genbackend"],
|
||||||
)
|
)
|
||||||
|
|
||||||
genrule(
|
genrule(
|
||||||
name = "hooks_gen",
|
name = "hooks_gen",
|
||||||
outs = ["hooks_gen.py"],
|
outs = ["hooks_gen.py"],
|
||||||
cmd = "$(location //pylib:genhooks) $@",
|
cmd = "$(location //pylib/tools:genhooks) $@",
|
||||||
tools = ["//pylib:genhooks"],
|
tools = ["//pylib/tools:genhooks"],
|
||||||
)
|
)
|
||||||
|
|
||||||
py_proto_library_typed(
|
py_proto_library_typed(
|
||||||
name = "backend_pb2",
|
name = "backend_pb2",
|
||||||
src = "//proto:backend.proto",
|
src = "//rslib:backend.proto",
|
||||||
visibility = [
|
visibility = [
|
||||||
"//visibility:public",
|
"//visibility:public",
|
||||||
],
|
],
|
||||||
|
@ -114,3 +113,9 @@ py_wheel(
|
||||||
version = "0.0.1",
|
version = "0.0.1",
|
||||||
deps = [":anki_pkg"],
|
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(
|
"protoc_wrapper": attr.label(
|
||||||
executable = True,
|
executable = True,
|
||||||
cfg = "exec",
|
cfg = "exec",
|
||||||
default = Label("//proto:protoc_wrapper"),
|
default = Label("//pylib/tools:protoc_wrapper"),
|
||||||
),
|
),
|
||||||
"protoc": attr.label(
|
"protoc": attr.label(
|
||||||
executable = True,
|
executable = True,
|
||||||
|
@ -44,7 +44,7 @@ py_proto_library_typed = rule(
|
||||||
"mypy_protobuf": attr.label(
|
"mypy_protobuf": attr.label(
|
||||||
executable = True,
|
executable = True,
|
||||||
cfg = "exec",
|
cfg = "exec",
|
||||||
default = Label("//proto:mypy_protobuf"),
|
default = Label("//pylib/tools:mypy_protobuf"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
|
@ -12,6 +12,7 @@ if __name__ == "__main__":
|
||||||
args = []
|
args = []
|
||||||
else:
|
else:
|
||||||
folder = os.path.join(os.path.dirname(__file__), "..")
|
folder = os.path.join(os.path.dirname(__file__), "..")
|
||||||
|
print(folder)
|
||||||
os.chdir(folder)
|
os.chdir(folder)
|
||||||
args = ["--diff", "--check"]
|
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,
|
# Wrapper for protoc that strips the dirname from the output files,
|
||||||
# and generates mypy typechecking info.
|
# and generates mypy typechecking info.
|
||||||
|
|
||||||
import sys
|
|
||||||
import subprocess
|
|
||||||
import shutil
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
(protoc, mypy_protobuf, proto, outdir) = sys.argv[1:]
|
(protoc, mypy_protobuf, proto, outdir) = sys.argv[1:]
|
||||||
|
|
||||||
|
@ -20,15 +20,18 @@ pb2_py = without_ext + "_pb2.py"
|
||||||
pb2_pyi = without_ext + "_pb2.pyi"
|
pb2_pyi = without_ext + "_pb2.pyi"
|
||||||
|
|
||||||
# invoke protoc
|
# invoke protoc
|
||||||
subprocess.run([
|
subprocess.run(
|
||||||
|
[
|
||||||
protoc,
|
protoc,
|
||||||
"--plugin=protoc-gen-mypy="+mypy_protobuf,
|
"--plugin=protoc-gen-mypy=" + mypy_protobuf,
|
||||||
"--python_out=.",
|
"--python_out=.",
|
||||||
"--mypy_out=.",
|
"--mypy_out=.",
|
||||||
basename],
|
basename,
|
||||||
|
],
|
||||||
# mypy prints to stderr on success :-(
|
# mypy prints to stderr on success :-(
|
||||||
stderr=subprocess.DEVNULL,
|
stderr=subprocess.DEVNULL,
|
||||||
check=True)
|
check=True,
|
||||||
|
)
|
||||||
|
|
||||||
# move files into output
|
# move files into output
|
||||||
shutil.move(pb2_py, outdir + "/" + pb2_py)
|
shutil.move(pb2_py, outdir + "/" + pb2_py)
|
|
@ -9,7 +9,7 @@ py_binary(
|
||||||
imports = ["."],
|
imports = ["."],
|
||||||
visibility = [":__subpackages__"],
|
visibility = [":__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pylib:hookslib",
|
"//pylib/tools:hookslib",
|
||||||
requirement("black"),
|
requirement("black"),
|
||||||
requirement("stringcase"),
|
requirement("stringcase"),
|
||||||
],
|
],
|
||||||
|
|
|
@ -25,15 +25,15 @@ cargo_build_script(
|
||||||
name = "build_script",
|
name = "build_script",
|
||||||
srcs = glob(["build/*.rs"]),
|
srcs = glob(["build/*.rs"]),
|
||||||
build_script_env = {
|
build_script_env = {
|
||||||
"BACKEND_PROTO": "$(execpath //proto:backend.proto)",
|
"BACKEND_PROTO": "$(location backend.proto)",
|
||||||
"PROTOC": "$(execpath @com_google_protobuf//:protoc)",
|
"PROTOC": "$(location @com_google_protobuf//:protoc)",
|
||||||
"FTL_FILES": "$(execpath ftl_files.list)",
|
"FTL_FILES": "$(location ftl_files.list)",
|
||||||
"BUILDINFO": "$(execpath //:buildinfo.txt)",
|
"BUILDINFO": "$(location //:buildinfo.txt)",
|
||||||
},
|
},
|
||||||
crate_root = "build/main.rs",
|
crate_root = "build/main.rs",
|
||||||
data = all_ftl_files + [
|
data = all_ftl_files + [
|
||||||
"ftl_files.list",
|
"ftl_files.list",
|
||||||
"//proto:backend.proto",
|
"backend.proto",
|
||||||
"//:buildinfo.txt",
|
"//:buildinfo.txt",
|
||||||
"@com_google_protobuf//:protoc",
|
"@com_google_protobuf//:protoc",
|
||||||
],
|
],
|
||||||
|
@ -182,3 +182,11 @@ proto_library(
|
||||||
srcs = ["fluent.proto"],
|
srcs = ["fluent.proto"],
|
||||||
visibility = ["//visibility:public"],
|
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(
|
protobufjs_ts_library(
|
||||||
name = "backend_proto",
|
name = "backend_proto",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = ["//proto:backend_proto_lib"],
|
deps = ["//rslib:backend_proto_lib"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Anki Library
|
# Anki Library
|
||||||
|
|
Loading…
Reference in a new issue