Current State of Python Packaging

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

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.

Transcript of Current State of Python Packaging

Page 1: Current State of Python Packaging

Current State of PythonPackagingClayton Parker

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

Page 2: Current State of Python Packaging

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

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

Page 3: Current State of Python Packaging

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

Page 4: Current State of Python Packaging

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

Page 5: Current State of Python Packaging

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

Page 6: Current State of Python Packaging

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

Page 7: Current State of Python Packaging

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

Page 8: Current State of Python Packaging

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

Page 9: Current State of Python Packaging

What about easy_install?Predecessor to pipStill usable, but discouraged

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

Page 10: Current State of Python Packaging

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

Page 11: Current State of Python Packaging

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='[email protected]', 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

Page 12: Current State of Python Packaging

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

Page 13: Current State of Python Packaging

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

Page 14: Current State of Python Packaging

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

Page 15: Current State of Python Packaging

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

Page 16: Current State of Python Packaging

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

Page 17: Current State of Python Packaging

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

Page 18: Current State of Python Packaging

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