Sunday, February 9, 2014

Creating a python distribution and publishing to PyPI

Step 1: Create a folder for your module
mkdir depict
cp depict.py depict

Here depict.py is the python module file, out of which we are creating a distribution

Step 2: Create setup.py file. This file contains distribution metadata.
The setup.py program provides metadata about your module and is used to build, install, and upload your packaged distribution.
cd depict
vi setup.py

from distutils.core import setup

setup (
        name = 'depict',
        version = '1.0.0',
        py_modules = ['depict'],
        author = 'Siddesh BG',
        author_email = 'siddesh.bg@gmail.com',
        url = 'http://sliceoffcodes.blogspot.com',
        description = 'A simple printer of nested lists',
        )

Step 3: Build the distribution
cd depict
python setup.py sdist

Step 4: Install the distribution into the local copy of python.
python setup.py install

Step 5: Register with PyPI. 
URL: https://pypi.python.org/pypi . It's straight forward.

Step 6: Command-line registration with PyPI
Though we have already registered with web, still command-line registration is mandatory to make command-line uploading tools aware of username and password. It needs to be done only once.

python setup.py register
running register
running check
We need to know who you are, so please choose either:
 1. use your existing login,
 2. register as a new user,
 3. have the server generate a new password for you (and email it to you), or
 4. quit
Your selection [default 1]:
1
Username: siddesh_bg
Password:
Registering depict to http://pypi.python.org/pypi
Server response (200): OK

Wow !! this module is successfully uploaded to PyPI. You can search it from PyPI.

Step 7: Re-uploading the module: 
The newly requested changes are applied to module and how to re-upload?
python setup.py sdist upload

How to use this module?
Download the module from https://pypi.python.org/packages/source/d/depict/depict-1.0.2.zip#md5=96e22076b0d67b031bf220b300ef776c
Extract the zip file.
Run :    python setup.py install