Added parser.py docstrings
parent
3277af2ac5
commit
d513a03c4a
|
@ -1,3 +1,4 @@
|
|||
"""Handles parsing a config file from disk."""
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
from typing import List, Union
|
||||
|
@ -6,9 +7,19 @@ import skeleton
|
|||
|
||||
|
||||
def read_specs_file(path: Union[str, Path]) -> List[Spec]:
|
||||
"""
|
||||
Read a config file and merge it with the skeleton.
|
||||
|
||||
Args:
|
||||
path: path to the yaml config file
|
||||
|
||||
Returns:
|
||||
A list of specs, parsed from the config.
|
||||
"""
|
||||
with open(path, "r") as yaml_file:
|
||||
data = yaml.safe_load(yaml_file)
|
||||
|
||||
# NOTE shouldn't this be defined as a top-level variable?
|
||||
categories = [
|
||||
("directories", DirectorySpec),
|
||||
("volumes", VolumeSpec),
|
||||
|
@ -23,6 +34,7 @@ def read_specs_file(path: Union[str, Path]) -> List[Spec]:
|
|||
|
||||
# Check what defaults are present
|
||||
defaults = {}
|
||||
|
||||
if data.get("defaults"):
|
||||
if data["defaults"].get("all"):
|
||||
defaults = skeleton.merge(defaults, data["defaults"]["all"])
|
||||
|
|
|
@ -89,6 +89,9 @@ def merge_with_skeleton(data: Dict, skel: Dict) -> Dict:
|
|||
data: dictionary containing the selected config values
|
||||
skel: dictionary containing the skeleton (aka the def)
|
||||
|
||||
Returns:
|
||||
a new dictionary representing the two merged dictionaries
|
||||
|
||||
Todo:
|
||||
* Check if an infinite loop is possible
|
||||
* Split info less complex functions
|
||||
|
|
Loading…
Reference in New Issue