Like @MartijnPieters suggests in a comment on your own answer, I'd use collective.recipe.template to generate an entry in the .ini
. I wondered myself how I could then access that data in my project, so I worked it out :-)
Let's work our way backwards to what you need. First in your view code where you want the buildout directory:
def your_view(request):
buildout_dir = request.registry.settings['buildout_dir']
....
request.registry.settings
(see documentation) is a "dictonary-like deployment settings object". See deployment settings, that's the **settings
that gets passed into your main method like def main(global_config, **settings)
Those settings are what's in the [app:main]
part of your deployment.ini
or production.ini
file. So add the buildout directory there:
[app:main]
use = egg:your_app
buildout_dir = /home/you/wherever/it/is
pyramid.reload_templates = true
pyramid.debug_authorization = false
...
But, and this is the last step, you don't want to have that hardcoded path in there. So generate the .ini with a template. The template development.ini.in
uses a ${partname:variable}
expansion language. in your case you need${buildout:directory}
:
[app:main]
use = egg:your_app
buildout_dir = ${buildout:dir}
# ^^^^^^^^^^^^^^^
pyramid.reload_templates = true
pyramid.debug_authorization = false
...
Add a buildout part in buildout.cfg
to generate development.ini
from development.ini.in
:
[buildout]
...
parts =
...
inifile
...
[inifile]
recipe = collective.recipe.template
input = ${buildout:directory}/development.ini.in
output = ${buildout:directory}/development.ini
Note that you can do all sorts of cool stuff with collective.recipe.template. ${serverconfig:portnumber}
to generate a matching port number in your production.ini
and in your your_site_name.nginx.conf
, for instance. Have fun!