bug fix for config path

pull/25/head
Kai Chen 2018-10-15 17:50:00 +08:00
parent 7205c2b1d0
commit 517e061ca4
1 changed files with 3 additions and 1 deletions

View File

@ -77,11 +77,13 @@ class Config(object):
filename = osp.abspath(osp.expanduser(filename))
check_file_exist(filename)
if filename.endswith('.py'):
sys.path.append(osp.dirname(filename))
module_name = osp.basename(filename)[:-3]
if '.' in module_name:
raise ValueError('Dots are not allowed in config file path.')
config_dir = osp.dirname(filename)
sys.path.insert(0, config_dir)
mod = import_module(module_name)
sys.path.pop(0)
cfg_dict = {
name: value
for name, value in mod.__dict__.items()