Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
W Jannis Leidel
h jezdez@enn.io
d @enn_io
6
How I learned to stop
worrying & love
Python Packaging
6
1) The past of Python packaging
2) Common pitfalls and gotchas
3) Everyday software development
4) The future of Python packaging
Ambiguous terms
- Python package
A directory with Python files (module)
and a __init__.py file
- Release
A version of a specific software, result
of a development cycle, e.g. “Django 1.3”
- Distribution
Source or binary form of a release,
e.g. zipped tarball or Windows installer
1
The past of Python
packaging, a brief
historical overview
Distutils history
- creates distributions
- installs to library directory
- builds C extensions
- processes documentation
Distutils enhancements
setup(
name='MyApp',
version='0.1.0',
description='My
app
that
does
things',
author='John
Doe',
author_email='johndoe@acme.com',
license='BSD',
packages=['myapp'],
package_data
=
{
'myapp':
[
'templates/*.html',
],
},
)
Long description
Rendered on PyPI with docutils
reStructuredText renderer
import
codecs
def
readme(filename):
file
=
codecs.open(filename,
'utf-‐8')
return
unicode(file.read())
setup(
#
...
long_description
=
readme('README.rst'),
)
package_data
Lists all additional, non-Python files of a
release to be installed from a distribution
setup(
#
...
package_data
=
{
'myapp':
[
'static/myapp/*/*',
'templates/myapp/*',
'locale/*/LC_MESSAGES/*'
],
},
)
MANIFEST.in
Template for the “MANIFEST” file that
lists all files to be put in a distribution
include
README.rst
recursive-‐include
docs
*.txt
recursive-‐include
myapp/locale
*.mo
*.po
recursive-‐include
myapp/static
*.css
*.png
recursive-‐include
myapp/templates
*.html
Use sane versions, dammit!
- Use ~/.pip/pip.conf
[install]
index-‐url
=
http://pypi.corp.local/
Local index
[files]
packages
=
myapp
extra_files
=
setup.py
README
resources
=
etc/settings.py.dist
{confdir}/myapp
Other files that are shipped with distutils2
- METADATA
- RECORD
a list of installed files (CSV formatting)
- RESOURCES
list of non-python files
- INSTALLER
name of the installer
- REQUESTED
exists if distribution wasn’t installed as
dependency
6
1) Keep your setup.py files simple
2) Follow the standards
3) Use virtualenv/pip
4) Look out for distutils2/packaging
5) In doubt, read the
“Hitchhiker’s Guide to Packaging”
Thanks! o
Questions? W Jannis Leidel
h jezdez@enn.io
Don‘t forget to
d @enn_io
while we’re
in Amsterdam!