From 385cd9d83e37ce93d825e15ac85c85962895d834 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sat, 21 Aug 2021 17:18:46 -0600 Subject: [PATCH] Add support for runnable projects --- tools/python/defs.bzl | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/python/defs.bzl b/tools/python/defs.bzl index edc4a91..3c38621 100644 --- a/tools/python/defs.bzl +++ b/tools/python/defs.bzl @@ -146,6 +146,7 @@ py_resources = rule( ) def py_project(name=None, + main=None, lib_srcs=None, lib_deps=None, lib_data=None, @@ -184,8 +185,10 @@ def py_project(name=None, "**/*.pyc", ]) + lib_name = name if not main else "lib" + py_library( - name=name, + name=lib_name, srcs=lib_srcs, deps=lib_deps, data=lib_data, @@ -198,12 +201,28 @@ def py_project(name=None, ], ) + if main: + py_binary( + name = name, + main = main, + imports=[ + "src/python", + "src/resources", + ], + deps=[ + lib_name, + ], + visibility = [ + "//visibility:public", + ], + ) + for src in test_srcs: if "test_" in src: py_pytest( name=src.split("/")[-1], srcs=[src] + [f for f in test_srcs if "test_" not in f], - deps=[name] + (test_deps or []), + deps=[lib_name] + (test_deps or []), data=test_data, imports=[ "test/python",