django & buildout (en)
TRANSCRIPT
![Page 1: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/1.jpg)
Django & BuildoutHorst Gutmann
Photo: http://flickr.com/photos/yakobusan/2363688612/http://creativecommons.org/licenses/by-nc-sa/3.0/at/
![Page 2: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/2.jpg)
Django
• Web Framework in Python
• MVC
• ... has tons of great features that are actually not really relevant for the topic at hand
• Summary: <3
2
![Page 3: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/3.jpg)
Django and its libs
• What do we usually need ...
• Django
• django-tagging
• django-threadedcomments
• (if things like DB-bindings are already installed)
3
![Page 4: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/4.jpg)
All of that you have to install on ...
4
• ... your own machine
• ... your server
• ... and basically every other machine that has anything to do with the development
![Page 5: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/5.jpg)
Installing from & with ...
• Straight from an SCM-checkout
• Sadly that’s still very common since the apps are still quite young
• Using a setup.py
• Using setuptools and easy_install (PyPI <3)
5
![Page 6: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/6.jpg)
Being root helps
• You have to either install these libraries as root user
• ... or you have to start messing around with the PYTHONPATH
• ... which normally results in just a big mess
6
![Page 7: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/7.jpg)
virtualenv
• virtualenv lets you install Python packages without being root
• It lets you build environments for those packages that you load at will
7
$ virtualenv myenv
$ source myenv/bin/activate
$ cd /some/lib
$ python setup.py install
....
$ deactivate
Photo: http://flickr.com/photos/fensterbme/145621388/
![Page 8: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/8.jpg)
virtualenv
• ... is a great tool if you want to try a new library
• But it doesn’t solve the problem that you have to manually reconstruct the environment every time.
• The environments are not portable (C-extensions?)
• ... and not moveable (experimental right now)
8
![Page 9: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/9.jpg)
zc.buildout
• Buildout now lets you build a whole environment with just one config-file
• Basically, it’s similar to Maven in the Java-world, just without XML ;-)
• A project consists of multiple parts
• Each part defines, where its data is coming from and where to store it
9Photo: http://flickr.com/photos/mdpettitt/2521514631/
![Page 10: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/10.jpg)
Recipes exist ...
• ... that download eggs and build a wrapped interpreter to test them
• ... that download a source-distribution and install it
• ... that checkout code from Subversion
• ... and much much more
10
![Page 11: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/11.jpg)
A small example
>>> buildout.cfg
[buildout]parts = sample
[sample]recipe = zc.recipe.eggsinterpreter = myinterpretereggs =
storm==0.12
11
$ buildout
$./bin/myinterpreter> from storm.locals import *
PyPI Canonical
![Page 12: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/12.jpg)
Buildout for Django
• What is in for Django developers?
• A simple way to install dependencies
• ... and to freeze them at a version
• ... and naturally really fast deployment (even with a WSGI-script)
12
![Page 13: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/13.jpg)
djangorecipe
• Recipe for Django projects by Jeroen Vloothuis: http://pypi.python.org/pypi/djangorecipe/
• Creates a Django project with a given version
• ... and creates a wrapper for manage.py with all eggs and other dependencies loaded
13
![Page 14: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/14.jpg)
Another example[buildout]parts = django svnapps
[django]recipe = djangorecipeversion = 1.0project = mysitesettings = settingsextra-paths = ${svnapps:location}/tagging
[svnapps]recipe = iw.recipe.subversionurls = http://django-tagging.googlecode.com/svn/trunk/ tagging
14
![Page 15: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/15.jpg)
import syssys.path[0:0] = [ '$HOME/.buildout/eggs/djangorecipe-0.12.1-py2.6.egg', '$HOME/.buildout/eggs/zc.recipe.egg-1.1.0-py2.6.egg', '$HOME/.buildout/eggs/zc.buildout-1.1.1-py2.6.egg', '$HOME/.buildout/eggs/setuptools-0.6c9-py2.6.egg', '$HOME/tmp/buildout2/parts/django', '$HOME/tmp/buildout2', '$HOME/tmp/buildout2/parts/svnapps/tagging', ]
import djangorecipe.manageif __name__ == '__main__': djangorecipe.manage.main('mysite.settings')
./bin/django
15
![Page 16: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/16.jpg)
mod_wsgi?
• djangorecipe can also be used to create a WSGI-script
• Option: wsgi = true
• ./bin/django.wsgi
• Naturally also includes all the dependencies
16
![Page 17: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/17.jpg)
Summary
• Buildout provides easy dependency management from a multitude of sources (public or not and not only with setuptools)
• Dependencies AND freezing of them
• For developing on a Django project all you need is one buildout.cfg
• djangorecipe also provides you with a WSGI-script
• Migrating to it is very easy :-)
17
![Page 18: Django & Buildout (en)](https://reader034.vdocuments.site/reader034/viewer/2022050720/5554afccb4c905fd608b54dd/html5/thumbnails/18.jpg)
Some links
• http://www.djangoproject.com
• http://pypi.python.org/pypi/zc.buildout/
• http://pypi.python.org/pypi/djangorecipe/
• Icons: http://graffletopia.com/stencils/144
• Pony: http://djangopony.com
18