@@ -18,7 +18,7 @@ _a_struct_type = type(struct())
18
18
_a_string_type = type ("" )
19
19
20
20
def _py_binary_or_test (name , rule , srcs , main , imports , deps = [], resolutions = {}, ** kwargs ):
21
- # Compatibility with rules_python, see docs on find_main
21
+ # Compatibility with rules_python, see docs in py_executable.bzl
22
22
main_target = "_{}.find_main" .format (name )
23
23
determine_main (
24
24
name = main_target ,
@@ -56,8 +56,10 @@ def py_binary(name, srcs = [], main = None, imports = ["."], resolutions = {}, *
56
56
Args:
57
57
name: name of the rule
58
58
srcs: python source files
59
- main: the entry point. If absent, then the first entry in srcs is used. If srcs is non-empty,
60
- then this is treated as a suffix of a file that should appear among the srcs.
59
+ main: the entry point.
60
+ Like rules_python, this is treated as a suffix of a file that should appear among the srcs.
61
+ If absent, then "[name].py" is tried. As a final fallback, if the srcs has a single file,
62
+ that is used as the main.
61
63
imports: List of import paths to add for this binary.
62
64
resolutions: FIXME
63
65
**kwargs: additional named parameters to the py_binary_rule
@@ -89,6 +91,8 @@ def py_binary(name, srcs = [], main = None, imports = ["."], resolutions = {}, *
89
91
90
92
def py_test (name , main = None , srcs = [], imports = ["." ], ** kwargs ):
91
93
"Identical to py_binary, but produces a target that can be used with `bazel test`."
94
+
95
+ # Ensure that any other targets we write will be testonly like the py_test target
92
96
kwargs ["testonly" ] = True
93
97
_py_binary_or_test (name = name , rule = _py_test , srcs = srcs , main = main , imports = imports , ** kwargs )
94
98
0 commit comments