Skip to content

Commit

Permalink
update default config overwrite mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
rgutzen committed Oct 31, 2023
1 parent 6e425c0 commit 4fd185c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
14 changes: 8 additions & 6 deletions cobrawap/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ def initialize(output_path=None, config_path=None, **kwargs):

# populate config_path with template config files
if any(config_path.iterdir()):
overwrite = (input(f"The config direcotry {config_path} already exists "\
overwrite = (input(f"The config directory {config_path} already exists "\
"and is not empty. Create template config files "\
"anyway? [Y/n]").lower() == 'y'
or True)
"anyway? [y/N]").lower() == 'y'
or False)
else:
overwrite = True
if overwrite:
Expand Down Expand Up @@ -232,8 +232,10 @@ def create(profile=None, parent_profile=None, data_path=None,
profile=config_name,
parent=parent_profile)

setup_entry_stage(profile=profile, parent_profile=parent_profile,
data_path=data_path, loading_script_name=loading_script_name)
setup_entry_stage(profile=profile,
parent_profile=parent_profile,
data_path=data_path,
loading_script_name=loading_script_name)
return None


Expand Down Expand Up @@ -303,7 +305,7 @@ def run_stage(profile=None, stage=None, extra_args=None, **kwargs):

# select stage
while stage not in stages.keys():
stage = input("Which stage should be executed?\n"
stage = input("Which stage should be executed?\n "
+"\n ".join(f"{k} {v}" for k,v in get_setting('stages').items())
+"\nSelect the stage index: ")
stage = stages[stage]
Expand Down
23 changes: 17 additions & 6 deletions cobrawap/cmd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,24 @@ def create_new_configfile(profile, stage=None, stage_number=None, parent=None):
config_path = Path(get_setting('config_path'))

parent = f'_{parent}' if parent else ''
template_config_path = config_path / stage / 'configs' \
/ f'config{parent}.yaml'
new_config_path = config_path / stage / 'configs' \
/ f'config_{profile}.yaml'
config_dir = config_path / stage / 'configs'
template_config_path = config_dir / f'config{parent}.yaml'
new_config_path = config_dir / f'config_{profile}.yaml'

if new_config_path.exists():
log.debug(f"config file `{new_config_path}` already exists. Skip.")
return None

if not template_config_path.exists():
log.debug(f"parent config file `{template_config_path}` doesn't exist.")
potential_parents = [f.name for f in config_dir.iterdir() \
if f.name.startswith(f'config{parent}')]
if potential_parents:
log.debug(f"Using `{potential_parents[0]}` instead.")
template_config_path = config_dir / potential_parents[0]
else:
raise FileNotFoundError("No parent config file fitting the name "
f"`{parent.strip('_')}` found!")

shutil.copy(template_config_path, new_config_path)
update_configfile(new_config_path, {'PROFILE':profile})
Expand Down Expand Up @@ -113,12 +124,12 @@ def setup_entry_stage(profile, parent_profile=None,

stages = get_setting('stages')
loading_script_path = config_path / stages['1'] / 'scripts' \
/ f'{loading_script_name}'
/ f'{loading_script_name}'
if loading_script_path.exists():
log.info(f"`{loading_script_name}` already exists. Skip.")
else:
shutil.copy(config_path / stages['1'] / 'scripts' \
/ 'enter_data_template.py',
/ 'enter_data_template.py',
loading_script_path)

# update stage 01 config
Expand Down
6 changes: 3 additions & 3 deletions pipeline/utils/snakefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def set_setting(setting: dict) -> None:
key_overlap = [k for k in setting.keys() if k in settings.keys()]
if key_overlap:
overwrite = (input(f"There are already settings for {key_overlap}! "\
"Overwrite? [Y/n]").lower() == 'y'
or True)
"Overwrite? [y/N]").lower() == 'y'
or False)
if not overwrite:
setting.pop[key_overlap, None]
_ = [setting.pop(k, None) for k in key_overlap]

settings.update(setting)
with open(SETTINGS_PATH, 'w') as f:
Expand Down

0 comments on commit 4fd185c

Please sign in to comment.