Skip to content

Commit 74419ae

Browse files
committed
allow srcs in py_console_script_binary when using py_test as the binary
1 parent ca91cea commit 74419ae

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

python/private/py_console_script_binary.bzl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Implementation for the macro to generate a console_script py_binary from an 'ent
1717
"""
1818

1919
load("//python:py_binary.bzl", "py_binary")
20+
load("//python:py_test.bzl", "py_test")
2021
load(":py_console_script_gen.bzl", "py_console_script_gen")
2122

2223
def _dist_info(pkg):
@@ -72,8 +73,14 @@ def py_console_script_binary(
7273
"""
7374
main = "rules_python_entry_point_{}.py".format(name)
7475

75-
if kwargs.pop("srcs", None):
76+
srcs = kwargs.pop("srcs", [])
77+
78+
if binary_rule == py_test:
79+
srcs = srcs + [main]
80+
elif srcs:
7681
fail("passing 'srcs' attribute to py_console_script_binary is unsupported")
82+
else:
83+
srcs = [main]
7784

7885
py_console_script_gen(
7986
name = "_{}_gen".format(name),
@@ -86,7 +93,7 @@ def py_console_script_binary(
8693

8794
binary_rule(
8895
name = name,
89-
srcs = [main],
96+
srcs = srcs,
9097
main = main,
9198
deps = [pkg] + kwargs.pop("deps", []),
9299
**kwargs

0 commit comments

Comments
 (0)