_helpers: add inplace keyword argument to update_config_from_wildcards
This commit is contained in:
parent
388ea65847
commit
9f643ea429
@ -10,6 +10,7 @@ import os, sys, glob
|
||||
path = workflow.source_path("../scripts/_helpers.py")
|
||||
sys.path.insert(0, os.path.dirname(path))
|
||||
|
||||
from _helpers import validate_checksum, update_config_from_wildcards
|
||||
from snakemake.utils import update_config
|
||||
|
||||
|
||||
@ -41,7 +42,10 @@ def scenario_config(scenario_name):
|
||||
|
||||
def static_getter(wildcards, keys, default):
|
||||
"""Getter function for static config values."""
|
||||
return get_config(config, keys, default)
|
||||
config_with_wildcards = update_config_from_wildcards(
|
||||
config, wildcards, inplace=False
|
||||
)
|
||||
return get_config(config_with_wildcards, keys, default)
|
||||
|
||||
|
||||
def dynamic_getter(wildcards, keys, default):
|
||||
@ -53,7 +57,11 @@ def dynamic_getter(wildcards, keys, default):
|
||||
raise ValueError(
|
||||
f"Scenario {scenario_name} not found in file {config['run']['scenario']['file']}."
|
||||
)
|
||||
return get_config(scenario_config(scenario_name), keys, default)
|
||||
config_with_scenario = scenario_config(scenario_name)
|
||||
config_with_wildcards = update_config_from_wildcards(
|
||||
config_with_scenario, wildcards, inplace=False
|
||||
)
|
||||
return get_config(config_with_wildcards, keys, default)
|
||||
|
||||
|
||||
def config_provider(*keys, default=None):
|
||||
|
@ -8,6 +8,7 @@ import hashlib
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import copy
|
||||
import urllib
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
@ -469,13 +470,14 @@ def parse(infix):
|
||||
return {infix.pop(0): parse(infix)}
|
||||
|
||||
|
||||
def update_config_from_wildcards(config, w):
|
||||
def update_config_from_wildcards(config, w, inplace=True):
|
||||
"""
|
||||
Parses configuration settings from wildcards and updates the config.
|
||||
|
||||
- TODO: Should be run inside config_provider function.
|
||||
"""
|
||||
|
||||
if not inplace:
|
||||
config = copy.deepcopy(config)
|
||||
|
||||
if w.get("opts"):
|
||||
opts = w.opts.split("-")
|
||||
|
||||
@ -641,6 +643,9 @@ def update_config_from_wildcards(config, w):
|
||||
infix = o.split("+")[1:]
|
||||
update_config(config, parse(infix))
|
||||
|
||||
if not inplace:
|
||||
return config
|
||||
|
||||
|
||||
def get_checksum_from_zenodo(file_url):
|
||||
parts = file_url.split("/")
|
||||
|
Loading…
Reference in New Issue
Block a user