Skip to content

Commit

Permalink
Support {python} placeholder
Browse files Browse the repository at this point in the history
This placeholder is expanded on *execution* of a container, rather than
on configuration/addition. This helps use the same Python installation
that is also executing the datalad-container code.

Previously, the docker-support code would expand and then hardcode
`sys.executable` on configuring a container. This led to non-portable
configuration (e.g., hardcoded `python.exe` on windows), and would fail
to pick up the correct python installation in any case where the
`python` entrypoint would not point to the correct one.

Closes #226
Closes #224
  • Loading branch information
mih committed Oct 9, 2023
1 parent ca712e5 commit 273cafa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 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.exectuable on execute

Check failure on line 68 in datalad_container/containers_add.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

exectuable ==> executable
return '{python} -m datalad_container.adapters.docker run {img} {cmd}'


def _ensure_datalad_remote(repo):
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

0 comments on commit 273cafa

Please sign in to comment.