Command line for your package

In the previous post, I explained how to create a package.
Everyone also wants to use their package with command line so here the steps you can follow. The package we built named shortpath. The structure of our package was

/shortpath

shortpath/

__init__.py
shortpath.py

MANIFEST.in
README.rst
__init__.py
setup.py

Now add new script to it for accessing your package with command line

/shortpath

bin/

shortpath

shortpath script will have some code like

#!/usr/bin/env python

import shortpath
print shortpath.some_method()

Now we have to declare our command script in setup.py

setup(
    ...
    scripts=['bin/funniest-joke'],
    ...
)

When we will be done with our installation of the package, setup tools will copy the script to our PATH and make the command available for general use.

$ shortpath

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s