Skip to content

Commit 161635b

Browse files
committed
cleaning: removing ContainerTask and ContainerSpec
1 parent 2dd5603 commit 161635b

File tree

3 files changed

+16
-174
lines changed

3 files changed

+16
-174
lines changed

pydra/engine/specs.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -676,23 +676,6 @@ def _check_requires(self, fld, inputs):
676676
return False
677677

678678

679-
@attr.s(auto_attribs=True, kw_only=True)
680-
class ContainerSpec(ShellSpec):
681-
"""Refine the generic command-line specification to container execution."""
682-
683-
image: ty.Union[File, str] = attr.ib(
684-
metadata={"help_string": "image", "mandatory": True}
685-
)
686-
"""The image to be containerized."""
687-
container: ty.Union[File, str, None] = attr.ib(
688-
metadata={"help_string": "container"}
689-
)
690-
"""The container."""
691-
container_xargs: ty.Optional[ty.List[str]] = attr.ib(
692-
default=None, metadata={"help_string": "todo"}
693-
)
694-
695-
696679
@attr.s
697680
class LazyInterface:
698681
_task: "core.TaskBase" = attr.ib()

pydra/engine/task.py

Lines changed: 4 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
SpecInfo,
5858
ShellSpec,
5959
ShellOutSpec,
60-
ContainerSpec,
6160
attr_fields,
6261
)
6362
from .helpers import (
@@ -67,7 +66,7 @@
6766
output_from_inputfields,
6867
parse_copyfile,
6968
)
70-
from .helpers_file import template_update, is_local_file
69+
from .helpers_file import template_update
7170
from ..utils.typing import TypeParser
7271
from .environments import Native
7372

@@ -342,10 +341,7 @@ def command_args(self, root=None):
342341

