Why do script entrypoints require a function be specified?

Just for others’ reference, this concern was originally raised on the PEP 621 Setuptools testing thread, and discussed at some length there, which readers here might want to peruse first, particularly @abravalheri 's detailed response giving some additional background on the current situation.

In any case, at least to my naive analysis, it would seem quite possible and desirable, either via a specification update PR or a short PEP (which I’m happy to help with), to modify this section to allow the behavior implied above (i.e. that of runpy)—specifically, if a module is specified, execute it as a script with __name__ == "__main__", and if a package, execute __main__,py inside of it. This would simplify and, thusly, encourage a consistent best-practice approach to declaring a package’s main entrypoint, if it has one; namely, for package spam,

[project.scripts]
spam-cli = "spam"

instead of the following,

[project.scripts]
spam-cli = "spam.__main__.main"

for an entry point that would work equally by executing it via spam-cli and via python -m spam.

@pf_moore what do you think about this?

5 Likes