I thought this was a great little tutorial.
For people having problems, here’s what the final setup.py should look like at the end:
from setuptools import setup
setup(
name='cute_snek',
entry_points={
'snek_types': [
'cute = cute_snek:cute_snek',
'normal = snek:normal_snek',
'fancy = snek:fancy_snek',
],
'console_scripts': [
'snek = snek:main',
],
}
)
The key is how he moved the original snek types (‘normal’ and ‘fancy’) into the entry_points so that the code in snek.py can find them:
def get_sneks():
sneks = {}
for entry_point in pkg_resources.iter_entry_points('snek_types'):
sneks[entry_point.name] = entry_point.load()
return sneks
Notice how the function get_sneks simply iterates through the snek_types that are listed in the setup.py file.
Notice from the setup.py file that the code expects to find the cute_snek in a file called cute_snek.py (which simply contains the text string: cute_snek = r"…" exactly as he shows it).
And the code expects to find the normal_snek and fancy_snek strings in the original file snek.py since in setup.py it maps ‘normal’ to the normal_spec variable inside snek.py:
‘normal = snek:normal_snek’
Also, to see what the “console_scripts” entry point in setup.py does, it’s instructive to do:
>which snek
and then follow the resulting path to the installed snek script:
#!/some_path_to_your_python_env_here/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'cute-snek','console_scripts','snek'
__requires__ = 'cute-snek'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('cute-snek', 'console_scripts', 'snek')()
)