_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")
|
path = workflow.source_path("../scripts/_helpers.py")
|
||||||
sys.path.insert(0, os.path.dirname(path))
|
sys.path.insert(0, os.path.dirname(path))
|
||||||
|
|
||||||
|
from _helpers import validate_checksum, update_config_from_wildcards
|
||||||
from snakemake.utils import update_config
|
from snakemake.utils import update_config
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +42,10 @@ def scenario_config(scenario_name):
|
|||||||
|
|
||||||
def static_getter(wildcards, keys, default):
|
def static_getter(wildcards, keys, default):
|
||||||
"""Getter function for static config values."""
|
"""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):
|
def dynamic_getter(wildcards, keys, default):
|
||||||
@ -53,7 +57,11 @@ def dynamic_getter(wildcards, keys, default):
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Scenario {scenario_name} not found in file {config['run']['scenario']['file']}."
|
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):
|
def config_provider(*keys, default=None):
|
||||||
|
@ -8,6 +8,7 @@ import hashlib
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import copy
|
||||||
import urllib
|
import urllib
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -469,13 +470,14 @@ def parse(infix):
|
|||||||
return {infix.pop(0): 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.
|
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"):
|
if w.get("opts"):
|
||||||
opts = w.opts.split("-")
|
opts = w.opts.split("-")
|
||||||
|
|
||||||
@ -641,6 +643,9 @@ def update_config_from_wildcards(config, w):
|
|||||||
infix = o.split("+")[1:]
|
infix = o.split("+")[1:]
|
||||||
update_config(config, parse(infix))
|
update_config(config, parse(infix))
|
||||||
|
|
||||||
|
if not inplace:
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_checksum_from_zenodo(file_url):
|
def get_checksum_from_zenodo(file_url):
|
||||||
parts = file_url.split("/")
|
parts = file_url.split("/")
|
||||||
|
Loading…
Reference in New Issue
Block a user