Skip to content

feat: add shebang attribute on py_console_script_binary #2867

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

chrisirhc
Copy link
Contributor

@chrisirhc chrisirhc commented May 8, 2025

Background

Use case: user is setting up the environment for a docker image, and needs a bash executable from the py_console_script (e.g. to run ray from command line without full bazel bootstrapping). User is responsible of setting up the right paths (and hermeticity concerns). There's no change in default behavior per this diff.

Previously, prior to Bazel mod, this was possible and simple through the use of rules_python_wheel_entry_points (per here) but these are not reachable now via Bazel mod.

Approach

Add a shebang attribute that allows users of the console binary to use it like a binary executable.

This is similar to the functionality that came with wheel entry points here:

With this change, one can specify a shebang like:

py_console_script_binary(
    name = "yamllint",
    pkg = "@pip//yamllint",
    shebang = "#!/usr/bin/env python3",
)

TODOs:

  • Update tests
  • Add test for this functionality
  • Leave default to without shebang so this is a non-breaking change
  • Documentation (want to hear more about the general approach first, and also want to hear whether this warrants specific docs, or can just leave it to API docs)

):
"""Run the generator

Args:
entry_points: The entry_points.txt file to be parsed.
out: The output file.
console_script: The console_script entry in the entry_points.txt file.
console_script_guess: The string used for guessing the console_script if it is not provided.
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused?

Copy link
Contributor Author

@chrisirhc chrisirhc May 9, 2025

Choose a reason for hiding this comment

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

Hm what do you mean?
This was a previously undocumented arg. I thought it seems reasonable to document it to maintain the order of arguments, and for consisency.

@chrisirhc chrisirhc marked this pull request as ready for review May 9, 2025 03:24
@chrisirhc chrisirhc requested review from rickeylev and aignas as code owners May 9, 2025 03:24
@chrisirhc chrisirhc changed the title WIP add custom shebang on py_console_script_binary shebang on py_console_script_binary May 9, 2025
@chrisirhc chrisirhc changed the title shebang on py_console_script_binary feat: shebang on py_console_script_binary May 9, 2025
@chrisirhc chrisirhc changed the title feat: shebang on py_console_script_binary feat: add shebang attribute on py_console_script_binary May 9, 2025
@aignas
Copy link
Collaborator

aignas commented May 9, 2025

I don't fully understand the intention.

  • Doesn't shebang doesn't ever get used because we have the bootstrap script?
  • If we put the actual python path, then it will be non-hermetic, if the shebang is an absolute path?
  • If we are using /env/usr/bin python then it is UNIX specific and non hermetic?

@chrisirhc
Copy link
Contributor Author

chrisirhc commented May 9, 2025

I don't fully understand the intention.

  • Doesn't shebang doesn't ever get used because we have the bootstrap script?
  • If we put the actual python path, then it will be non-hermetic, if the shebang is an absolute path?
  • If we are using /env/usr/bin python then it is UNIX specific and non hermetic?

Use case: user is setting up the environment for a docker image, and needs a bash executable from the py_console_script target to run ray from command line without full bazel bootstrapping (an entry point in the ray dep). User is responsible of setting up the right paths and make sure the shebang points to a known available path (and hermeticity concerns).
There's no change in default behavior per this diff, which is that there's no shebang.

Previously, prior to Bazel mod, this was possible and simple through the use of rules_python_wheel_entry_points (per here) but these are not reachable now via Bazel mod.

Similar to the intention specified via PEP 441 for shebang line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants