[Zope-Coders] 2.7: moving from env.variables to ZConfig?

Fred L. Drake, Jr. fred@zope.com
Wed, 23 Apr 2003 15:20:31 -0400


Chris McDonough writes:
 > This is almost the case right now.  ZConfig sets environment variables
 > based on config file contents and thus overrides any envvar settings
 > provided in the shell under which Zope was started.

Looking at the code again, I suspect there are still problems here.
In most cases, if the value is not set from the config file, or if the
value matches the default, the corresponding envvar is not unset,
which would also be needed to ensure the environment variables reflect
the actual configuration.

 > In the long term, we want to change all core code that obtains
 > configuration settings from envvars.  The current codebase refers to
 > envvars for config in a lot of places, which is obviously confusing for
 > people reading the code.  In the short term, having ZConfig set those
 > variables for us is a reasonable interim solution.

For values supported by the current schema, it's easy enough to use
the configuration object to retrieve them, especially for the Zope
core.  Instead of looking at the environment variable, the way to get
a configuration value is this:

1) At the top of the module that consults the configuration:

     from App.config import getConfiguration

2) To check the config value:

     conf = getConfiguration()
     value = getattr(conf, "my_config_attribute", default)

   The getattr() is used since tests may use partial configurations.
   The attributes softwarehome, zopehome, instancehome, and clienthome
   are always defined.

   Note that getConfiguration() should be called when the value is
   needed, primarily because tests can cause the configuration to
   change while the process is running, and the configuration can
   change during the bootstrap process; code that delays retrieving
   the configuration should behave as expected in the face of dynamic
   changes to the configuration.


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation