From d3bafb00630f9b8251a2853217dc9c924329284b Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 22 May 2023 22:52:21 -0400 Subject: [PATCH] Always prefer a config template if found --- piker/config.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/piker/config.py b/piker/config.py index b708e252..d838bcdd 100644 --- a/piker/config.py +++ b/piker/config.py @@ -228,6 +228,7 @@ def load( [str | bytes,], MutableMapping, ] = tomllib.loads, + touch_if_dne: bool = False, **tomlkws, @@ -249,18 +250,19 @@ def load( exist_ok=True, ) - if not path.is_file(): - if path is None: - fn: str = _conf_fn_w_ext(conf_name) + if ( + not path.is_file() + and touch_if_dne + ): + fn: str = _conf_fn_w_ext(conf_name) - # try to copy in a template config to the user's directory if - # one exists. - template: Path = repodir() / 'config' / fn - if template.is_file(): - shutil.copyfile(template, path) + # try to copy in a template config to the user's directory if + # one exists. + template: Path = repodir() / 'config' / fn + if template.is_file(): + shutil.copyfile(template, path) - # touch an empty file - elif touch_if_dne: + else: # just touch an empty file with same name with path.open(mode='x'): pass