MCPcopy Create free account
hub / github.com/apple/ml-pointersect / read_config_file

Function read_config_file

cdslib/core/utils/argparse_utils.py:28–55  ·  view source on GitHub ↗

Read a config file and return a dict (arg_name -> val). Args: filename: json or yaml filename Returns: a dictionary maps argument name (str) -> val

(
    filename: str,
)

Source from the content-addressed store, hash-verified

26
27
28def read_config_file(
29 filename: str,
30) -> T.Dict[str, T.Any]:
31 """
32 Read a config file and return a dict (arg_name -> val).
33
34 Args:
35 filename:
36 json or yaml filename
37
38 Returns:
39 a dictionary maps argument name (str) -> val
40 """
41
42 if os.path.exists(filename):
43 ext = os.path.splitext(filename)[1]
44 if ext == ".json":
45 with open(filename, "r") as f:
46 config_dict = json.load(f)
47 elif ext == ".yaml":
48 with open(filename, "r") as f:
49 config_dict = yaml.load(f, Loader=yaml.FullLoader)
50 else:
51 raise NotImplementedError(f"{filename} ({ext}) not supported")
52 else:
53 raise RuntimeError(f"{filename} not exist")
54
55 return config_dict
56
57
58def compile_argparser_str(

Callers 1

load_optionsMethod · 0.90

Calls 1

loadMethod · 0.80

Tested by

no test coverage detected