Stop substitution {python} at containers-run runtime#250
Open
mih wants to merge 2 commits intodatalad:masterfrom
Open
Stop substitution {python} at containers-run runtime#250mih wants to merge 2 commits intodatalad:masterfrom
{python} at containers-run runtime#250mih wants to merge 2 commits intodatalad:masterfrom
Conversation
|
Code Climate has analyzed commit fe704e4 and detected 0 issues on this pull request. View more on Code Climate. |
Member
|
#244 was merged, should we proceed that way? |
Member
Author
|
Sadly, this does not seem to be working. It looks like >>> import datalad
>>> import datalad_container
>>> datalad.cfg.get('datalad.run.substitutions.python') is None
True
>>> datalad.cfg.obtain('datalad.run.substitutions.python')
'/home/mih/env/datalad-dev/bin/python'It does not matter whether the default is set via If >>> [c for c in configuration('dump', result_renderer='disabled') if c['name'].startswith('datalad.run.substitutions.')]
[{'action': 'dump_configuration',
'refds': '/tmp/conti',
'name': 'datalad.run.substitutions.python',
'value': '/home/mih/env/datalad-dev/bin/python',
'purpose': 'Substitution for {python} placeholder',
'description': 'path to a Python interpreter executable',
'value_type': constraint:str,
'path': '/tmp/conti',
'status': 'ok'}] |
Member
Author
|
Here is a patch for diff --git a/datalad/core/local/run.py b/datalad/core/local/run.py
index a2ca86772..b588c4a34 100644
--- a/datalad/core/local/run.py
+++ b/datalad/core/local/run.py
@@ -38,6 +38,7 @@ from datalad.interface.base import (
build_doc,
eval_results,
)
+from datalad.interface.common_cfg import definitions as cfg_defs
from datalad.interface.common_opts import (
jobs_opt,
save_message_opt,
@@ -623,7 +624,12 @@ def format_command(dset, command, **kwds):
command = normalize_command(command)
sfmt = SequenceFormatter()
- for k, v in dset.config.items("datalad.run.substitutions"):
+ for k in set(cfg_defs.keys()).union(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.", "")
if sub_key not in kwds:
kwds[sub_key] = vI think this would be a worthwhile addition. |
mih
added a commit
to mih/datalad
that referenced
this pull request
Oct 13, 2023
…ults
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 changeset 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 valueable for improving the portability of
run-recording across (specific) Python versions, or across different
(virtual) environments. See
datalad/datalad-container#224 for an example
use case.
A corresponding test is included.
The ability to keep run-records paramterizable, in particular, for
interpreters can also aid longevity (think platform-specific choices
to call a system Python executable `python3` for some years, and then
switch back.
Related datalad/datalad-container#250
Member
Author
|
I posted a corresponding PR at datalad/datalad#7509 It would make the tests pass in this (unmodified) PR. |
This causes worse portability issues than the previous approach of storing `python(.exe)`. Instead pass the placeholder on to `datalad run`. This would now error with ``` command has an unrecognized placeholder: 'python' ``` and requires a further intervention. Three options: - have datalad-core define `datalad.run.substitutions.python=sys.executable` - wait for datalad#244 and use `register_config()` to have datalad-container define it - have datalad-container define it at `containers-run` runtime by patching the configuration for the execution time (would have `rerun` fail still) - add the configuration item to the committed dataset config Closes datalad#249
Mostly to avoid the misconceptions that led to datalad#249
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This causes worse portability issues than the previous approach of storing
python(.exe).Instead pass the placeholder on to
datalad run.This would now error with (as evident by the CI failure)
and requires a further intervention. Options:
datalad.run.substitutions.python=sys.executableregister_config()to have datalad-container define itcontainers-runruntime by patching the configuration for the execution time (would havererunfail still)Closes #249