pypa/sampleproject

Can you add examples of multiple entry points/commands?

Closed this issue · 2 comments

Could you add to this sample where some entry points/commands/CLI would be in the structure?

This is something that I don't know where to put, for example, you have your code as a library but you want to distribute it with some CLI that use that library. Where would it be stored, in a /bin directory?

What if I also want to add tests to those CLI? Would them be in /bin/test? How the imports would work?

Is it possible to configure the setup.py so when you install the sampleproject its /bin files are accessible like regular commands of the operating system (without requiring to add something extra to $PATH)?

If you could add that CLI part to this sample I would appreciate a lot.

Thank you

Could you add to this sample where some entry points/commands/CLI would be in the structure?

This project has a sample CLI command (i.e. defined on the left side of the =):

sampleproject/setup.py

Lines 174 to 185 in 52966de

# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# `pip` to create the appropriate form of executable for the target
# platform.
#
# For example, the following would provide a command called `sample` which
# executes the function `main` from this package when invoked:
entry_points={ # Optional
'console_scripts': [
'sample=sample:main',
],
},

It calls into sample.main:

Related: https://setuptools.readthedocs.io/en/latest/userguide/entry_point.html

Where would it be stored, in a /bin directory?

Python decides that based on sysconfig.get_path("scripts").

What if I also want to add tests to those CLI? Would them be in /bin/test?

IME, they go with all your other tests in tests/.

How the imports would work?

The package is installed in the test environment by tox, and imports work normally. There's nothing special about them.
That said, some CLI frameworks offer testing help (e.g. Click).

Is it possible to configure the setup.py so when you install the sampleproject its /bin files are accessible like regular commands of the operating system (without requiring to add something extra to $PATH)?

You might be interested in pipx: https://pipxproject.github.io/pipx/
Related: https://packaging.python.org/guides/installing-stand-alone-command-line-tools/

Thanks a lot for your answer and the references. I will study that and I think I will learn a lot.
Thanks for pointing the direction.