"""Enhance ``run()`` placeholder substitutions to honor configuration defaults
Previously, ``run()`` would not recognize configuration defaults for
placeholder substitution. This means that any placeholders globally declared in
``datalad.interface.common_cfg``, or via ``register_config()`` in DataLad
extensions would not be effective.
This patch makes run's ``format_command()`` helper include such defaults
explicitly, and thereby enable the global declaration of substitution defaults.
Moreoever a ``{python}`` placeholder is now defined via this mechanism, and
points to the value of ``sys.executable`` by default. This particular
placeholder was found to be valuable for improving the portability of
run-recording across (specific) Python versions, or across different (virtual)
environments. See https://github.com/datalad/datalad-container/issues/224 for
an example use case.
https://github.com/datalad/datalad/pull/7509
"""
from itertools import filterfalse
import sys
from datalad.core.local.run import (
GlobbedPaths,
SequenceFormatter,
normalize_command,
quote_cmdlinearg,
)
from datalad.interface.common_cfg import definitions as cfg_defs
from datalad.support.constraints import EnsureStr
from datalad.support.extensions import register_config
from . import apply_patch
# This function is taken from datalad-core@a96c51c0b2794b2a2b4432ec7bd51f260cb91a37
# datalad/core/local/run.py
# The change has been proposed in https://github.com/datalad/datalad/pull/7509
apply_patch(
'datalad.core.local.run', None, 'format_command', format_command)
register_config(
'datalad.run.substitutions.python',
'Substitution for {python} placeholder',
description='Path to a Python interpreter executable',
type=EnsureStr(),
default=sys.executable,
dialog='question',
)