dp3.common.config ¶
Platform config file reader and config model.
HierarchicalDict ¶
Bases: dict
Extension of built-in dict
that simplifies working with a nested hierarchy of dicts.
get ¶
Key may be a path (in dot notation) into a hierarchy of dicts. For example
dictionary.get('abc.x.y')
is equivalent to
dictionary['abc']['x']['y']
.
:returns: self[key]
or default
if key is not found.
Source code in dp3/common/config.py
update ¶
Update HierarchicalDict
with other dictionary and merge common keys.
If there is a key in both current and the other dictionary and values of both keys are dictionaries, they are merged together.
Example:
HierarchicalDict({'a': {'b': 1, 'c': 2}}).update({'a': {'b': 10, 'd': 3}})
->
HierarchicalDict({'a': {'b': 10, 'c': 2, 'd': 3}})
None
.
Source code in dp3/common/config.py
CronExpression ¶
Bases: BaseModel
Cron expression used for scheduling. Also support standard cron expressions, such as
- "*/15" (every 15 units)
- "1,2,3" (1, 2 and 3)
- "1-3" (1, 2 and 3)
Attributes:
Name | Type | Description |
---|---|---|
year |
Optional[str]
|
4-digit year |
month |
Optional[int]
|
month (1-12) |
day |
Optional[Union[Annotated[int, Field(ge=1, le=31)], CronStr]]
|
day of month (1-31) |
week |
Optional[int]
|
ISO week (1-53) |
day_of_week |
Optional[Union[Annotated[int, Field(ge=0, le=6)], CronStr]]
|
number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun) |
hour |
Optional[Union[TimeInt, CronStr]]
|
hour (0-23) |
minute |
Optional[Union[TimeInt, CronStr]]
|
minute (0-59) |
second |
Optional[Union[TimeInt, CronStr]]
|
second (0-59) |
timezone |
str
|
Timezone for time specification (default is UTC). |
EntitySpecDict ¶
Bases: BaseModel
Class representing full specification of an entity.
Attributes:
Name | Type | Description |
---|---|---|
entity |
EntitySpec
|
Specification and settings of entity itself. |
attribs |
dict[str, AttrSpecType]
|
A mapping of attribute id -> AttrSpec |
ModelSpec ¶
Bases: BaseModel
Class representing the platform's current entity and attribute specification.
Attributes:
Name | Type | Description |
---|---|---|
config |
dict[str, EntitySpecDict]
|
Legacy config format, exactly mirrors the config files. |
entities |
dict[str, EntitySpec]
|
Mapping of entity id -> EntitySpec |
attributes |
dict[tuple[str, str], AttrSpecType]
|
Mapping of (entity id, attribute id) -> AttrSpec |
entity_attributes |
dict[str, dict[str, AttrSpecType]]
|
Mapping of entity id -> attribute id -> AttrSpec |
relations |
dict[tuple[str, str], AttrSpecType]
|
Mapping of (entity id, attribute id) -> AttrSpec only contains attributes which are relations. |
Provided configuration must be a dict of following structure:
{
<entity type>: {
'entity': {
entity specification
},
'attribs': {
<attr id>: {
attribute specification
},
other attributes
}
},
other entity types
}
Source code in dp3/common/config.py
PlatformConfig ¶
Bases: BaseModel
An aggregation of configuration available to modules.
Attributes:
Name | Type | Description |
---|---|---|
app_name |
str
|
Name of the application, used when naming various structures of the platform |
config_base_path |
str
|
Path to directory containing platform config |
config |
HierarchicalDict
|
A dictionary that contains the platform config |
model_spec |
ModelSpec
|
Specification of the platform's model (entities and attributes) |
num_processes |
PositiveInt
|
Number of worker processes |
process_index |
NonNegativeInt
|
Index of current process |
read_config ¶
Read configuration file and return config as a dict-like object.
The configuration file should contain a valid YAML
- Comments may be included as lines starting with #
(optionally preceded
by whitespaces).
This function reads the file and converts it to a HierarchicalDict
.
The only difference from built-in dict
is its get
method, which allows
hierarchical keys (e.g. abc.x.y
).
See doc of get method for more information.
Source code in dp3/common/config.py
read_config_dir ¶
Same as read_config, but it loads whole configuration directory of YAML files, so only files ending with ".yml" are loaded. Each loaded configuration is located under key named after configuration filename.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir_path
|
str
|
Path to read config from. |
required |
recursive
|
bool
|
If |
False
|