Monday, March 7, 2011

how to release python program/lib

To distribute Python programs to others, you should use the distutils module.
1. As preparation, you should first cleanly organize your work into a directory that has a
README file, supporting documentation, and your source code.
Typically, this directory will contain a mix of library modules, packages, and scripts. Modules and packages refer to source files that will be loaded with import statements. Scripts are programs that will run as the main program to the interpreter (e.g., running as python scriptname).
Here is an example of a directory containing Python code:
spam/
    README.txt
    Documentation.txt
    libspam.py # A single library module
    spampkg/ # A package of support modules
        __init__.py
        foo.py
        bar.py
    runspam.py # A script to run as: python runspam.py



2. After you have organized your code, create a file setup.py in the top most directo-
ry (spam in the previous examples). In this file, put the following code:
# setup.py
from distutils.core import setup
setup(name = "spam",
    version = "1.0",
    py_modules = ['libspam'],
    packages = ['spampkg'],
    scripts = ['runspam.py'],
)

3.Type the following shell command to make a source distribution:
% python setup.py sdist
...
This creates an archive file such as spam-1.0.tar.gz or spam-1.0.zip in the directo-
ry spam/dist.

If you type 'python setup.py bdist', a binary distribution is created in
which all of the .py files have already been precompiled into .pyc files and placed into
a directory structure that mimics that of the local platform.
  If you run 'python setup.py bdist_wininst' on a Windows machine, an .exe file will be created.
4. To install, a user simply unpacks the archive and performs these steps:
% unzip spam-1.0.zip
...
% cd spam-1.0
% python setup.py install

This installs the software into the local Python distribution and makes it available for
general use. Modules and packages are normally installed into a directory called
"site-packages" in the Python library.

5. alternative install option
 Python software is often distributed in the form of an .egg file.This format is created by the popular setuptools
extension (http://pypi.python.org/pypi/setuptools).To support setuptools, you can
simply change the first part of your setup.py file as follows:
# setup.py
try:
    from setuptools import setup
    except ImportError:
    from distutils.core import setup
    setup(name = "spam",
        ...
    )

6. Appendix:
list of setup arguments:
Parameters to setup()Parameter Description
name Name of the package (required)
version Version number (required)
author Author’s name
author_email Author’s email address

maintainer Maintainer’s name
maintainer_email Maintainer’s email
url Home page for the package
description Short description of the package
long_description Long description of the package
download_url Location where package can be downloaded
classifiers List of string classifiers

No comments: