Skip to content

Clarifications to example code in the command-line tools guide - #2061

Merged
rgommers merged 3 commits into
python:mainfrom
anpol:cli-tools-guide-clarify
Nov 26, 2026
Merged

rgommers merged 3 commits into
python:mainfrom
anpol:cli-tools-guide-clarify

Conversation

@anpol

@anpol anpol commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

The original command-line tools tutorial mixed together three separate execution-related concepts:

  • the callable app object, which defines the Typer-based CLI interface;
  • the if __name__ == "__main__" execution guard, typically used for direct module execution;
  • the __main__.py package entry point, used by python -m greetings;

This PR cleanly separates these responsibilities by:

  • keeping CLI definition in cli.py,
  • exposing an explicit main() entry function,
  • and reducing __main__.py to a thin package launcher.

This is the series of commits, please review them in order.


📚 Documentation preview 📚: https://python-packaging-user-guide--2061.org.readthedocs.build/en/2061/

@anpol anpol changed the title Clarifications for the command-line tools guide Clarifications to the command-line tools guide May 25, 2026
@anpol
anpol force-pushed the cli-tools-guide-clarify branch 2 times, most recently from 2fba17b to 00978cc Compare May 27, 2026 08:07
@rgommers rgommers added component: guides type: maintenance Regular maintenance of the guide, CI and repo labels Nov 10, 2026
When describing a CLI command with `typer`, it might be more common to
use unqualified names, especially when you are defining many command
parameters and want to avoid repetitive typing.
The intent of `greetings.cli` is likely to preconfigure the `app`
object, exportable for reuse by others.

Allowing `greetings.cli` to be runnable as a module didn't make much
sense, because the `greetings` module itself is already runnable.

Exporting the `main()` function and referencing it from the
`pyproject.toml` is likely more common and concise than relying on the
fact that the `app` object itself is callable.
Importing the `main()` function is likely more common and concise than
relying on the heavy-weight `app` object to be callable.
@rgommers
rgommers force-pushed the cli-tools-guide-clarify branch from 00978cc to 8358a44 Compare November 26, 2026 11:33
@rgommers rgommers changed the title Clarifications to the command-line tools guide Clarifications to example code in the command-line tools guide Nov 26, 2026

@rgommers rgommers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @anpol. This improves the example code a little, without changing the meaning of anything - which looks fine to me, in it goes.

@rgommers
rgommers enabled auto-merge November 26, 2026 11:35
@rgommers
rgommers added this pull request to the merge queue Nov 26, 2026
Merged via the queue into python:main with commit 9280c79 Nov 26, 2026
6 of 7 checks passed
@anpol
anpol deleted the cli-tools-guide-clarify branch November 26, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: guides type: maintenance Regular maintenance of the guide, CI and repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants