we buy cheese in a cheese shop

100
We Buy Cheese in a Cheese Shop

Upload: tzu-ping-chung

Post on 14-May-2015

517 views

Category:

Technology


1 download

DESCRIPTION

NOTE: SlideShare seems to have problems rendering some of my screenshots. Please visit https://speakerdeck.com/uranusjr/we-buy-cheese-in-a-cheese-shop for a correctly-displayed version. ORIGINAL DESCRIPTION: Python packaging is ______. But PyPA is trying to solve the problem. Let's take a look at how we got into this mess in the first place, and how did/will PyPA do to fix it.

TRANSCRIPT

Page 1: We Buy Cheese in a Cheese Shop

We Buy Cheese in a Cheese Shop

Page 2: We Buy Cheese in a Cheese Shop

Cheese Shop

Page 3: We Buy Cheese in a Cheese Shop

Cheese Shop Sketch http://en.wikipedia.org/wiki/Cheese_Shop_sketch

Page 4: We Buy Cheese in a Cheese Shop

https://pypi.python.org/pypi

Page 5: We Buy Cheese in a Cheese Shop
Page 6: We Buy Cheese in a Cheese Shop

Click this!

Page 7: We Buy Cheese in a Cheese Shop

Why I Hate Django by Cal Henderson at DjangoCon 2008

DjangoCon 2008 59

“I buy my eggs at the cheese shop”- Aaron Straup Cope

[MOON LANGUAGE]

Page 8: We Buy Cheese in a Cheese Shop

Me

• Call me TP

• Follow @uranusjr

• RTFM

• http://uranusjr.logdown.com/pages/about

Page 9: We Buy Cheese in a Cheese Shop

Terminology

Page 10: We Buy Cheese in a Cheese Shop

PyPI

Page 11: We Buy Cheese in a Cheese Shop

Python Package Indexaka The Cheese Shop

Page 12: We Buy Cheese in a Cheese Shop

PyPA

Page 13: We Buy Cheese in a Cheese Shop

Python Packaging Authority

Nobody Expects the Python Packaging Authority by Nick Coghlan at PyCon Australia 2013

Page 14: We Buy Cheese in a Cheese Shop

The Spanish Inquisition http://en.wikipedia.org/wiki/The_Spanish_Inquisition_(Monty_Python)

Page 15: We Buy Cheese in a Cheese Shop

Egg

Page 16: We Buy Cheese in a Cheese Shop

Eggs are to Pythons as Jars are to Java

http://peak.telecommunity.com/DevCenter/PythonEggs

Page 17: We Buy Cheese in a Cheese Shop
Page 18: We Buy Cheese in a Cheese Shop

Wheel

Page 19: We Buy Cheese in a Cheese Shop
Page 20: We Buy Cheese in a Cheese Shop

Wheels as in Cheese Shops

Page 21: We Buy Cheese in a Cheese Shop

http://www.pythonwheels.com (retrieved on 2013-11-30)

Page 22: We Buy Cheese in a Cheese Shop

http://www.python.org/dev/peps/pep-0427/

Page 23: We Buy Cheese in a Cheese Shop

Wheel is…• The replacement of egg

• Standardized

• Alternative Python implementation

• API tag

• Packaged with better structure and metadata

• Performance

• Security

Page 24: We Buy Cheese in a Cheese Shop

But Why?If It Ain’t Broke, Don’t Fix It

Page 25: We Buy Cheese in a Cheese Shop

Because Eggs Are BrokenNo pun intended

Page 26: We Buy Cheese in a Cheese Shop

Where We Are Now

Page 27: We Buy Cheese in a Cheese Shop

Package Author

Server

You

Page 28: We Buy Cheese in a Cheese Shop

Package Author

Server

You

Page 29: We Buy Cheese in a Cheese Shop

distutils

• I am no expert on neither itself nor its history

• Built-in since Python 1.6 (2000)

• Nothing really changed since about 10 years ago

Full documentation: http://docs.python.org/library/distutils.html

Page 30: We Buy Cheese in a Cheese Shop

Container

What you want to deploy

Full documentation: http://docs.python.org/library/distutils.html

Page 31: We Buy Cheese in a Cheese Shop

The “Makefile”

Full documentation: http://docs.python.org/library/distutils.html

Page 32: We Buy Cheese in a Cheese Shop

Extra rules on non-module information

Full documentation: http://docs.python.org/library/distutils.html

Page 33: We Buy Cheese in a Cheese Shop

from distutils.core import setup!!setup(! name='mypackage',! version='1.0',! packages=['mymodule'],! description='My package',! url='http://myawesomepackage.com',! author='Me the Author',! author_email='[email protected]'!)

setup.py

Documentation: http://docs.python.org/distutils/setupscript.html

Page 34: We Buy Cheese in a Cheese Shop

include README.rst!

recursive-exclude * __pycache__!

recursive-exclude * *.py[co]!

include docs!

prune docs/build

MANIFEST.in

Documentation: http://docs.python.org/distutils/sourcedist.html

Page 35: We Buy Cheese in a Cheese Shop

$ python setup.py sdist!!$ python setup.py bdist_wininst

Documentation: http://docs.python.org/distutils/sourcedist.html

Page 36: We Buy Cheese in a Cheese Shop
Page 37: We Buy Cheese in a Cheese Shop

$ python setup.py bdist_egg

Documentation: http://peak.telecommunity.com/DevCenter/PythonEggs

from setuptools import setup!!setup(! # ...!)

Page 38: We Buy Cheese in a Cheese Shop

Source distribution

Page 39: We Buy Cheese in a Cheese Shop

Binary egg

Page 40: We Buy Cheese in a Cheese Shop

Windows installer

Page 41: We Buy Cheese in a Cheese Shop

Does this make sense now?

DjangoCon 2008 58

“I buy my eggs at the cheese shop”- Aaron Straup Cope

Page 42: We Buy Cheese in a Cheese Shop
Page 43: We Buy Cheese in a Cheese Shop

Package metadata (collected from setup)

Page 44: We Buy Cheese in a Cheese Shop

The “zip safety” flag

Page 45: We Buy Cheese in a Cheese Shop

Top level modules

Page 46: We Buy Cheese in a Cheese Shop

Files in the package

Page 47: We Buy Cheese in a Cheese Shop

Depended packages

Page 48: We Buy Cheese in a Cheese Shop

Package information (as seen on PyPI)

Page 49: We Buy Cheese in a Cheese Shop

Where to find packages (aside from PyPI)

Page 50: We Buy Cheese in a Cheese Shop

Package Author

Server

You

Page 51: We Buy Cheese in a Cheese Shop

$ python setup.py register!!$ python setup.py sdist bdist_egg upload

Documentation: http://docs.python.org/distutils/packageindex.html

Page 52: We Buy Cheese in a Cheese Shop

Package Author

Server

You

Page 53: We Buy Cheese in a Cheese Shop

Package Author

PyPI

You

Page 54: We Buy Cheese in a Cheese Shop

Package Author

PyPI

mirror

mirror

You

Page 55: We Buy Cheese in a Cheese Shop

Package Author

PyPI

Self-hosted Server

You

Page 56: We Buy Cheese in a Cheese Shop

[Y]ou don't have to worry about it. They've figured

it all out already.

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) by Joel Spolsky

Page 57: We Buy Cheese in a Cheese Shop

Actually they did not; I just don’t want to talk about it.

Page 58: We Buy Cheese in a Cheese Shop

Package Author

Server

You

Page 59: We Buy Cheese in a Cheese Shop

1. Go to PyPI and search for a package

2. Download

3. Install

• Extract

• python setup.py install

The Manual Way

Page 60: We Buy Cheese in a Cheese Shop

1. Install Setuptools

2. Run easy_install <package>!

3. Profit!

With Setuptools

Documentation: https://pypi.python.org/pypi/setuptools#installation-instructions

Page 61: We Buy Cheese in a Cheese Shop

Problem?

Page 62: We Buy Cheese in a Cheese Shop

LIAR!!!1

Page 63: We Buy Cheese in a Cheese Shop
Page 64: We Buy Cheese in a Cheese Shop

What is zip-safe, anyway?

Page 65: We Buy Cheese in a Cheese Shop
Page 66: We Buy Cheese in a Cheese Shop

Why PIP?

http://www.pip-installer.org/en/latest/other-tools.html#easy-install

• All packages are downloaded before installation

• Flat installation by default

• Uninstallation

• Clean code™

