Question

I have a python package like this:

package/
   setup.py 
   deb/
   build/
   sound/
     __init__.py
     run.py
     config.py
     readaudio.py    

inside run.py:

#! /usr/bin/env python   

start():
    ...do something
resume():
    ....do something
if __name__=="__main__":
   start()

I have built a package and installed it, now I want to run the installed package from command line. Something like

$ ./sound.run

or

$ python sound.run.resume

I want to be able to do this system-wide ( or in a virtualenv), since that's the point of installing it. I know the commands above wouldn't work, but I hope this conveys the idea. I want to call the program not the functions within the python env.

But I am not sure how I can run it from command line without using something like this:

$ python -c " from sound import run; run.start();"

Any suggestions, is that even possible?

Was it helpful?

Solution

You can use setuptools's entry points feature to create a console script for your project

setup(name=project_name,
    packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
    include_package_data=True,
    zip_safe=False,
    entry_points="""
    [console_scripts]
    sound-run = sound.run:start
    sound-resume = sound.run:resume
    """
    # Other setuptools stuff
    )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top