Skip to content

Python .zip in OutputGroupInfo is missing shebang line #17629

@fughilli

Description

@fughilli

Description of the bug:

The native py_binary implementation was amended in #9453 to export the zipped python executable in an OutputGroupInfo named python_zip_file. However, this archive is different than the one produced when building the py_binary with --build_python_zip, since it does not include the shebang line needed to make the stub execute when invoked on the command line. This is because the action that prepends the shebang is gated on the command line flag:
https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/bazel/rules/python/BazelPythonSemantics.java#L252

This code path should be amended such that the artifact in the output group is the same as the one produced when building with the flag (i.e., remove the gating on the flag and have the resulting artifact populate the OutputGroupInfo and optionally be output directly when the flag is provided).

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

main.py

print("hello world")

BUILD

filegroup(
name = "main_zip",
srcs = [":main"],
output_group = "python_zip_file",
)

py_binary(
name = "main",
srcs = ["main.py"],
)

Invoke:

bazel build :main_zip

Inspect:

hexdump -Cv bazel-bin/main.zip | head -n 10

Observe no shebang line.

Invoke:

bazel build :main --build_python_zip

Inspect:

hexdump -Cv bazel-bin/main | head -n 10

Observe a shebang line.

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

release 5.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions