Forewords
While building a Flask application with zc.buildout, I have been searching a way to build the script for Apache's mod_wsgi directly from the buildout command.
Being brain dumb, having other emergencies, and being a lazy programmer, I asked to stackoverflow for some hints.
My fellow Gaël Pasgrimaud suggests using collective.recipe.modwsgi but I did not want to add the PasteDeploy monster to my software stack.
So I took time to hack zc.recipe.egg and find how it creates custom scripts. Et voilà...
I found a way to create my custom wsgi script just using the great z3c.recipe.runscript, I already use for other purposes in various projects. z3c.recipe.runscript is a great piece of software that helps creating your own custom small recipes when you don't find what you need in Pypi or have time to create a real zc.buildout recipe. Here are the snips you need to do the same in your project :
A snip of buildout.cfg
The three parameters expected from this custom part are :
egg
The egg name that contains the wsgi app code.
script
The full path to the wsgi script that will be generated, the same path should sit to the right of the WSGIScriptAlias in your Apache config.
app
The Python name of the application object in the above mentioned egg.
And the snip of above referenced buildouthelpers.py:
Some assumptions without which none of this works:
- Your wsgi app sits in the egg.with.wsgiapp egg.
- This egg.with.wsgiapp egg is installed in another buildout part using zc.recipe.egg recipe (or another one that relies on it), and this part is executed before [wsgiscript].
- All requirements for egg.with.wsgiapp must sit in its setup() parameter install_requires and not in a pip requirements file.
Hope this will help others who fell in a similar situation. Any question or improvement suggestion is welcome.
Comments !