Skip to content

check_manifest

Script to check that JSON schemas for task arguments (as reported in the package manfest) are up-to-date.

_compare_dicts(old, new, path=[])

Provide more informative comparison of two (possibly nested) dictionaries.

PARAMETER DESCRIPTION
old

TBD

TYPE: dict[str, Any]

new

TBD

TYPE: dict[str, Any]

path

TBD

TYPE: list[str] DEFAULT: []

Source code in fractal_tasks_core/dev/check_manifest.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def _compare_dicts(
    old: dict[str, Any], new: dict[str, Any], path: list[str] = []
):
    """
    Provide more informative comparison of two (possibly nested) dictionaries.

    Args:
        old: TBD
        new: TBD
        path: TBD
    """
    path_str = "/".join(path)
    keys_old = set(old.keys())
    keys_new = set(new.keys())
    if not keys_old == keys_new:
        msg = (
            "\n\n"
            f"Dictionaries at path {path_str} have different keys:\n\n"
            f"OLD KEYS:\n{keys_old}\n\n"
            f"NEW KEYS:\n{keys_new}\n\n"
        )
        raise ValueError(msg)
    for key, value_old in old.items():
        value_new = new[key]
        if type(value_old) != type(value_new):
            msg = (
                "\n\n"
                f"Values at path {path_str}/{key} "
                "have different types:\n\n"
                f"OLD TYPE:\n{type(value_old)}\n\n"
                f"NEW TYPE:\n{type(value_new)}\n\n"
            )
            raise ValueError(msg)
        if isinstance(value_old, dict):
            _compare_dicts(value_old, value_new, path=path + [key])
        else:
            if value_old != value_new:
                msg = (
                    "\n\n"
                    f"Values at path {path_str}/{key} "
                    "are different:\n\n"
                    f"OLD VALUE:\n{value_old}\n\n"
                    f"NEW VALUE:\n{value_new}\n\n"
                )
                raise ValueError(msg)