7

I'm using setup_tools and setup.py to distribute a package of tools. The face of the package the user sees is a collection of command line scripts installed using the console_scripts entry point.

I would like to have an additional script that the user can execute to see a list of console_scripts that the package has installed.

Is there a principled way of doing this? One simple way is to copy the list from the 'console_scripts' entry in setup.py, but this is going to be error prone as the list has to be updated when the package is modified.

My current solution is to actually read the setup.py script and parse the console_scripts entry. This does not look Pythonic.

Hence my question if there is a principled way to do this. Thanks!

1 Answer 1

3

This is possible using the pkg_resources module from setuptools and filtering for the package you're interested in.

import pkg_resources
def find_my_console_scripts(package_name):
    entrypoints = (ep for ep in pkg_resources.iter_entry_points('console_scripts')
                   if ep.module_name.startswith(package_name))
    return entrypoints

The returned EntryPoints have attributes for everything defined in setup.py such as name, module_name,attrs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.