Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #356 (defect)

Opened 3 years ago

Last modified 3 years ago

Formalize server.environment as a set of config defaults

Status: closed (fixed)

Reported by: fumanchu Assigned to: fumanchu
Priority: normal Milestone: 2.2-beta
Component: CherryPy code Keywords: server.environment development mode config
Cc:

In the beginning, the "server.environment" config value was proposed as a means of enabling a set of features with a single config entry. For example, by setting "server.environment" to "development", the user would instantly gain the benefits of the logDebugInfoFilter, autoreload, and tracebacks in the browser, to name a few.

In practice (as this concept has been implemented in code), each such feature has required an override; that is, each "development mode" feature needed a way to be turned off, selectively, without changing the entire mode. In every case so far (except one which should probably be corrected), the override has been implemented via an additional config entry. For example:

defaultOn = (cherrypy.config.get('server.environment') == 'development')
if cherrypy.config.get('server.showTracebacks', defaultOn):
    show_tracebacks()

It is reasonable to assume that every future use of server.environment will have the same override requirements, and will be implemented in the same fashion. Therefore, it would be worth the effort to formalize this relationship between the environment mode and the config map.

One obvious way to do that would be to add a global "environments" dict to the config module. Each key would be a legal value for "server.environment", and each value would be another dict of config defaults. For example, the current 2.1-final environments would be represented as follows:

# cherrypy/config.py

environments = {
    "production": {},
    "staging": {},
    "development": {
        "autoreload.on": True,
        "server.showTracebacks": True,
        "logDebugInfoFilter.on": True,
        "server.logFileNotFound": True,
    },
}

Application developers would then be empowered to do three things: first, conveniently inspect all effects for a given environment; second, alter the builtin environments on a global scale; and third, create new environments per application as needed.

In addition, the environment-logic currently littered throughout the code would be cleaned up and centralized within config.py. Although this might be viewed as distancing code from its effects, that is desirable in this case--CherryPy code should be written without knowledge of the current environment, being content to switch based on config values only.

Change History

10/21/05 12:57:21: Modified by fumanchu

  • status changed from new to assigned.

10/30/05 18:49:17: Modified by fumanchu

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in [761]. Note that each entry in the new config.environment dict must list all configs which are affected by any environment, so that an environment on a child path can override an environment on a parent path.

Hosted by WebFaction

Log in as guest/cpguest to create tickets