There are basically two ways to install Python console scripts to my path by setup.py
:
setup( ... entry_points = { 'console_scripts': [ 'foo = package.module:func', ], } )
and
setup( ... scripts = [ 'scripts/myscript.sh' ] )
What are the differences? I see the first approach allows me to choose nice, specific name for my script, but are there any other differences? Different original purposes, compatibility (setuptools, distutils, ...?), usage, ...? I am quite confused and a nice elaborated reply could help me (and probably also others) to properly understand all this.
Update: Since I asked the question PyPA published these cool docs on the topic.
Entry points are a type of metadata that can be exposed by packages on installation. They are a very useful feature of the Python ecosystem, and come specially handy in two scenarios: 1. The package would like to provide commands to be run at the terminal. This functionality is known as console scripts.
The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.
The console_scripts Entry Point Setuptools allows modules to register entrypoints which other packages can hook into to provide certain functionality. It also provides a few itself, including the console_scripts entry point.
In computer programming, an entry point is where the first instructions of a program are executed, and where the program has access to command line arguments.
The docs for the (awesome) Click package suggest a few reasons to use entry points instead of scripts, including
__name__
to __main__
, which could cause code to be imported twice (if another module imports your script)Click is a nice way to implement functions for use as entry_points
, btw.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With