343342
pos_args = [] # list for (position, command arg)
344343
self._positions_provided = []
345-
for field in attr_fields(
346-
self.inputs,
347-
exclude_names=("container", "image", "container_xargs"),
348-
):
344+
for field in attr_fields(self.inputs):
349345
name, meta = field.name, field.metadata
350346
if (
351347
getattr(self.inputs, name) is attr.NOTHING
@@ -527,13 +523,9 @@ def cmdline(self):
527523
self.inputs.check_fields_input_spec()
528524
if self.state:
529525
raise NotImplementedError
530-
if isinstance(self, ContainerTask):
531-
command_args = self.container_args + self.command_args()
532-
else:
533-
command_args = self.command_args()
534526
# Skip the executable, which can be a multi-part command, e.g. 'docker run'.
535-
cmdline = command_args[0]
536-
for arg in command_args[1:]:
527+
cmdline = self.command_args()[0]
528+
for arg in self.command_args()[1:]:
537529
# If there are spaces in the arg, and it is not enclosed by matching
538530
# quotes, add quotes to escape the space. Not sure if this should
539531
# be expanded to include other special characters apart from spaces
@@ -556,11 +548,6 @@ def _prepare_bindings(self, root: str):
556548
"""
557549
for fld in attr_fields(self.inputs):
558550
if TypeParser.contains_type(FileSet, fld.type):
559-
# Is container_path necessary? Container paths should just be typed PurePath
560-
assert not fld.metadata.get("container_path")
561-
# Should no longer happen with environments; assertion for testing purposes
562-
# XXX: Remove before merge, so "image" can become a valid input file
563-
assert not fld.name == "image"
564551
fileset = getattr(self.inputs, fld.name)
565552
copy = parse_copyfile(fld)[0] == FileSet.CopyMode.copy
566553

@@ -578,134 +565,6 @@ def _prepare_bindings(self, root: str):
578565
DEFAULT_COPY_COLLATION = FileSet.CopyCollation.adjacent
579566

580567

581-
class ContainerTask(ShellCommandTask):
582-
"""Extend shell command task for containerized execution."""
583-
584-
def __init__(
585-
self,
586-
name,
587-
audit_flags: AuditFlag = AuditFlag.NONE,
588-
cache_dir=None,
589-
input_spec: ty.Optional[SpecInfo] = None,
590-
messenger_args=None,
591-
messengers=None,
592-
output_cpath="/output_pydra",
593-
output_spec: ty.Optional[SpecInfo] = None,
594-
rerun=False,
595-
strip=False,
596-
**kwargs,
597-
):
598-
"""
599-
Initialize this task.
600-
601-
Parameters
602-
----------
603-
name : :obj:`str`
604-
Name of this task.
605-
audit_flags : :obj:`pydra.utils.messenger.AuditFlag`
606-
Auditing configuration
607-
cache_dir : :obj:`os.pathlike`
608-
Cache directory
609-
input_spec : :obj:`pydra.engine.specs.SpecInfo`
610-
Specification of inputs.
611-
messenger_args :
612-
TODO
613-
messengers :
614-
TODO
615-
output_cpath : :obj:`str`
616-
Output path within the container filesystem.
617-
output_spec : :obj:`pydra.engine.specs.BaseSpec`
618-
Specification of inputs.
619-
strip : :obj:`bool`
620-
TODO
621-
622-
"""
623-
if input_spec is None:
624-
input_spec = SpecInfo(name="Inputs", fields=[], bases=(ContainerSpec,))
625-
self.output_cpath = Path(output_cpath)
626-
self.bindings = {}
627-
super().__init__(
628-
name=name,
629-
input_spec=input_spec,
630-
output_spec=output_spec,
631-
audit_flags=audit_flags,
632-
messengers=messengers,
633-
messenger_args=messenger_args,
634-
cache_dir=cache_dir,
635-
strip=strip,
636-
rerun=rerun,
637-
**kwargs,
638-
)
639-
640-
def _field_value(self, field, check_file=False):
641-
"""
642-
Checking value of the specific field, if value is not set, None is returned.
643-
If check_file is True, checking if field is a local file
644-
and settings bindings if needed.
645-
"""
646-
value = super()._field_value(field)
647-
if value and check_file and is_local_file(field):
648-
# changing path to the cpath (the directory should be mounted)
649-
lpath = Path(str(value))
650-
cdir = self.bind_paths()[lpath.parent][0]
651-
cpath = cdir.joinpath(lpath.name)
652-
value = str(cpath)
653-
return value
654-
655-
def container_check(self, container_type):
656-
"""Get container-specific CLI arguments."""
657-
if self.inputs.container is None:
658-
raise AttributeError("Container software is not specified")
659-
elif self.inputs.container != container_type:
660-
raise AttributeError(
661-
f"Container type should be {container_type}, but {self.inputs.container} given"
662-
)
663-
if self.inputs.image is attr.NOTHING:
664-
raise AttributeError("Container image is not specified")
665-
666-
def bind_paths(self):
667-
"""Get bound mount points
668-
669-
Returns
670-
-------
671-
mount points: dict
672-
mapping from local path to tuple of container path + mode
673-
"""
674-
self._prepare_bindings()
675-
return {**self.bindings, **{self.output_dir: (self.output_cpath, "rw")}}
676-
677-
def binds(self, opt):
678-
"""
679-
Specify mounts to bind from local filesystems to container and working directory.
680-
681-
Uses py:meth:`bind_paths`
682-
683-
"""
684-
bargs = []
685-
for lpath, (cpath, mode) in self.bind_paths().items():
686-
bargs.extend([opt, f"{lpath}:{cpath}:{mode}"])
687-
return bargs
688-
689-
def _prepare_bindings(self):
690-
fields = attr_fields(self.inputs)
691-
for fld in fields:
692-
if TypeParser.contains_type(FileSet, fld.type):
693-
assert not fld.metadata.get(
694-
"container_path"
695-
) # <-- Is container_path necessary, container paths should just be typed PurePath
696-
if fld.name == "image": # <-- What is the image about?
697-
continue
698-
fileset = getattr(self.inputs, fld.name)
699-
copy_mode, _ = parse_copyfile(fld)
700-
container_path = Path(f"/pydra_inp_{fld.name}")
701-
self.bindings[fileset.parent] = (
702-
container_path,
703-
"rw" if copy_mode == FileSet.CopyMode.copy else "ro",
704-
)
705-
706-
SUPPORTED_COPY_MODES = FileSet.CopyMode.any - FileSet.CopyMode.symlink
707-
708-
709568
def split_cmd(cmd: str):
710569
"""Splits a shell command line into separate arguments respecting quotes
711570

pydra/engine/tests/test_specs.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Runtime,
1212
Result,
1313
ShellSpec,
14-
ContainerSpec,
14+
# ContainerSpec,
1515
LazyIn,
1616
LazyOut,
1717
LazyField,
@@ -51,17 +51,17 @@ def test_shellspec():
5151
assert hasattr(spec, "args")
5252

5353

54-
container_attrs = ["image", "container", "container_xargs"]
55-
56-
57-
def test_container():
58-
with pytest.raises(TypeError):
59-
spec = ContainerSpec()
60-
spec = ContainerSpec(
61-
executable="ls", image="busybox", container="docker"
62-
) # (execute, args, image, cont)
63-
assert all([hasattr(spec, attr) for attr in container_attrs])
64-
assert hasattr(spec, "executable")
54+
# container_attrs = ["image", "container", "container_xargs"]
55+
#
56+
#
57+
# def test_container():
58+
# with pytest.raises(TypeError):
59+
# spec = ContainerSpec()
60+
# spec = ContainerSpec(
61+
# executable="ls", image="busybox", container="docker"
62+
# ) # (execute, args, image, cont)
63+
# assert all([hasattr(spec, attr) for attr in container_attrs])
64+
# assert hasattr(spec, "executable")
6565

6666

6767
class NodeTesting:

0 commit comments

Comments
 (0)