Skip to content

Support python -m invocation style #2539

@rickeylev

Description

@rickeylev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions