File size: 904 Bytes
872b0a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Copyright (c) Meta Platforms, Inc. and affiliates.
"""

import json
import os

from easydict import EasyDict
from utils.manifold_utils import pathmgr


def update_config(base_cfg, new_cfg):
    for key in new_cfg:
        if key not in base_cfg:
            base_cfg[key] = new_cfg[key]
        elif type(base_cfg[key]) == EasyDict and type(new_cfg[key]) == EasyDict:
            update_config(base_cfg[key], new_cfg[key])
        else:
            base_cfg[key] = new_cfg[key]

    return base_cfg


def init_config(cfg_file):
    with open(pathmgr.get_local_path(cfg_file)) as f:
        cfg = EasyDict(json.load(f))

    if "base_configs" in cfg:
        base_cfg_file = os.path.join(os.path.dirname(cfg_file), cfg.base_configs)
        with open(pathmgr.get_local_path(base_cfg_file)) as f:
            base_cfg = EasyDict(json.load(f))
        cfg = update_config(base_cfg, cfg)

    return cfg