Upload
tzu-ping-chung
View
521
Download
1
Tags:
Embed Size (px)
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.
Citation preview
We Buy Cheese in a Cheese Shop
Cheese Shop
Cheese Shop Sketch http://en.wikipedia.org/wiki/Cheese_Shop_sketch
https://pypi.python.org/pypi
Click this!
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]
Me
• Call me TP
• Follow @uranusjr
• RTFM
• http://uranusjr.logdown.com/pages/about
Terminology
PyPI
Python Package Indexaka The Cheese Shop
PyPA
Python Packaging Authority
Nobody Expects the Python Packaging Authority by Nick Coghlan at PyCon Australia 2013
The Spanish Inquisition http://en.wikipedia.org/wiki/The_Spanish_Inquisition_(Monty_Python)
Egg
Eggs are to Pythons as Jars are to Java
http://peak.telecommunity.com/DevCenter/PythonEggs
Wheel
Wheels as in Cheese Shops
http://www.pythonwheels.com (retrieved on 2013-11-30)
http://www.python.org/dev/peps/pep-0427/
Wheel is…• The replacement of egg
• Standardized
• Alternative Python implementation
• API tag
• Packaged with better structure and metadata
• Performance
• Security
But Why?If It Ain’t Broke, Don’t Fix It
Because Eggs Are BrokenNo pun intended
Where We Are Now
Package Author
Server
You
Package Author
Server
You
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
Container
What you want to deploy
Full documentation: http://docs.python.org/library/distutils.html
The “Makefile”
Full documentation: http://docs.python.org/library/distutils.html
Extra rules on non-module information
Full documentation: http://docs.python.org/library/distutils.html
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
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
$ python setup.py sdist!!$ python setup.py bdist_wininst
Documentation: http://docs.python.org/distutils/sourcedist.html
$ python setup.py bdist_egg
Documentation: http://peak.telecommunity.com/DevCenter/PythonEggs
from setuptools import setup!!setup(! # ...!)
Source distribution
Binary egg
Windows installer
Does this make sense now?
DjangoCon 2008 58
“I buy my eggs at the cheese shop”- Aaron Straup Cope
Package metadata (collected from setup)
The “zip safety” flag
Top level modules
Files in the package
Depended packages
Package information (as seen on PyPI)
Where to find packages (aside from PyPI)
Package Author
Server
You
$ python setup.py register!!$ python setup.py sdist bdist_egg upload
Documentation: http://docs.python.org/distutils/packageindex.html
Package Author
Server
You
Package Author
PyPI
You
Package Author
PyPI
mirror
mirror
You
Package Author
PyPI
Self-hosted Server
You
[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
Actually they did not; I just don’t want to talk about it.
Package Author
Server
You
1. Go to PyPI and search for a package
2. Download
3. Install
• Extract
• python setup.py install
The Manual Way
1. Install Setuptools
2. Run easy_install <package>!
3. Profit!
With Setuptools
Documentation: https://pypi.python.org/pypi/setuptools#installation-instructions
Problem?
LIAR!!!1
What is zip-safe, anyway?
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
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)
先別說這個了!你聽過 distribute 嗎?
Commit history of https://bitbucket.org/pypa/setuptools/
https://bitbucket.org/tarek/distribute/overview
distribute
• Intended to replace Setuptools
• Shares the same module names (setuptools and pkg_resources)
• Active development
https://bitbucket.org/tarek/distribute/overview
http://xkcd.com/927/
We Need a New Standard!
http://ziade.org/2010/03/03/the-fate-of-distutils-pycon-summit-packaging-sprint-detailed-report/
http://www.python.org/dev/peps/pep-0376/
Not Even in Python 3.4
This is what you get when developers fight
with each other.
Panel: Directions for Packaging, PyCON US 2013
Panel: Directions for Packaging, PyCON US 2013
./setup.py install must die!
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
https://github.com/pypa/pip/commit/b90fc1a
pip >= 1.4 setuptools >= 0.8
Upgrading notes: http://pythonhosted.org/setuptools/merge-faq.html
$ python setup.py bdist_wheel upload
Documentation: docs.python.org/distutils/packageindex.html
$ pip install --use-wheel <package>
MORE IS BETTER
Pillow-2.2.1-cp32-none-win32.whl
Name
Version
Python tag
ABI tag
Platform
I’m a wheel!
django_mosql-0.2-py27-none-any.whl
Replaces dashes with underscores
Implementation not relevant
Does not need ABI information
Platform independent
Description gets its own file!
Other metadata (similar to PKG-INFO)
Unchanged
???
Metadata in JSON
Wheel format specification
SHA256 for each file in this directory
What Changed?
• The One True Cheese Shop
• Forward compatibility
• Machine-friendliness
• Safety
Wrapping Up
• Python packaging is _____
• How did we get into this mess?
• distutils
• setuptools
• PyPI
• A way out
Wheel is the future. Adapt today!