<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>geek scrap &#187; buildout</title>
	<atom:link href="http://geekscrap.com/tags/buildout/feed/" rel="self" type="application/rss+xml" />
	<link>http://geekscrap.com</link>
	<description>there is at least one way to do it</description>
	<lastBuildDate>Tue, 12 Apr 2011 10:14:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Integrate Tornado in Django</title>
		<link>http://geekscrap.com/2010/02/integrate-tornado-in-django/</link>
		<comments>http://geekscrap.com/2010/02/integrate-tornado-in-django/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 09:32:00 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[How-tos]]></category>
		<category><![CDATA[buildout]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[supervisord]]></category>
		<category><![CDATA[tornado]]></category>
		<category><![CDATA[wsgi]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=588</guid>
		<description><![CDATA[Tornado is a nice python WSGI-compliant web server developed by guys at FriendFeed. It&#8217;s primarily thought as application server for python web frameworks and according to FriendFeed benchmarks, it&#8217;s blazing fast thanks to its non-blocking connections. UPDATE: For more performance info, James Abley pointed me to a very complete benchmark of available Python asynchronous webservers. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tornadoweb.org/">Tornado</a> is a nice python WSGI-compliant web server developed by guys at FriendFeed. It&#8217;s primarily thought as application server for python web frameworks and according to FriendFeed benchmarks, it&#8217;s blazing fast thanks to its non-blocking connections.</p>
<p><strong>UPDATE</strong>: For more performance info, James Abley pointed me to a <a rel="nofollow" href="http://nichol.as/asynchronous-servers-in-python">very complete benchmark</a> of available Python asynchronous webservers. It looks like Tornado is a real monster of concurrency.</p>
<p>There are already some how-to&#8217;s on the web on plugging Django web framework into Tornado webserver. A quick recap:</p>
<ol>
<li>A <a rel="nofollow" href="http://www.jeremybowers.com/blog/4/tornado-web-framework-production-django-and-nginx/">tutorial</a> on Tornado, Django and nginx by Jeremy Bowers.</li>
<li>How to <a rel="nofollow" href="http://lincolnloop.com/blog/2009/sep/15/using-django-inside-tornado-web-server/">import django framework</a> inside a Tornado project by Lincoln Loop.</li>
<li>A <a rel="nofollow" href="http://www.djangosnippets.org/snippets/1748/">snippet</a> by lawgon.</li>
</ol>
<p>My approach is slightly different as I wanted to run Tornado using Django management command-line interface.</p>
<p><span id="more-588"></span>The 3 easy steps are:</p>
<ol>
<li>Add Tornado module to your django setup. If you use buildout, add Tornado git checkout to buildout.cfg using <em>minitage.recipe.fetch</em> recipe, like this:
<pre lang="ini">[buildout]
...
parts =
...
    tornado
    django
...

[tornado]
recipe = minitage.recipe.fetch
urls = git://github.com/facebook/tornado.git | git | | ${buildout:parts-directory}/tornado

[django]
recipe = minitage.recipe.scripts
initialization =
    import os
    os.environ['DJANGO_SETTINGS_MODULE']='project.settings.development'
scripts =
    django
eggs =
    Django
    ...
entry-points=
    django=django.core.management:execute_from_command_line
extra-paths =
    ${buildout:directory}
    ${tornado:location}
...</pre>
</li>
<li>Next, create a command-line extension hierarchy in your project&#8217;s main app:
<pre>$ mkdir project/myapp/management
$ touch project/myapp/management/__init__.py
$ mkdir project/myapp/management/commands
$ touch project/myapp/management/commands/__init__.py</pre>
</li>
<li>Last, add a runtornado.py script in project/myapp/management/commands/ folder with the following content:
<pre lang="python">from django.core.management.base import BaseCommand, CommandError
from optparse import make_option
import os
import sys

class Command(BaseCommand):
    option_list = BaseCommand.option_list + ()
    help = "Starts a Tornado Web."
    args = '[optional port number, or ipaddr:port]'

    def handle(self, addrport='', *args, **options):
        import django
        from django.core.handlers.wsgi import WSGIHandler
        from tornado import httpserver, wsgi, ioloop

	sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
	sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)

        if args:
            raise CommandError('Usage is runserver %s' % self.args)
        if not addrport:
            addr = ''
            port = '8000'
        else:
            try:
                addr, port = addrport.split(':')
            except ValueError:
                addr, port = '', addrport
        if not addr:
            addr = '127.0.0.1'

        if not port.isdigit():
            raise CommandError("%r is not a valid port number." % port)

        quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'

        def inner_run():
            from django.conf import settings
            print "Validating models..."
            self.validate(display_num_errors=True)
            print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
            print "Server is running at http://%s:%s/" % (addr, port)
            print "Quit the server with %s." % quit_command
            application = WSGIHandler()
            container = wsgi.WSGIContainer(application)
            http_server = httpserver.HTTPServer(container)
            http_server.listen(int(port), address=addr)
            ioloop.IOLoop.instance().start()

        inner_run()</pre>
</li>
</ol>
<p>To run your tornado webserver, you just need to call your usual management program like manage.py with runtornado command, with the same syntax as runserver. In my case, I just run production server using <a rel="nofollow" href="http://supervisord.org/">supervisord</a>, with a command like this:</p>
<pre>$ ./bin/django runtornado --settings=project.settings.production 8000</pre>
<p>If you found this quick how-to useful, remember to follow me on <a rel="nofollow" href="http://twitter.com/geekscrap">Twitter</a> or subscribe to my feed for more django tips.</p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/02/integrate-tornado-in-django/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>.gitignore for Django buildout</title>
		<link>http://geekscrap.com/2010/01/gitignore-for-django-buildout/</link>
		<comments>http://geekscrap.com/2010/01/gitignore-for-django-buildout/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 07:30:37 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[How-tos]]></category>
		<category><![CDATA[.gitignore]]></category>
		<category><![CDATA[buildout]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[minitage]]></category>
		<category><![CDATA[pyc]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=342</guid>
		<description><![CDATA[If you&#8217;re keeping your django buildout installation under git, you may find the following .gitignore list useful to prevent your commits from cluttering with ugly temporary files (of course it also applies to other revision control system ignore files). You may need to adapt folder names to your buildout.cfg setup. *~ *.orig *.pyc *.rej .installed.cfg [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re keeping your django buildout installation under git, you may find the following <em>.gitignore</em> list useful to prevent your commits from cluttering with ugly temporary files (of course it also applies to other revision control system ignore files). You may need to adapt folder names to your buildout.cfg setup.</p>
<p><span id="more-342"></span></p>
<pre>*~
*.orig
*.pyc
*.rej
.installed.cfg
__minitage__*
bin/*
develop-eggs
downloads
eggs
log
parts
project/media/uploads
tmp</pre>
<p>As usual, feel free to post your additions as comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/01/gitignore-for-django-buildout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buildout!</title>
		<link>http://geekscrap.com/2010/01/buildout/</link>
		<comments>http://geekscrap.com/2010/01/buildout/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 01:15:04 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[buildout]]></category>
		<category><![CDATA[humour]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=49</guid>
		<description><![CDATA[Of course building from sources packages like wxPython in buildout led me to this: (Remixed by Matt Hamilton, original from http://xkcd.com/303)]]></description>
			<content:encoded><![CDATA[<p>Of course building from sources packages like wxPython in buildout led me to this:</p>
<p><a href="http://pypi.python.org/pypi/mr.developer"><img class="size-full wp-image-48   alignnone" title="xkcd buildout" src="http://geekscrap.com/wp-content/uploads/2010/01/xkcd-buildout1.png" alt="xkcd buildout" width="413" height="360" /></a></p>
<p><em>(Remixed by Matt Hamilton, original from <a rel="nofollow" href="http://xkcd.com/303">http://xkcd.com/303</a></em><em>)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/01/buildout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install wxPython in buildout</title>
		<link>http://geekscrap.com/2010/01/install-wxpython-in-buildout/</link>
		<comments>http://geekscrap.com/2010/01/install-wxpython-in-buildout/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 06:40:17 +0000</pubDate>
		<dc:creator>geekscrap</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[How-tos]]></category>
		<category><![CDATA[buildout]]></category>
		<category><![CDATA[easy_install]]></category>
		<category><![CDATA[egg]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[setuptools]]></category>
		<category><![CDATA[wxPython]]></category>

		<guid isPermaLink="false">http://geekscrap.com/?p=12</guid>
		<description><![CDATA[While completing setup of this blog with WordPress, I&#8217;ve also been working on another task: adding wxPython dependency to a pythonic project of mine. The deployment of this project is done through buildout, a nice piece of software that handles a sandboxed environment for python projects. You can find download and install instructions to start [...]]]></description>
			<content:encoded><![CDATA[<p>While completing setup of this blog with WordPress, I&#8217;ve also been working on another task: adding <a rel="nofollow" href="http://www.wxpython.org/">wxPython</a> dependency to a pythonic project of mine. The deployment of this project is done through <a rel="nofollow" href="http://www.buildout.org/">buildout</a>, a nice piece of software that handles a sandboxed environment for python projects.</p>
<p>You can find download and install instructions to start a buildout barebone <a rel="nofollow" href="http://www.buildout.org/install.html">here</a>, however I will do a small recap:</p>
<p><span id="more-12"></span>First, check that your python installation has <a rel="nofollow" href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a> installed (platform-specific install instructions <a rel="nofollow" href="http://pypi.python.org/pypi/setuptools">here</a>).</p>
<p>Then run the following commands to create your new project and fetch bootstrapping script:</p>
<pre lang="Bash">$ mkdir projectdir
$ cd projectdir
$ wget http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py
$ mkdir downloads # this is needed, as buildout won't create it by itself.</pre>
<p>Next step is writing buildout.cfg, an ini-style configuration file that specifies the setup for your deployment. The generic section is named &#8220;buildout&#8221; and its &#8220;parts&#8221; attribute refers to other sections that must be evaluated. I&#8217;ve created two parts: an example named &#8220;myproject&#8221;, which downloads, builds and installs a couple of fake eggs with wxPython in PYTHONPATH and a &#8220;wxPython&#8221; part, which downloads, builds and installs wxPython inside &#8220;parts&#8221; directory.</p>
<p>Each part is evaluated using a recipe, which is a plugin that is dynamically download from <a rel="nofollow" href="http://pypi.python.org/pypi">eggs repository</a> or any other repository you pass through a find-links attribute. For my purposes I&#8217;ve employed two recipes from <a rel="nofollow" href="http://www.minitage.org/">minitage project</a>, a software deployment project developed by a nice french dude called kiorky (you can chat with him and obtain support at #minitage on irc.freenode.net).</p>
<pre lang="INI">[buildout]
download-cache = downloads
parts =
    wxPython
    myproject

[myproject]
recipe = minitage.recipe.egg
eggs =
    myegg
    myotheregg
extra_paths = ${wxPython:location}/lib/python

[wxPython]
recipe = minitage.recipe.cmmi
url = http://downloads.sourceforge.net/wxpython/wxPython-src-2.8.10.1.tar.bz2
post-make-hook = ${buildout:directory}/hooks.py:wxpython_post_make_hook
configure-options =
    --enable-debug --enable-debug_gdb # replace with --enable-optimize in production code
    --enable-display
    --enable-geometry
    --enable-graphics_ctx
    --enable-mediactrl
    --enable-sound
    --enable-unicode
    --with-libjpeg=builtin
    --with-libpng=builtin
    --with-libtiff=builtin
    --with-opengl
    --with-sdl
    --with-zlib=builtin
# Platform-dependent options, add as needed. Platform names are from sys.platform.lower().
configure-options-darwin = --with-mac --enable-monolithic
configure-options-linux2 = --with-gtk2</pre>
<p>Configure-make-make-install recipe, namely minitage.recipe.cmmi, has a series of special options called &#8220;hooks&#8221; that allow extending the building process with non-standard actions through python code. I&#8217;ve added a call to wxpython_post_make_hook in hooks.py to deal with special post-install code:</p>
<pre lang="python">import os
import sys
import subprocess

def wxpython_post_make_hook(o, b):
    return subprocess.call([sys.executable, 'setup.py',
        'WX_CONFIG=%s' % os.path.join(o['location'], 'bin', 'wx-config'),
        'BUILD_GIZMOS=0', 'BUILD_STC=0',
        'install', '--home=%s' % o['location'],
        ], cwd=os.path.join(o['compile-directory'], 'wxPython'))</pre>
<p>Please note that I&#8217;ve disabled gizmos and stc support from wxPython, because I don&#8217;t need them and  they would require additional building in contrib.</p>
<p>Finally, launch the bootstrapping code:</p>
<pre lang="bash">$ python2.6 ./bootstrap.py</pre>
<p>Of course, if you have a different version of python installed, adjust the command accordingly.</p>
<p>Now buildout is ready to be executed with:</p>
<pre lang="bash">$ ./bin/buildout</pre>
<p>That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://geekscrap.com/2010/01/install-wxpython-in-buildout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
