File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,8 +14,6 @@ Creating the package
1414First of all, create a source tree for the :term: `project <Project> `. For the sake of an example, we'll
1515build a simple tool outputting a greeting (a string) for a person based on arguments given on the command-line.
1616
17- .. todo :: Advise on the optimal structure of a Python package in another guide or discussion and link to it here.
18-
1917This project will adhere to :ref: `src-layout <src-layout-vs-flat-layout >` and in the end be alike this file tree,
2018with the top-level folder and package name ``greetings ``:
2119
@@ -95,6 +93,16 @@ so initialize the command-line interface here:
9593 from greetings.cli import app
9694 app()
9795
96+ In this layout, importing ``greetings `` runs :file: `__init__.py `, which can
97+ stay empty. Running ``python -m greetings `` then runs :file: `__main__.py `.
98+ Keep that entry point small and put the reusable CLI callable in an importable
99+ module such as :file: `cli.py `. Both :file: `__main__.py ` and the installed
100+ script declared in ``[project.scripts] `` can call the same object. Code that
101+ needs that callable can import it from ``greetings.cli ``.
102+ See the `Python documentation for __main__ `_ for more details.
103+
104+ .. _Python documentation for __main__ : https://docs.python.org/3/library/__main__.html
105+
98106.. note ::
99107
100108 In order to enable calling the command-line interface directly from the :term: `source tree <Project Source Tree> `,
You can’t perform that action at this time.
0 commit comments