Search code examples
pyramid

Pyramid: getting INI settings filename


I need to take different actions based on what config file is passed at the time the server is started.

I have three config files -- prod.ini, dev.ini and test.ini.

When I do

pserve test.ini

I want to be able to know, within code, that test.ini has been passed. Is there any way to do it?

I checked config.registry.settings -- but it does not have anything.

The only other option I have is to specify an env directive within the INI files and then access it -- which is easy. But I didn't want to do the extra work and have to remember to do it for every new INI file I create.


Solution

  • WSGI entry point should look like:

    def main(global_config, **settings):
        """ This function returns a Pyramid WSGI application.
    

    If my memory doesn't server me incorrectly, there should be global_config["__file__"] which is the configuration INI filename.

    However what I usually do is that inside the INI file itself you specify a variable mode = production or mode = test, etc.