python / python/cpython

Support entrypoint references in -m

Open
#145,495 15 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core stdlib topic-importlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

I'd like to adopt entry-points more at my company (we currently have top-level .py files that are often simple redirects to entry-point-style functions), but concern has been raised that there's no simple way for devs to mimic an entry-point invocation without installing their module, which is a hurdle to training. I'd like to extend -m to support entry-point syntax, i.e.

python -m importable.module:entrypoint_function [args...]

This should be roughly equivalent to adding this as a console_scripts entry-point, installing the module, and calling the entry-point from the bin dir:

  • the function will be expected to look at sys.argv to see what's been passed in
  • the first three elements in argv will be replaced with a single entry, so [args...] will be in argv[1:]
Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing CPython's command-line handling for -m and compare it with the packaging entry-points and console_scripts behavior described in the proposal. Confirm how sys.argv should be rewritten and what happens for python -m importable.module:entrypoint_function [args...]; done means the syntax invokes the function with the specified arguments and preserves the stated argv contract.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.