Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ A brief description of the categories of changes:
`interpreter_version_info` arg.
* (bzlmod) Correctly pass `isolated`, `quiet` and `timeout` values to `whl_library`
and drop the defaults from the lock file.
* (rules) The first element of the default outputs is now the executable again.

### Removed
* (pip): Removes the `entrypoint` macro that was replaced by `py_console_script_binary` in 0.26.0.
Expand Down
5 changes: 3 additions & 2 deletions python/private/common/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment =
main_py = precompile_result.py_to_pyc_map[main_py]
direct_pyc_files = depset(precompile_result.pyc_files)

default_outputs = precompile_result.keep_srcs + precompile_result.pyc_files
executable = _declare_executable_file(ctx)
default_outputs.append(executable)
default_outputs = [executable]
default_outputs.extend(precompile_result.keep_srcs)
default_outputs.extend(precompile_result.pyc_files)

imports = collect_imports(ctx, semantics)

Expand Down
11 changes: 11 additions & 0 deletions tests/base_rules/py_executable_base_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ load("@rules_python_internal//:rules_python_config.bzl", rp_config = "config")
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
load("@rules_testing//lib:truth.bzl", "matching")
load("@rules_testing//lib:util.bzl", rt_util = "util")
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
load("//tests/base_rules:base_tests.bzl", "create_base_tests")
load("//tests/base_rules:util.bzl", "WINDOWS_ATTR", pt_util = "util")
load("//tests/support:support.bzl", "LINUX_X86_64", "WINDOWS_X86_64")
Expand Down Expand Up @@ -297,6 +298,16 @@ def _test_files_to_build_impl(env, target):
"{package}/{test_name}_subject.py",
])

if IS_BAZEL_7_OR_HIGHER:
# As of Bazel 7, the first default output is the executable, so
# verify that is the case. rules_testing
# DepsetFileSubject.contains_exactly doesn't provide an in_order()
# call, nor access to the underlying depset, so we have to do things
# manually.
first_default_output = target[DefaultInfo].files.to_list()[0]
executable = target[DefaultInfo].files_to_run.executable
env.expect.that_file(first_default_output).equals(executable)

def _test_name_cannot_end_in_py(name, config):
# Bazel 5 will crash with a Java stacktrace when the native Python
# rules have an error.
Expand Down