diff --git a/proto/.gitignore b/proto/.gitignore deleted file mode 100644 index e692b0dd8..000000000 --- a/proto/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -fluent.proto - diff --git a/proto/BUILD.bazel b/proto/BUILD.bazel deleted file mode 100644 index c6faa1341..000000000 --- a/proto/BUILD.bazel +++ /dev/null @@ -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"]) diff --git a/pylib/BUILD.bazel b/pylib/BUILD.bazel index a77bc575c..fd7039906 100644 --- a/pylib/BUILD.bazel +++ b/pylib/BUILD.bazel @@ -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"), ], diff --git a/pylib/anki/BUILD.bazel b/pylib/anki/BUILD.bazel index 46c55ecd7..d11c8ef42 100644 --- a/pylib/anki/BUILD.bazel +++ b/pylib/anki/BUILD.bazel @@ -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__"], +) diff --git a/proto/defs.bzl b/pylib/protobuf.bzl similarity index 92% rename from proto/defs.bzl rename to pylib/protobuf.bzl index 9c30bc5a6..c1c301ae3 100644 --- a/proto/defs.bzl +++ b/pylib/protobuf.bzl @@ -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"), ), }, ) diff --git a/pylib/tests/run_format.py b/pylib/tests/run_format.py index a5da0efc3..51268b273 100644 --- a/pylib/tests/run_format.py +++ b/pylib/tests/run_format.py @@ -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"] diff --git a/pylib/tools/BUILD.bazel b/pylib/tools/BUILD.bazel new file mode 100644 index 000000000..939c157a7 --- /dev/null +++ b/pylib/tools/BUILD.bazel @@ -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__"], +) diff --git a/proto/protoc_wrapper.py b/pylib/tools/protoc_wrapper.py similarity index 78% rename from proto/protoc_wrapper.py rename to pylib/tools/protoc_wrapper.py index 4f4ffec14..0c4b23dd8 100644 --- a/proto/protoc_wrapper.py +++ b/pylib/tools/protoc_wrapper.py @@ -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([ - protoc, - "--plugin=protoc-gen-mypy="+mypy_protobuf, - "--python_out=.", - "--mypy_out=.", - basename], +subprocess.run( + [ + protoc, + "--plugin=protoc-gen-mypy=" + mypy_protobuf, + "--python_out=.", + "--mypy_out=.", + 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) diff --git a/qt/BUILD.bazel b/qt/BUILD.bazel index 864fce01b..ca14f591a 100644 --- a/qt/BUILD.bazel +++ b/qt/BUILD.bazel @@ -9,7 +9,7 @@ py_binary( imports = ["."], visibility = [":__subpackages__"], deps = [ - "//pylib:hookslib", + "//pylib/tools:hookslib", requirement("black"), requirement("stringcase"), ], diff --git a/rslib/BUILD.bazel b/rslib/BUILD.bazel index 6552f7502..12fa6063f 100644 --- a/rslib/BUILD.bazel +++ b/rslib/BUILD.bazel @@ -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"]) diff --git a/proto/backend.proto b/rslib/backend.proto similarity index 100% rename from proto/backend.proto rename to rslib/backend.proto diff --git a/ts/lib/BUILD.bazel b/ts/lib/BUILD.bazel index 5b659287d..5294681d2 100644 --- a/ts/lib/BUILD.bazel +++ b/ts/lib/BUILD.bazel @@ -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