entrypoint-module-name (SMP105)

SMP105No fixNamingAll rules

Flags main.py and _main.py when they serve as command entrypoints.

Why is this bad?

Python looks for a package’s __main__.py when it runs python -m package. Keeping the command’s entrypoint there makes the executable module easy to find and lets the same package run through -m. A separate _main.py can still hold the implementation when __main__.py imports and calls it.

Example

Flagged

pyproject.toml

[project]
name = "pkg"
version = "1"

[project.scripts]
pkg = "pkg.main:run"

pkg/main.py

1def run() -> None:
2    print("ready")
Preferred

pyproject.toml

[project]
name = "pkg"
version = "1"

[project.scripts]
pkg = "pkg.__main__:run"

pkg/__main__.py

1def run() -> None:
2    print("ready")
3
4
5if __name__ == "__main__":
6    run()

What it does

The rule reports a file named main.py or _main.py when a [project.scripts] or [project.gui-scripts] entry in pyproject.toml names its module, or when the file has a top-level if __name__ == "__main__": block. It does not report the filename alone.

Exceptions

  • Implementation modules: _main.py can hold a command’s implementation when the configured entrypoint names __main__.py instead.

  • Other entry points: plugin objects in [project.entry-points] do not make their module a command entrypoint.

Fix

No fix is offered. Renaming an entrypoint also requires updating its imports and script declaration.