Current State of Python Packaging

Preview:

DESCRIPTION

A historical discussion along with a survey of the current landscape of Python packaging. Also learn the basics of uploading your package to PyPi. Presentation was given at the IndyPy user group meeting in February 2014.

Citation preview

Current State of PythonPackagingClayton Parker

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

A History LessonLet's start off with a bit of history.

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

Genesis2000

distutils is added to the standard library in Python 1.6

2003

PyPi is up and running

2004

Setuptools and eggs are unleashed upon the world

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

Second Wave2006

Jim Fulton creates Buildout

2007

Ian Bicking creates virtualenv

2008

Ian Bicking creates pip as an alternative to easy_install

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

The Fork2008

Tarek Ziadé creates distribute, a fork of setuptools aimingto keep the project alive

2008-2012

Packaging life is painful...An effort to fix packaging(distutils2 / packaging) was abandoned.

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

The Present2013

The wheel format is created out of PEP425 and PEP427

2013

pip starts using distlib, out of the ashes of distutils2 andpackaging

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

The Present2013

distribute merges back into setuptools. After almost 10years, setuptools gets to 1.0!!! And then a 2.0 not longafter.

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

How to install?Easiest way to install a package is with pip:

$ pip install requests

Then to upgrade:

$ pip install --upgrade requests

Pretty simple eh?

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

What about easy_install?Predecessor to pipStill usable, but discouraged

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

Advanced features of pipCan do more than just installAbility to install from a requirements.txt fileSearch PyPiShow metadata about the current environment

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

How to create a package?A basic setup.py

import osfrom setuptools import setup

setup( name='mypackage', version='1.0', description='Short description of the package', long_description='reStructured text documentation', url='http://github.com/username/mypackage', license='BSD', author='Author Name', author_email='name@example.com', py_modules=['mypackage'], include_package_data=True, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Programming Language :: Python', ],)

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

PyPi configSetup your ~/.pypirc

[distutils]index-servers= pypi

[pypi]repository = https://pypi.python.org/pypiusername = davepassword = 12345

Yes, that password is in clear text. So be careful!

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

PyPi UploadUploading a new package to PyPi:

$ python setup.py register$ python setup.py sdist upload$ python setup.py bdist_wheel upload

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

Install your packageNow you can install your package just like any other:

$ pip install mypackage

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

Project environmentsTwo common ways of handling your project

Virtualenv (Also venv in Python 3.3+)Buildout

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

VirtualenvUsed to create isolated Python environments:

$ sudo pip install virtualenv$ virtualenv myenv$ cd myenv

Now activate and see what python is available:

$ source bin/activate(myenv)$ which python/Users/clayton/myenv/bin/python

Also check out virtualenvwrapper for more awesomeness!

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

BuildoutUsed to create repeatable environments:

$ git clone https://example.com/git/my-buildout.git$ cd my-buildout$ python bootstrap.py$ bin/buildout

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

LinksPython Packaging User Guide

Detailed information about packaging and the tools that can beused

Sharing Your Labor of Love

Excellent blog post detailing getting your package on PyPi

Current State of Python Packaging - Clayton Parker - IndyPy 02/11/14

Recommended