remove conf and use yacs instead

This commit is contained in:
chenfeiyu 2020-12-03 18:42:36 +08:00
parent 4df5ad42f6
commit 3ca037453e
2 changed files with 2 additions and 49 deletions

View File

@ -1,48 +0,0 @@
import attrdict
import flatdict
import argparse
import yaml
class Config(attrdict.AttrDict):
def dump(self, path):
with open(path, 'wt') as f:
yaml.safe_dump(dict(self), f, default_flow_style=None)
def dumps(self):
return yaml.safe_dump(dict(self), default_flow_style=None)
@classmethod
def from_file(cls, path):
with open(path, 'rt') as f:
c = yaml.safe_load(f)
return cls(c)
def merge_file(self, path):
with open(path, 'rt') as f:
other = yaml.safe_load(f)
self.update(self + other)
def merge_args(self, args):
args_dict = vars(args)
args_dict.pop("config") # exclude config file path
args_dict = {k: v for k, v in args_dict.items() if v is not None}
nested_dict = flatdict.FlatDict(args_dict, delimiter=".").as_dict()
self.update(self + nested_dict)
def merge(self, other):
self.update(self + other)
def flatten(self):
flat = flatdict.FlatDict(self, delimiter='.')
return flat
def add_options_to_parser(self, parser):
parser.add_argument(
"--config", type=str,
help="extra config file to override the default config")
flat = self.flatten()
g = parser.add_argument_group("config file options")
for k, v in flat.items():
g.add_argument("--{}".format(k), type=type(v),
help="config file option: {}".format(k))

View File

@ -66,7 +66,8 @@ setup_info = dict(
'llvmlite==0.31.0',
'opencc',
'g2p_en',
'g2pM'
'g2pM',
'yacs',
],
# Package info