Skip to content
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

Support python -m invocation style #2539

Open
rickeylev opened this issue Dec 27, 2024 · 0 comments
Open

Support python -m invocation style #2539

rickeylev opened this issue Dec 27, 2024 · 0 comments

Comments

@rickeylev
Copy link
Collaborator

Python supports two ways to start programs: by file, or by module name.

Today, only file is supported. This is a FR for -m to also be supported. There's two main use cases for this style:

  1. Using a file not in the same Bazel package as main.
  2. Specifying a main that comes from dependencies, and referencing the actual main file directly is problematic.

Some example use cases:

  • When using a macro to generate a test/binary.
  • pytest: a common main is used and the tests to execute are passed as arguments or discovered at runtime. This basically a special case of the above.

This should be fairly easy to implement using bootstrap script. It just requires passing the name of the main module to the stage2 bootstrap instead of the path to the main module.

Docs for -m: https://docs.python.org/3.10/using/cmdline.html#cmdoption-m

See also: runpy.run_module: https://docs.python.org/3.10/library/runpy.html#runpy.run_module

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

No branches or pull requests

1 participant