Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@ py_test(
shard_count = 2,
deps = ["@pypi_pytest//:pkg"],
)

py_test(
name = "absolute_main_test",
srcs = [
"__init__.py",
"main_test.py",
],
main = "//examples/pytest:main_test.py",
)

py_test(
name = "main_with_colon_test",
srcs = [
"__init__.py",
"main_test.py",
],
main = ":main_test.py",
)
Empty file added examples/pytest/__init__.py
Empty file.
1 change: 1 addition & 0 deletions examples/pytest/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print("loaded as main!")
5 changes: 2 additions & 3 deletions py/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ def _determine_main(ctx):
Artifact; the main file. If one can't be found, an error is raised.
"""
if ctx.attr.main:
# Deviation from rules_python: allow a leading colon, e.g. `main = ":my_target"`
proposed_main = ctx.attr.main.removeprefix(":")
proposed_main = ctx.attr.main.label.name
if not proposed_main.endswith(".py"):
fail("main {} must end in '.py'".format(proposed_main))
else:
Expand Down Expand Up @@ -87,7 +86,7 @@ determine_main = rule(
implementation = _determine_main_impl,
attrs = {
"target_name": attr.string(mandatory = True, doc = "The name of the py_binary or py_test we are finding a main for"),
"main": attr.string(doc = "Hint the user supplied as the main"),
"main": attr.label(doc = "Hint the user supplied as the main", allow_single_file = True),
"srcs": attr.label_list(allow_files = True),
},
)
Loading