• PyPI with HTTPS by default

Page 67: We Buy Cheese in a Cheese Shop

Why NOT PIP?

http://www.pip-installer.org/en/latest/other-tools.html#easy-install

• Incompatible with certain legacy packages (rare)

• Cannot install from bdist packages (except eggs)

Page 68: We Buy Cheese in a Cheese Shop

先別說這個了!你聽過 distribute 嗎?

Page 69: We Buy Cheese in a Cheese Shop

Commit history of https://bitbucket.org/pypa/setuptools/

Page 70: We Buy Cheese in a Cheese Shop

https://bitbucket.org/tarek/distribute/overview

Page 71: We Buy Cheese in a Cheese Shop

distribute

• Intended to replace Setuptools

• Shares the same module names (setuptools and pkg_resources)

• Active development

https://bitbucket.org/tarek/distribute/overview

Page 72: We Buy Cheese in a Cheese Shop

http://xkcd.com/927/

Page 73: We Buy Cheese in a Cheese Shop

We Need a New Standard!

Page 74: We Buy Cheese in a Cheese Shop
Page 75: We Buy Cheese in a Cheese Shop

http://ziade.org/2010/03/03/the-fate-of-distutils-pycon-summit-packaging-sprint-detailed-report/

Page 76: We Buy Cheese in a Cheese Shop

http://www.python.org/dev/peps/pep-0376/

Page 77: We Buy Cheese in a Cheese Shop

Not Even in Python 3.4

Page 78: We Buy Cheese in a Cheese Shop

This is what you get when developers fight

with each other.

Panel: Directions for Packaging, PyCON US 2013

Page 79: We Buy Cheese in a Cheese Shop
Page 80: We Buy Cheese in a Cheese Shop
Page 81: We Buy Cheese in a Cheese Shop
Page 82: We Buy Cheese in a Cheese Shop

Panel: Directions for Packaging, PyCON US 2013

./setup.py install must die!

Page 83: We Buy Cheese in a Cheese Shop

PyPA’s Schedule• Merge Distribute back to Setuptools (Done)

• New binary distribution format (Done)

• Built-in Setuptools and pip support in Python

• Better security

• …And more!

The Future of Python Packaging, Python Packaging User Guide

Page 84: We Buy Cheese in a Cheese Shop

https://github.com/pypa/pip/commit/b90fc1a

Page 85: We Buy Cheese in a Cheese Shop

pip >= 1.4 setuptools >= 0.8

Upgrading notes: http://pythonhosted.org/setuptools/merge-faq.html

Page 86: We Buy Cheese in a Cheese Shop

$ python setup.py bdist_wheel upload

Documentation: docs.python.org/distutils/packageindex.html

$ pip install --use-wheel <package>

Page 87: We Buy Cheese in a Cheese Shop

MORE IS BETTER

Page 88: We Buy Cheese in a Cheese Shop

Pillow-2.2.1-cp32-none-win32.whl

Name

Version

Python tag

ABI tag

Platform

I’m a wheel!

Page 89: We Buy Cheese in a Cheese Shop

django_mosql-0.2-py27-none-any.whl

Replaces dashes with underscores

Implementation not relevant

Does not need ABI information

Platform independent

Page 90: We Buy Cheese in a Cheese Shop

Description gets its own file!

Page 91: We Buy Cheese in a Cheese Shop

Other metadata (similar to PKG-INFO)

Page 92: We Buy Cheese in a Cheese Shop

Unchanged

Page 93: We Buy Cheese in a Cheese Shop

???

Page 94: We Buy Cheese in a Cheese Shop

Metadata in JSON

Page 95: We Buy Cheese in a Cheese Shop

Wheel format specification

Page 96: We Buy Cheese in a Cheese Shop

SHA256 for each file in this directory

Page 97: We Buy Cheese in a Cheese Shop

What Changed?

• The One True Cheese Shop

• Forward compatibility

• Machine-friendliness

• Safety

Page 98: We Buy Cheese in a Cheese Shop

Wrapping Up

• Python packaging is _____

• How did we get into this mess?

• distutils

• setuptools

• PyPI

• A way out

Page 99: We Buy Cheese in a Cheese Shop

Wheel is the future. Adapt today!

Page 100: We Buy Cheese in a Cheese Shop