Skip to content

Commit

Permalink
Merge pull request #207 from vulder/generalize-settingsfunc
Browse files Browse the repository at this point in the history
[utils] Generalize setup_config to enable use from other projects.
  • Loading branch information
simbuerg committed Oct 30, 2018
2 parents 6a54d72 + 71820e0 commit 0712eee
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions benchbuild/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def path_constructor(loader, node):
return ConfigPath(value)


def __find_config__(test_file=None, defaults=None, root=os.curdir):
def find_config(test_file=None, defaults=None, root=os.curdir):
"""
Find the path to the default config file.
Expand Down Expand Up @@ -568,7 +568,7 @@ def walk_rec(cur_path, root):
return ret


def setup_config(cfg):
def setup_config(cfg, config_filenames=None, env_var_name=None):
"""
This will initialize the given configuration object.
Expand All @@ -580,10 +580,17 @@ def setup_config(cfg):
WARNING: Environment variables do _not_ take precedence over the config
file right now. (init_from_env will refuse to update the
value, if there is already one.)
Args:
config_filenames: list of possible config filenames
env_var_name: name of the environment variable holding the config path
"""
config_path = os.getenv("BB_CONFIG_FILE", None)
if env_var_name is None:
env_var_name = "BB_CONFIG_FILE"

config_path = os.getenv(env_var_name, None)
if not config_path:
config_path = __find_config__()
config_path = find_config(defaults=config_filenames)

if config_path:
cfg.load(config_path)
Expand Down

0 comments on commit 0712eee

Please sign in to comment.