Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix absolute label use in main attribute of py_test #463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ py_test(
"@pypi_pytest//:pkg",
],
)

py_test(
name = "absolute_main_test",
srcs = [
# 2 files required
"__init__.py",
"main_test.py",
],
main = "//examples/pytest: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!")
4 changes: 2 additions & 2 deletions py/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _determine_main(ctx):
"""
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.removeprefix(":")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think label.name will ever have a : as prefix. maybe we are really missing something here?

if not proposed_main.endswith(".py"):
fail("main {} must end in '.py'".format(proposed_main))
else:
Expand Down Expand Up @@ -87,7 +87,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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change as Alex pointed out, so i am not sure if we can land it as a minor.

"srcs": attr.label_list(allow_files = True),
},
)
Loading