Search code examples
pythonpyramid

How to use a relative path for the ini file in pyramid.wsgi as argument of pyramid.paster.get_app?


How can I use a relative path for the production.ini file in the pyramid.wsgi file as argument of the paster.get_app() function?

I tried it and it keeps complaining that it can't find the file. In the error message, it has a starting forward slash added, so in case of the code below, I get an error saying that it can't find the file "/./production.ini".

from pyramid.paster import get_app, setup_logging
import logging

# THIS works: ini_path = '/home/bla/app/production.ini'
ini_path = "./production.ini" # This doesn't work, why not?
setup_logging(ini_path)
application = get_app(ini_path, 'main')

Solution

  • It's dependent on the working directory where the script (process) is executed. If you want it relative to the script itself then you might want os.path.join(os.path.dirname(__file__), 'production.ini').