Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support {python} placeholder #227

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions changelog.d/20231009_185242_michael.hanke_noexe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### 🚀 Enhancements and New Features

- A new placeholder `{python}` is supported by container execution.
It resolves to the Python interpreter executable running DataLad
on container execution. This solves portability issues with the
previous approach of hard-coding a command name on container
configuration.
Fixes https://github.com/datalad/datalad-container/issues/226 via
https://github.com/datalad/datalad-container/pull/227 (by @mih)
6 changes: 5 additions & 1 deletion datalad_container/containers_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def _guess_call_fmt(ds, name, url):
elif url.startswith('shub://') or url.startswith('docker://'):
return 'singularity exec {img} {cmd}'
elif url.startswith('dhub://'):
return op.basename(sys.executable) + ' -m datalad_container.adapters.docker run {img} {cmd}'
# {python} is replaced with sys.executable on *execute*
return '{python} -m datalad_container.adapters.docker run {img} {cmd}'


def _ensure_datalad_remote(repo):
Expand Down Expand Up @@ -143,6 +144,9 @@ class ContainersAdd(Interface):
replaced with the desired command. Additional placeholders:
'{img_dspath}' is relative path to the dataset containing the image,
'{img_dirpath}' is the directory containing the '{img}'.
'{python}' expands to the path of the Python executable that is
running the respective DataLad session, for example a
'datalad containers-run' command.
""",
metavar="FORMAT",
constraints=EnsureStr() | EnsureNone(),
Expand Down
5 changes: 5 additions & 0 deletions datalad_container/containers_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os.path as op
import sys

from datalad.interface.base import Interface
from datalad.interface.base import build_doc
Expand Down Expand Up @@ -115,6 +116,10 @@ def __call__(cmd, container_name=None, dataset=None,
'Convert it to a plain string.'.format(callspec))
try:
cmd_kwargs = dict(
# point to the python installation that runs *this* code
# we know that it would have things like the docker
# adaptor installed with this extension package
python=sys.executable,
img=image_path,
cmd=cmd,
img_dspath=image_dspath,
Expand Down