➜ development $ tree -L 2 VotePackage
VotePackage
├── MANIFEST
├── README.txt
├── setup.py
└── votepackage
└── __init__.py
2 directories, 6 files
from distutils.core import setup
setup(
name='VotePackage',
version='0.1dev',
author='Vasyl Dizhak',
author_email='vasyl.dizhak@djangostars.com',
description='Centralized system for python package voting',
packages=['votepackage',],
license='Simplified BSD License',
long_description=open('README.txt').read(),
)
...
name='VotePackage'
...
Has to be unique name.
http://pypi.python.org/pypi/<name>
packages=['votepackage', 'votepackage.tests']
setup(...,
package_data={'votepackage': ['stats/*.json']},
...
)
setup(...,
data_files =[
('/etc/init.d', ['pypivote-server']),
]
...
)
>>> from distutils.version import LooseVersion as V
>>> v1 = V('1.0dev')
>>> v2 = V('1.0.9alpha')
>>> v2 > v1
>>> False
$ pip install -U name
author='Vasyl Dizhak',
author_email='vasyl.dizhak@djangostars.com',
maintainer='Vasyl Dizhak',
maintainer_email='vasyl.dizhak@djangostars.com',
long_description=open('README.md').read(),
include LICENSE
include README.rst
recursive-include votepackage/static *
recursive-include votepackage/templates *
install_requires = [
'requests',
'pycli'
],
if sys.version_info[:2] in ((2, 6), (3, 1)):
# argparse has been added in Python 3.2 / 2.7
requirements.append('argparse>=1.2.1')
if 'win32' in str(sys.platform).lower():
# Terminal colors for Windows
requirements.append('colorama>=0.2.4')
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'Environment :: Console',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3'
'Framework :: Django'
]
python setup.py register --list-classifiers
setup(...,
scripts=['django/bin/django-admin.py']
)
entry_points={
'console_scripts': [
'pypivote=votepackage:main',
],
Use tox to automate package testing against different python versions
import sys
from setuptools.command.test import test as TestCommand
class Tox(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import tox
errno = tox.cmdline(self.test_args)
sys.exit(errno)
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py25,py26,py27,py33
[testenv]
deps=pytest # install pytest in the venvs
commands=py.test # or 'nosetests' or ...
# setup.py
...
tests_require=['tox'], #install tox package
cmdclass = {'test': Tox},
$ python setup.py test
...
py27 inst-nodeps: /Users/rootart/development/
VotePackage/.tox/dist/VotePackage-0.1dev.zip
py27 runtests: commands[0]
...
py25: commands succeeded
py26: commands succeeded
py27: commands succeeded
py33: commands succeeded
congratulations :)
$ virtualenv env
$ pip install/uninstall package
$ pip freeze > requirements-dev.txt
$ pip install -r requirements-dev.txt
$ pip install ... -M (--mirrors) #PEP-381
$ pip install -e git/hg/svn
$ pip list -o #get outdated packages
# $HOME/.pip/pip.conf
[global]
timeout = 60
index-url = http://local.cheeseshop/
download_cache = ~/.cache/pip
python setup.py bdist_wheel --universal
....
pip wheel --wheel-dir=/local/wheels -r requirements.txt
pip install --no-index --find-links=/local/wheels \
-r requirements.txt
Requires-External: C
Requires-External: libpng (>=1.5) #PIL :)
Requires-Dist package; python_version == '2.5'
Obsoletes-Dist: OtherProject (<3.0)