Installation
Normal installation
$ easy_install.py Package
$ easy_install.py http://sample.host/Package-X.Y.tar.gz
$ easy_install.py http://svn.sample.host/Package/trunk
Development installation
$ easy_install.py --editable --build <DIR> Package
$ # or just download and unpack the package
$ cd <DIR>/Package
$ sudo python setup.py develop
Isolated (version-specific) installation
$ easy_install.py -m Package==X.Y
$ python
>>> import pkg_resources
>>> require('Package==X.Y')
easy_install.py (General)
$ easy_install.py kid
easy_install.py (Development)
$ easy_install.py --editable \
--build-directory ~/co \
--find-links=http://pythonpaste.org/package_index.html \
Paste
$ cd ~/co/paste
$ sudo python setup.py develop
* develop installs a package without moving it into site-packages/
* Paste.egg-link is the poor man's symlink to ~/co/paste
* easy-install.pth also points to ~/co/paste
* Python finds .pth files in site-packages and adds their contents to sys.path
Installing in Isolation
$ sudo python setup.py easy_install --multi-version
Creating Packages
Package layout should be like the following:
mypackage-1.0.0/
|-- README
|-- setup.py
|-- ez_setup.py
|-- mypackage/
| |-- __init__.py
| |-- source1.py
| |-- source2.py
| |-- data/
(optional)
| |-- mydata.json
|-- tests
(optional)
|-- |-- __init__.py
|-- |-- runall.py
|-- |-- test0.py
|-- docs
(optional)
|-- |-- source
|-- |-- build
|-- |-- |-- html
|-- |-- |-- pdf
* Download ez_setup.py from
https://bootstrap.pypa.io/ez_setup.py.
Sample for setup.py (
hashcalclib):
import io
import textwrap
from distutils.util import convert_path
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages
mainNS = {}
initPath = convert_path('hashcalclib/__init__.py')
with open(initPath, 'r') as file_:
exec(file_.read(), mainNS)
readmeFile = io.open('README.txt', encoding='utf-8')
with readmeFile:
longDescription = readmeFile.read()
setupParams = dict(\
name='hashcalclib', \
version=mainNS['__version__'], \
description='A hash calculation and verification library.', \
long_description=longDescription, \
author=mainNS['__author__'], \
author_email=mainNS['__email__'], \
license=mainNS['__license__'], \
keywords='', \
url=mainNS['__url__'], \
packages=find_packages(exclude=['*.tests']), \
zip_safe=False, \
classifiers=textwrap.dedent(\
"""
Development Status :: 4 - Beta
Environment :: Console
Environment :: Win32 (MS Windows)
Environment :: X11 Applications
Intended Audience :: Developers
Intended Audience :: End Users/Desktop
License :: OSI Approved :: GNU General Public License v2 (GPLv2)
License :: OSI Approved :: Python Software Foundation License
Operating System :: OS Independent
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Topic :: Security :: Cryptography
Topic :: Utilities
"""
).strip().splitlines(),
)
* See the references section for
more classifiers.
When everything is ready, use "python setup.py --help-commands" to view the commands:
Standard commands:
build build everything needed to install
build_py "build" pure Python modules (copy to build directory)
build_ext build C/C++ extensions (compile/link to build directory)
build_clib build C/C++ libraries used by Python extensions
build_scripts "build" scripts (copy and fixup #! line)
clean clean up temporary files from 'build' command
install install everything from build directory
install_lib install all Python modules (extensions and pure Python)
install_headers install C/C++ header files
install_scripts install scripts (Python or otherwise)
install_data install data files
sdist create a source distribution (tarball, zip file, etc.)
register register the distribution with the Python package index
bdist create a built (binary) distribution
bdist_dumb create a "dumb" built distribution
bdist_rpm create an RPM distribution
bdist_wininst create an executable installer for MS Windows
upload upload binary package to PyPI
Extra commands:
develop install package in 'development mode'
saveopts save supplied options to setup.cfg or other config file
egg_info create a distribution's .egg-info directory
upload_docs Upload documentation to PyPI
alias define a shortcut to invoke one or more commands
easy_install Find/get/install Python packages
rotate delete older distributions, keeping N newest files
bdist_egg create an "egg" distribution
install_egg_info Install an .egg-info directory for the package
test run unit tests after in-place build
build_sphinx Build Sphinx documentation
setopt set an option in setup.cfg or another config file
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
Reference:
https://pythonhosted.org/an_example_pypi_project/index.html
https://pypi.python.org/pypi/setuptools/
https://pypi.python.org/pypi?%3Aaction=list_classifiers
http://www.ianbicking.org/docs/setuptools-presentation/
https://bashelton.com/2009/04/setuptools-tutorial/