Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support src-less invocation of py_binary #2765

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

Closed
aignas opened this issue Apr 10, 2025 · 3 comments · Fixed by #2768
Closed

Support src-less invocation of py_binary #2765

aignas opened this issue Apr 10, 2025 · 3 comments · Fixed by #2768

Comments

@aignas
Copy link
Collaborator

aignas commented Apr 10, 2025

With the recent addition of the #2671, I find that in most cases I can replace the py_console_script_binary with just a py_binary, e.g:

py_console_script_binary(
    name = "foo",
    deps = [...],
    pkg = "foo",
    script = "bar",
)

versus

py_binary(
    name = "foo",
    deps = [...], # assuming "foo" is in the deps
    main_module = "bar"
)

However I cannot do this, because the srcs cannot be empty here.

An alternative to this could be to use the python_interpreter introduced in #2507

interpreter_binary(
    name = "foo",
    deps = [...],
    args = ["-m", "foo"],
)
@rickeylev
Copy link
Collaborator

This sounds like a bug. I changed srcs to no longer be mandatory as part of adding the main module attribute so that such a case could work

@aignas
Copy link
Collaborator Author

aignas commented Apr 10, 2025

Let me double check.

@aignas
Copy link
Collaborator Author

aignas commented Apr 10, 2025

OK, it works if I pass srcs = []. So the attribute specification is mandatory, but the list can be empty. That is a little bit of a rough corner.

aignas added a commit to aignas/rules_python that referenced this issue Apr 10, 2025
With this PR we mark the srcs attribute as optional as we can
leverage the `main_module` to just run things from the deps.

Fixes bazel-contrib#2765
github-merge-queue bot pushed a commit that referenced this issue Apr 13, 2025
With this PR we mark the srcs attribute as optional as we can
leverage the `main_module` to just run things from the deps.

This also removes a long-standing `TODO` note.

Fixes #2765

---------

Co-authored-by: Richard Levasseur <[email protected]>
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 a pull request may close this issue.

2 participants