Knock together a handy py_project macro
This commit is contained in:
parent
6c6b0a060f
commit
4d8cd34cbc
2 changed files with 101 additions and 66 deletions
|
@ -6,6 +6,7 @@ load("//tools/python:defs.bzl",
|
||||||
"py_unittest",
|
"py_unittest",
|
||||||
"py_pytest",
|
"py_pytest",
|
||||||
"py_resources",
|
"py_resources",
|
||||||
|
"py_project",
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@arrdem_source_pypi//:requirements.bzl",
|
load("@arrdem_source_pypi//:requirements.bzl",
|
||||||
|
|
|
@ -144,3 +144,37 @@ py_resources = rule(
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def py_project(name=None,
|
||||||
|
lib_srcs=None,
|
||||||
|
lib_deps=None,
|
||||||
|
test_srcs=None,
|
||||||
|
test_deps=None):
|
||||||
|
"""
|
||||||
|
A helper for defining conventionally-formatted python project.
|
||||||
|
|
||||||
|
Assumes that there's a src/python tree, and a src/test tree.
|
||||||
|
|
||||||
|
Each test_*.py source generates its own implicit test target. This allows
|
||||||
|
for automatic test parallelism.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
lib_srcs = lib_srcs or native.glob(["src/python/**/*.py"])
|
||||||
|
test_srcs = test_srcs or native.glob(["test/python/**/*.py"])
|
||||||
|
|
||||||
|
py_library(
|
||||||
|
name=name,
|
||||||
|
srcs=lib_srcs,
|
||||||
|
deps=lib_deps,
|
||||||
|
imports=["src/python"],
|
||||||
|
)
|
||||||
|
|
||||||
|
for src in test_srcs:
|
||||||
|
if "test_" in src:
|
||||||
|
py_pytest(
|
||||||
|
name=name + ".test." + str(hash(src)).replace("-", "") + "." + src.split("/")[-1],
|
||||||
|
srcs=test_srcs,
|
||||||
|
deps=[name] + test_deps,
|
||||||
|
imports=["test/python"],
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue