expose binaries from pip

This commit is contained in:
Damien Elmes 2021-04-13 21:21:30 +10:00
parent 62423bd041
commit 07309a4c42
2 changed files with 42 additions and 0 deletions

View File

@ -1,5 +1,19 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement")
load(":binary.bzl", "pip_binary")
pip_binary(name = "black")
pip_binary(name = "isort")
pip_binary(name = "mypy")
pip_binary(name = "pylint")
pip_binary(
name = "protoc-gen-mypy",
pkg = "mypy-protobuf",
)
py_binary(
name = "update",

28
pip/binary.bzl Normal file
View File

@ -0,0 +1,28 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@py_deps//:requirements.bzl", "requirement")
def pip_binary(name, pkg = None):
"Expose a binary from pip as an executable for linting."
if not pkg:
pkg = name
binary_prefix = requirement(pkg).replace(":pkg", ":bin/" + name)
copy_file(
name = name + "_bin",
src = select({
"@platforms//os:windows": binary_prefix + ".exe",
"//conditions:default": binary_prefix,
}),
out = name + "_bin.py",
)
native.py_binary(
name = name,
srcs = [":" + name + "_bin.py"],
main = ":" + name + "_bin.py",
deps = [
requirement(pkg),
],
)