|
Pythomnic » Documentation » Configuration
Each Pythomnic cage is configured separately by means of a set of
configuration files.
Pythomnic uses the following approach to configuration - configuration
files should allow reasonably unlimited customization, but reside in
a well defined place, and have clearly defined behaviour. Rather than
coming up with a separate mechanism for storing configuration, Pythomnic
uses for configuration something it already has - the dynamically
reloadable application modules.
A configuration module is by no means different from any other module,
only that by convention it resides in the "config" cage subdirectory
and its name starts with "config_", ex. "config_foo.py". Except for the
actual configration parameters put in them, all configuration files
are identical.
You could introduce any number of configuration modules you like. For
example you may decide that you need a place to put configuration for
transportation map. In this case you go to config directory and copy
config_template.py to config_transportation_map.py. The former is just
an empty configuration file, let's examine its contents:
##################################
# EDIT YOUR SETTINGS BELOW
##################################
def config_dynamic(config):
pass
def config_static(config):
pass
##################################
# END OF USER EDITABLE ZONE
##################################
These two methods are the the place where you put the actual configuration
parameters. Something like this:
def config_dynamic(config):
config.set("parameter1", 10)
config.set("foo_bar", [ "whatever", { "it": "takes" } ])
config.set("anything.really", lambda x: x ** 2)
The config object is a dict-like container to put all sorts of values.
The rest of your application modules then reference the values by name,
using the following syntax:
f = pmnc.config_transporation_map.get("anything.really")
assert map(f, [1, 2, 3]) == [1, 4, 9]
|
Features Download Documentation Tutorial |