27 March 2013

PyPi Packages

Create a setup.py file similar to the abbreviated one below1. The Python docs can explain this file and many virtualenvs will help you to test it.

#! /usr/bin/env python

import os

from setuptools import setup

setup(
  name='sesame',
  version='0.1.0',
  description='Encryption tool for application configs.',
  long_description=open('README.rst').read(),
  author='Matt Black',
  author_email='',
  url='http://github.com/mafrosis/sesame',
  packages=['sesame', 'sesame.flask'],
  package_data={'': ['LICENSE']},
  package_dir={'': '.'},
  include_package_data=True,
  install_requires=[open('requirements.txt').read()],
  scripts=['scripts/sesame'],
  license=open('LICENSE').read(),
  classifiers=(
    'Development Status :: 3 - Alpha',
  ),
)

You can register with the command line tool, but for simplicity's sake, I recommend popping over to both PyPi and Test PyPi to register accounts.

Then create a configuration file at ~/.pypirc, changing where appropriate:

[distutils]
index-servers =
     pypi
     ppt

[pypi]
username: mafro
password: <redacted>

[ppt]
repository: http://testpypi.python.org/pypi
username: mafro
password: <redacted>

The first part declares the two available servers: pypi for production and ppt for testing. The subsequent blocks define parameters for each of these.

Now commands to interact with PyPi are much more straight forward. Create and upload a package:

$ python setup.py register -r ppt sdist upload -r ppt

The -r parameter specifies that we're sending to the Test PyPi site.

When pushing a subsequent release, you will only need to run this:

$ python setup.py sdist upload -r ppt

Notes

Write your README in restructured text so it plays nice with Github and PyPi.

All manner of niceties exist in the docutils package, such as testing of your restructured text README:

$ python setup.py --long-description | rst2html.py > output.html

:x


  1. The full version can be found here 


Tagged in devops code tekkers