Skip to content

Commit 4e4153f

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

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

python/private/py_console_script_binary.bzl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Implementation for the macro to generate a console_script py_binary from an 'entry_points.txt' config.
1717
"""
1818

19-
load("//python:py_binary.bzl", "py_binary")
19+
load("//python:py_binary.bzl", "py_binary", "py_test")
2020
load(":py_console_script_gen.bzl", "py_console_script_gen")
2121

2222
def _dist_info(pkg):
@@ -72,8 +72,14 @@ def py_console_script_binary(
7272
"""
7373
main = "rules_python_entry_point_{}.py".format(name)
7474

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

7884
py_console_script_gen(
7985
name = "_{}_gen".format(name),
@@ -86,7 +92,7 @@ def py_console_script_binary(
8692

8793
binary_rule(
8894
name = name,
89-
srcs = [main],
95+
srcs = srcs,
9096
main = main,
9197
deps = [pkg] + kwargs.pop("deps", []),
9298
**kwargs

0 commit comments

Comments
 (0)