Skip to content

Commit

Permalink
Fix run substitution patch
Browse files Browse the repository at this point in the history
Reported by @yarikoptic in
https://github.com/datalad/datalad/pull/7509/files#r1358426552

This changeset adds protection against processing non-substitution
configuration items.

It also reduces duplication a bit more.

In contrast to the change proposal in
datalad/datalad#7509 the (intermediate) set size
is minimized by using a early filter.
  • Loading branch information
mih committed Oct 18, 2023
1 parent e65ca9f commit bda2fd0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions datalad_next/patches/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
https://github.com/datalad/datalad/pull/7509
"""

from itertools import filterfalse
import sys

from datalad.core.local.run import (
Expand Down Expand Up @@ -53,14 +54,19 @@ def format_command(dset, command, **kwds):
"""
command = normalize_command(command)
sfmt = SequenceFormatter()
cprefix = 'datalad.run.substitutions.'

for k in set(cfg_defs.keys()).union(dset.config.keys()):
def not_subst(x):
return not x.startswith(cprefix)

for k in set(filterfalse(not_subst, cfg_defs.keys())).union(
filterfalse(not_subst, dset.config.keys())):
v = dset.config.get(
k,
# pull a default from the config definitions
# if we have no value, but a key
cfg_defs.get(k, {}).get('default', None))
sub_key = k.replace("datalad.run.substitutions.", "")
sub_key = k.replace(cprefix, "")
if sub_key not in kwds:
kwds[sub_key] = v

Expand Down

0 comments on commit bda2fd0

Please sign in to comment.