-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinputs.py
35 lines (29 loc) · 863 Bytes
/
inputs.py
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
import argparse
import yaml
from dataclasses import dataclass
@dataclass
class CLI:
"""
Parse command-line arguments. This parser enables users to pass a named
`config` argument.
"""
def __post_init__(self) -> None:
self.parser = argparse.ArgumentParser()
self.parser.add_argument(
"-c", "--config", type=str, help="Path to configuration yaml file"
)
self.parser.add_argument(
"--write",
type=bool,
help="If true, write results",
default=True,
action=argparse.BooleanOptionalAction,
)
self.args = self.parser.parse_args()
def load_yaml(filepath: str) -> dict:
"""
Create a data structure from a YAML config filepath.
"""
with open(filepath, "r") as f:
data = yaml.safe_load(f)
return data