You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the guide more easily comprehensible, mention difference between
src and flat layout concerning `runpy` behaviour, mention typer CLI
parser, tighten language
Co-authored-by: Jason R. Coombs <[email protected]>
In order to enable calling the command-line interface directly from the :term:`source tree <Project Source Tree>`,
147
+
i.e. as ``python src/greetings``, a certain hack could be placed in this file; read more at
148
+
:ref:`running-cli-from-source-src-layout`.
149
+
151
150
152
151
``pyproject.toml``
153
152
------------------
@@ -161,28 +160,21 @@ For the project to be recognised as a command-line tool, additionally a ``consol
161
160
[project.scripts]
162
161
greet = "greetings.cli:main"
163
162
164
-
Besides, it could prove rewarding to add a ``pipx``-specific entry point, the meaning of which is described below:
165
-
166
-
.. code-block:: toml
167
-
168
-
[project.entry-points."pipx.run"]
169
-
greetings = "greetings.cli:main"
170
-
171
-
172
163
Now, the project's source tree is ready to be transformed into a :term:`distribution package <Distribution Package>`,
173
164
which makes it installable.
174
165
175
166
176
167
Installing the package with ``pipx``
177
168
====================================
178
169
179
-
After installing ``pipx`` as described in :ref:`installing-stand-alone-command-line-tools`, you're ready to install your project:
170
+
After installing ``pipx`` as described in :ref:`installing-stand-alone-command-line-tools`, install your project:
180
171
181
172
.. code-block:: console
182
173
183
-
$ pipx install ./greetings/
174
+
$ cd path/to/greetings/
175
+
$ pipx install .
184
176
185
-
This will expose the executable script we defined as an entry point and make the command ``greet`` available to you.
177
+
This will expose the executable script we defined as an entry point and make the command ``greet`` available.
186
178
Let's test it:
187
179
188
180
.. code-block:: console
@@ -194,14 +186,30 @@ Let's test it:
194
186
$ greet --gender masculine
195
187
Greetings, dear Mr. what's-his-name!
196
188
197
-
To just run the program without installing it permanently, you could use ``pipx run``, which will create a temporary (but cached) virtual environment for it:
189
+
To just run the program without installing it permanently, use ``pipx run``, which will create a temporary (but cached) virtual environment for it:
198
190
199
191
.. code-block:: console
200
192
201
-
$ pipx run ./greetings/ --knight
193
+
$ pipx run --spec . greet --knight
194
+
195
+
This syntax is a bit unpractical, however; as the name of the entry point we defined above does not match the package name,
196
+
we need to state explicitly which executable script to run (even though there is only on in existence).
197
+
198
+
There is, however, a more practical solution to this problem, in the form of an entry point specific to ``pipx run``.
199
+
The same can be defined as follows in :file:`pyproject.toml`:
200
+
201
+
.. code-block:: toml
202
+
203
+
[project.entry-points."pipx.run"]
204
+
greetings = "greetings.cli:main"
205
+
206
+
207
+
Thanks to this entry point (which *must* match the package name), ``pipx`` will pick up the executable script as the
208
+
default one and run it, which makes this command possible:
209
+
210
+
.. code-block:: console
202
211
203
-
Thanks to the entry point we defined above (which *must* match the package name), ``pipx`` will pick up the executable script as the
204
-
default one and run it; otherwise, you'd need to specify the entry point's name explicitly with ``pipx run --spec ./greetings/ greet --knight``.
212
+
$ pipx run . --knight
205
213
206
214
Conclusion
207
215
==========
@@ -211,3 +219,4 @@ meaning uploading it to a :term:`package index <Package Index>`, most commonly :
0 commit comments