Why do script entrypoints require a function be specified?

__main__.py is already special - see the documentation (specifically, the discussion of the <script> argument) and the documentation of the runpy.run_module function.

The proposal is that

[project.scripts]
foo_cmd = foo

will create an entry point that’s equivalent to running python -m foo.

The specific specification change would be to this text

The object reference points to a function which will be called with no arguments when this command is run.

which would need to be amended to say

The object reference points to a function which will be called with no arguments when this command is run, or a module which will be run as if invoked via python -m module.

The spec change would require a change to any code that currently creates entry point wrappers - that’s at least distlib (which would handle pip as well), installer, and uv, and possibly others. It might also need changes to build backends to allow the module-only form of the script specification - the pyproject.toml specification for entry points doesn’t prohibit the module form for scripts, but backends might do so, given that it’s not currently possible to generate a script wrapper for that form.

It mostly just needs someone to do the work to (a) create PRs implementing this proposal, both to the spec and to the installers, and (b) collect agreement to the change from installers and any affected backends, as evidence that the proposal change is acceptable.

9 Likes