The gemstone.config module¶
Configurables¶
- class
gemstone.config.
Configurable
(name, *, template=None)[source]¶Defines a configurable value for the application.
Example (You should not use configurables in this way unless you are writing a custom
Configurator
)c = Configurable("test", template=lambda x: x * 2) c.set_value("10") c.get_final_value() # "10" * 2 -> 1010 c2 = Configurable("list_of_ints", template=lambda x: [int(y) for y in x.split(",")]) c.set_value("1,2,3,4,5") c.get_final_value() # [1,2,3,4,5]
Parameters:
- name – The name of the configurable parameter
- template – A callable template to apply over the extracted value
Configurators¶
- class
gemstone.config.
BaseConfigurator
[source]¶Base class for defining configurators. A configurator is a class that, starting from a set of name-configurable pairs, depending on the configurables’ options and the environment, builds a configuration for the application.
get
(name)[source]¶Gets the extracted value for the specified name, if available. If no value could be loaded for the specified name,
None
must be returned.
get_configurable_by_name
(name)[source]¶Returns the registered configurable with the specified name or
None
if no such configurator exists.
register_configurable
(configurable)[source]¶Registers a configurable instance with this configurator
Parameters: configurable – a Configurable
instance
- class
gemstone.config.
CommandLineConfigurator
[source]¶Configurator that collects values from command line arguments. For each registered configurable, will attempt to get from command line the value designated by the argument
--name
wherename
is the name of the configurable.Example
For the configurables
- Configurable(“a”)
- Configurable(“b”)
- Configurable(“c”)
the following command line interface will be exposed
usage: service.py [-h] [--a A] [--b B] [--c C] optional arguments: -h, --help show this help message and exit --a A --b B --c CThe
service.py
can be called like thispython service.py --a=1 --b=2 --c=3