It is not packaging ● No versioning ● You can’t upload this on PyPI (Others cannot install it using pip or easy_install) ● Has no package name ● Doesn’t work at all if it contains any C extensions ○ How is it built? ○ No binary distributions ● No metadata (Who made it? What does it for me?) ● requirements.txt is not packaging but using packages
In the beginning, there was distutils from distutils.core import setup setup(name='Foo', version='1.0', description='Very useful thing', author='Hong Minhee', author_email='[email protected]', url='http://example.com/', packages=['foo', 'foo.bar'])
In the beginning, there was distutils $ python setup.py sdist running sdist running check writing manifest file 'MANIFEST' creating Foo-1.0 ... making hard links in Foo-1.0... hard linking setup.py -> Foo-1.0 hard linking foo/__init__.py -> Foo-1.0/foo ... creating dist Creating tar archive removing 'Foo-1.0' (and everything under it)
In the beginning, there was distutils $ tree lib/python2.7/site-packages/ lib/python2.7/site-packages/ └── foo ├── __init__.py ├── bar │ ├── __init__.py │ └── mod.py ├── exc.py └── util.py 2 directories, 5 files
In the beginning, there was distutils Python 2.7.2+ (default, Jul 20 2012...) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or ... >>> import foo.bar.mod >>> foo.bar.mod.__doc__ 'Useful modules.'
setuptools: De facto standard ● Built on top of distutils ● easy_install ● Dependency resolution ● .egg binary distribution ● Resource management ● Dynamic discovery of plugins
setuptools: Built on top of distutils from distutils.core import setup setup(name='Foo', version='1.0', description='Very useful thing', author='Hong Minhee', author_email='[email protected]', url='http://example.com/', packages=['foo', 'foo.bar'])
setuptools: Built on top of distutils from setuptools import setup, find_packages setup(name='Foo', version='1.0', description='Very useful thing', author='Hong Minhee', author_email='[email protected]', url='http://example.com/', packages=find_packages(), install_requires=['Flask', 'Wand>=0. 2.1'])
pip: Successor of easy_install ● Replaces easy_install (not setuptools) ● Can uninstall packages ● Install packages w/ atomic transaction ○ Install everything ○ or nothing ● Can freeze current site-packages ○ Widely used pattern to generate requirements. txt ● Very useful install -r option ● No easy-install.pth or such
pip: Downsides? ● Can’t install egg packages ● Hard to use pip on Windows ● Or you need entire C build toolchain to install ordinary Python packages at least ○ Visual Studio ○ cygwin? mingw? ● Discourage to declare package metadata using setup.py
Distribute: Maintained fork of setuptools ● setuptools hasn’t been maintained since 2006 ● setuptools doesn’t provide recent Python versions ● Distribute is a fork of setuptools ● Hence it provides the same namespace to setuptools >>> import setuptools >>> setuptools 0.6.30-py2.7.egg/setuptools/__init__.pyc'>
packaging ● Also known as Distutils2 ● To be merged to Python standard library ● Declarative packaging via setup.cfg ● Eliminate imperative packaging (setup.py) ● You can’t use it for your package right now ● Though it would be possible soon :-)
setup.py can do everything! ● Ordinary Python script ● That means it’s Turing-complete ● It gives powerful flexibility ○ Sync long_description field with README file ○ Conditional dependencies using sys.platform and if keyword ○ Platform-aware building process by extending distutils
setup.py knows nothing… ● You can even implement a PHP-to-Python compiler in the script and generate Python files just-in-time ● Nothing can be assumed with setup.py ● Cannot be indexed ● You need to execute the script to get metadata ● Exactly, one of possible metadata variants ● The root cause of why installing Python packages is so slow
TL;DR: Package management ● Install distribute (instead of setuptools) first ● easy_install pip virtualenv ● Use pip to install and uninstall ● Use easy_install to install C extensions ● Isolate site-packages per project using virtualenv
TL;DR: The future of Python ecosystem ● Ready for packaging a.k.a. Distutils2 ● Test your package on various Python VMs/versions (Python 2 and 3, CPython, PyPy…) ● tox will help ● Prefer pip over easy_install ● Don’t make your setup.py dynamic ● It will be your future headache