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

Skip to content

feat(rules): add main_module attribute to run a module name (python -m) #2671

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

Merged
merged 1 commit into from
Mar 19, 2025

Conversation

rickeylev
Copy link
Collaborator

This implements the ability to run a module name instead of a file path, aka
python -m style of invocation.

This allows a binary/test to specify what the main module is without having to
have a direct dependency on the entry point file.

As a side effect, the srcs attribute is no longer required.

Fixes #2539

@rickeylev rickeylev requested a review from aignas as a code owner March 17, 2025 04:18
This is mutually exclusive with {obj}`main_module`.
""",
),
"main_module": lambda: attrb.String(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: what about main becoming main_module if it cannot find the file in srcs?

That said, then we would have worse error messages, so this solution is also good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd rather not because it's not clear how to transform the file name into a module name.

Copy link
Collaborator

@groodt groodt left a comment

Choose a reason for hiding this comment

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

LGTM

🎉

@groodt
Copy link
Collaborator

groodt commented Mar 18, 2025

Im looking forward to trying:
main_module = "pytest.main",

Or even better:
main_module = "pytest_bazel.main",

@rickeylev rickeylev added this pull request to the merge queue Mar 19, 2025
Merged via the queue into bazel-contrib:main with commit 032f6aa Mar 19, 2025
4 checks passed
@rickeylev rickeylev deleted the feat.main.module branch April 5, 2025 16:36
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.

Support python -m invocation style
3 participants