From d513a03c4a89173ea5c34478c35bfa9cae11a94e Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Sun, 25 Apr 2021 18:27:57 +0200 Subject: [PATCH] Added parser.py docstrings --- app/parser.py | 12 ++++++++++++ app/skeleton.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/app/parser.py b/app/parser.py index bbac40c..dcd9fb1 100644 --- a/app/parser.py +++ b/app/parser.py @@ -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"]) diff --git a/app/skeleton.py b/app/skeleton.py index 9fe48a6..5391e1b 100644 --- a/app/skeleton.py +++ b/app/skeleton.py @@ -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