Skip to content

Commit 4d2098b

Browse files
authored
Merge pull request #706 from djarecka/env
Env
2 parents fa240d9 + 7d39b4d commit 4d2098b

File tree

9 files changed

+7
-385
lines changed

9 files changed

+7
-385
lines changed

pydra/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
import attr
1616

1717
from . import mark
18-
from .engine import AuditFlag, DockerTask, ShellCommandTask, Submitter, Workflow, specs
18+
from .engine import AuditFlag, ShellCommandTask, Submitter, Workflow, specs
1919

2020
__all__ = (
2121
"Submitter",
2222
"Workflow",
2323
"AuditFlag",
2424
"ShellCommandTask",
25-
"DockerTask",
2625
"specs",
2726
"mark",
2827
)

pydra/engine/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
"""The core of the workflow engine."""
22
from .submitter import Submitter
33
from .core import Workflow
4-
from .task import AuditFlag, ShellCommandTask, DockerTask
4+
from .task import AuditFlag, ShellCommandTask
55
from . import specs
66

77
__all__ = [
88
"AuditFlag",
9-
"DockerTask",
109
"ShellCommandTask",
1110
"Submitter",
1211
"Workflow",

pydra/engine/specs.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,6 @@ class ContainerSpec(ShellSpec):
693693
)
694694

695695

696-
@attr.s(auto_attribs=True, kw_only=True)
697-
class DockerSpec(ContainerSpec):
698-
"""Particularize container specifications to the Docker engine."""
699-
700-
container: str = attr.ib("docker", metadata={"help_string": "container"})
701-
702-
703696
@attr.s(auto_attribs=True, kw_only=True)
704697
class SingularitySpec(ContainerSpec):
705698
"""Particularize container specifications to Singularity."""

pydra/engine/task.py

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
ShellSpec,
5959
ShellOutSpec,
6060
ContainerSpec,
61-
DockerSpec,
6261
SingularitySpec,
6362
attr_fields,
6463
)
@@ -225,33 +224,6 @@ class ShellCommandTask(TaskBase):
225224
input_spec = None
226225
output_spec = None
227226

228-
def __new__(cls, container_info=None, *args, **kwargs):
229-
if not container_info:
230-
return super().__new__(cls)
231-
232-
if len(container_info) == 2:
233-
type_cont, image = container_info
234-
else:
235-
raise Exception(
236-
f"container_info has to have 2 elements, but {container_info} provided"
237-
)
238-
239-
if type_cont == "docker":
240-
# changing base class of spec if user defined
241-
if "input_spec" in kwargs:
242-
kwargs["input_spec"].bases = (DockerSpec,)
243-
return DockerTask(image=image, *args, **kwargs)
244-
elif type_cont == "singularity":
245-
# changing base class of spec if user defined
246-
if "input_spec" in kwargs:
247-
kwargs["input_spec"].bases = (SingularitySpec,)
248-
return SingularityTask(image=image, *args, **kwargs)
249-
else:
250-
raise Exception(
251-
f"first element of container_info has to be "
252-
f"docker or singularity, but {container_info[0]} provided"
253-
)
254-
255227
def __init__(
256228
self,
257229
audit_flags: AuditFlag = AuditFlag.NONE,
@@ -735,89 +707,6 @@ def _prepare_bindings(self):
735707
SUPPORTED_COPY_MODES = FileSet.CopyMode.any - FileSet.CopyMode.symlink
736708

737709

738-
class DockerTask(ContainerTask):
739-
"""Extend shell command task for containerized execution with the Docker Engine."""
740-
741-
init = False
742-
743-
def __init__(
744-
self,
745-
name=None,
746-
audit_flags: AuditFlag = AuditFlag.NONE,
747-
cache_dir=None,
748-
input_spec: ty.Optional[SpecInfo] = None,
749-
messenger_args=None,
750-
messengers=None,
751-
output_cpath="/output_pydra",
752-
output_spec: ty.Optional[SpecInfo] = None,
753-
rerun=False,
754-
strip=False,
755-
**kwargs,
756-
):
757-
"""
758-
Initialize this task.
759-
760-
Parameters
761-
----------
762-
name : :obj:`str`
763-
Name of this task.
764-
audit_flags : :obj:`pydra.utils.messenger.AuditFlag`
765-
Auditing configuration
766-
cache_dir : :obj:`os.pathlike`
767-
Cache directory
768-
input_spec : :obj:`pydra.engine.specs.SpecInfo`
769-
Specification of inputs.
770-
messenger_args :
771-
TODO
772-
messengers :
773-
TODO
774-
output_cpath : :obj:`str`
775-
Output path within the container filesystem.
776-
output_spec : :obj:`pydra.engine.specs.BaseSpec`
777-
Specification of inputs.
778-
strip : :obj:`bool`
779-
TODO
780-
781-
"""
782-
if not self.init:
783-
if input_spec is None:
784-
input_spec = SpecInfo(name="Inputs", fields=[], bases=(DockerSpec,))
785-
super().__init__(
786-
name=name,
787-
input_spec=input_spec,
788-
output_spec=output_spec,
789-
audit_flags=audit_flags,
790-
messengers=messengers,
791-
messenger_args=messenger_args,
792-
cache_dir=cache_dir,
793-
strip=strip,
794-
output_cpath=output_cpath,
795-
rerun=rerun,
796-
**kwargs,
797-
)
798-
self.inputs.container_xargs = ["--rm"]
799-
self.init = True
800-
801-
@property
802-
def container_args(self):
803-
"""Get container-specific CLI arguments, returns a list if the task has a state"""
804-
if is_lazy(self.inputs):
805-
raise Exception("can't return container_args, self.inputs has LazyFields")
806-
self.container_check("docker")
807-
if self.state:
808-
raise NotImplementedError
809-
810-
cargs = ["docker", "run"]
811-
if self.inputs.container_xargs is not None:
812-
cargs.extend(self.inputs.container_xargs)
813-
814-
cargs.extend(self.binds("-v"))
815-
cargs.extend(["-w", str(self.output_cpath)])
816-
cargs.append(self.inputs.image)
817-
818-
return cargs
819-
820-
821710
class SingularityTask(ContainerTask):
822711
"""Extend shell command task for containerized execution with Singularity."""
823712

pydra/engine/tests/test_dockertask.py

Lines changed: 2 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import pytest
33
import attr
44

5-
from ..task import DockerTask, ShellCommandTask
5+
from ..task import ShellCommandTask
66
from ..submitter import Submitter
77
from ..core import Workflow
8-
from ..specs import ShellOutSpec, SpecInfo, File, DockerSpec, ShellSpec
8+
from ..specs import ShellOutSpec, SpecInfo, File, ShellSpec
99
from ..environments import Docker
1010
from .utils import no_win, need_docker, result_submitter, result_no_submitter
1111

@@ -113,202 +113,6 @@ def test_docker_st_1(results_function, plugin):
113113
assert res[0].output.return_code == res[1].output.return_code == 0
114114

115115

116-
# tests with workflows
117-
118-
119-
# TODO: to remove or update
120-
# @no_win
121-
# @need_docker
122-
# @pytest.mark.skip(reason="we probably don't want to support bindings as an input")
123-
# def test_wf_docker_1(plugin, tmp_path):
124-
# """a workflow with two connected task
125-
# the first one read the file that is bounded to the container,
126-
# the second uses echo
127-
# """
128-
# with open(tmp_path / "file_pydra.txt"), "w" as f:
129-
# f.write("hello from pydra")
130-
#
131-
# wf = Workflow(name="wf", input_spec=["cmd1", "cmd2"])
132-
# wf.inputs.cmd1 = ["cat", "/tmp_dir/file_pydra.txt"]
133-
# wf.inputs.cmd2 = ["echo", "message from the previous task:"]
134-
# wf.add(
135-
# DockerTask(
136-
# name="docky_cat",
137-
# image="busybox",
138-
# executable=wf.lzin.cmd1,
139-
# bindings=[(str(tmp_path), "/tmp_dir", "ro")],
140-
# strip=True,
141-
# )
142-
# )
143-
# wf.add(
144-
# DockerTask(
145-
# name="docky_echo",
146-
# image="ubuntu",
147-
# executable=wf.lzin.cmd2,
148-
# args=wf.docky_cat.lzout.stdout,
149-
# strip=True,
150-
# )
151-
# )
152-
# wf.set_output([("out", wf.docky_echo.lzout.stdout)])
153-
#
154-
# with pytest.raises(Exception) as excinfo:
155-
# wf.docky_echo.cmdline
156-
# assert "can't return cmdline" in str(excinfo.value)
157-
#
158-
# with Submitter(plugin=plugin) as sub:
159-
# wf(submitter=sub)
160-
#
161-
# res = wf.result()
162-
# assert res.output.out == "message from the previous task: hello from pydra"
163-
#
164-
#
165-
# @no_win
166-
# @need_docker
167-
# @pytest.mark.skip(reason="we probably don't want to support bindings as an input")
168-
# def test_wf_docker_1_dockerflag(plugin, tmp_path):
169-
# """a workflow with two connected task
170-
# the first one read the file that is bounded to the container,
171-
# the second uses echo
172-
# using ShellComandTask with container_info
173-
# """
174-
# with open(tmp_path / "file_pydra.txt"), "w" as f:
175-
# f.write("hello from pydra")
176-
#
177-
# wf = Workflow(name="wf", input_spec=["cmd1", "cmd2"])
178-
# wf.inputs.cmd1 = ["cat", "/tmp_dir/file_pydra.txt"]
179-
# wf.inputs.cmd2 = ["echo", "message from the previous task:"]
180-
# wf.add(
181-
# ShellCommandTask(
182-
# name="shocky_cat",
183-
# container_info=("docker", "busybox", [(str(tmp_path), "/tmp_dir", "ro")]),
184-
# executable=wf.lzin.cmd1,
185-
# strip=True,
186-
# )
187-
# )
188-
# wf.add(
189-
# ShellCommandTask(
190-
# name="shocky_echo",
191-
# executable=wf.lzin.cmd2,
192-
# args=wf.shocky_cat.lzout.stdout,
193-
# strip=True,
194-
# container_info=("docker", "ubuntu"),
195-
# )
196-
# )
197-
# wf.set_output([("out", wf.shocky_echo.lzout.stdout)])
198-
#
199-
# with Submitter(plugin=plugin) as sub:
200-
# wf(submitter=sub)
201-
#
202-
# res = wf.result()
203-
# assert res.output.out == "message from the previous task: hello from pydra"
204-
#
205-
#
206-
# @no_win
207-
# @need_docker
208-
# @pytest.mark.skip(reason="we probably don't want to support bindings as an input")
209-
# def test_wf_docker_2pre(plugin, tmp_path, data_tests_dir):
210-
# """a workflow with two connected task that run python scripts
211-
# the first one creates a text file and the second one reads the file
212-
# """
213-
#
214-
# cmd1 = ["python", "/scripts/saving.py", "-f", "/outputs/tmp.txt"]
215-
# dt = DockerTask(
216-
# name="save",
217-
# image="python:3.7-alpine",
218-
# executable=cmd1,
219-
# bindings=[(str(tmp_path), "/outputs"), (str(data_tests_dir), "/scripts", "ro")],
220-
# strip=True,
221-
# )
222-
# res = dt(plugin=plugin)
223-
# assert res.output.stdout == "/outputs/tmp.txt"
224-
#
225-
#
226-
# @no_win
227-
# @need_docker
228-
# @pytest.mark.skip(reason="we probably don't want to support bindings as an input")
229-
# def test_wf_docker_2(plugin, tmp_path, data_tests_dir):
230-
# """a workflow with two connected task that run python scripts
231-
# the first one creates a text file and the second one reads the file
232-
# """
233-
#
234-
# wf = Workflow(name="wf", input_spec=["cmd1", "cmd2"])
235-
# wf.inputs.cmd1 = ["python", "/scripts/saving.py", "-f", "/outputs/tmp.txt"]
236-
# wf.inputs.cmd2 = ["python", "/scripts/loading.py", "-f"]
237-
# wf.add(
238-
# DockerTask(
239-
# name="save",
240-
# image="python:3.7-alpine",
241-
# executable=wf.lzin.cmd1,
242-
# bindings=[
243-
# (str(tmp_path), "/outputs"),
244-
# (str(data_tests_dir), "/scripts", "ro"),
245-
# ],
246-
# strip=True,
247-
# )
248-
# )
249-
# wf.add(
250-
# DockerTask(
251-
# name="load",
252-
# image="python:3.7-alpine",
253-
# executable=wf.lzin.cmd2,
254-
# args=wf.save.lzout.stdout,
255-
# bindings=[
256-
# (str(tmp_path), "/outputs"),
257-
# (str(data_tests_dir), "/scripts", "ro"),
258-
# ],
259-
# strip=True,
260-
# )
261-
# )
262-
# wf.set_output([("out", wf.load.lzout.stdout)])
263-
#
264-
# with Submitter(plugin=plugin) as sub:
265-
# wf(submitter=sub)
266-
#
267-
# res = wf.result()
268-
# assert res.output.out == "Hello!"
269-
#
270-
#
271-
# @no_win
272-
# @need_docker
273-
# @pytest.mark.skip(reason="we probably don't want to support bindings as an input")
274-
# def test_wf_docker_3(plugin, tmp_path):
275-
# """a workflow with two connected task
276-
# the first one read the file that contains the name of the image,
277-
# the output is passed to the second task as the image used to run the task
278-
# """
279-
# with open(tmp_path / "image.txt"), "w" as f:
280-
# f.write("ubuntu")
281-
#
282-
# wf = Workflow(name="wf", input_spec=["cmd1", "cmd2"])
283-
# wf.inputs.cmd1 = ["cat", "/tmp_dir/image.txt"]
284-
# wf.inputs.cmd2 = ["echo", "image passed to the second task:"]
285-
# wf.add(
286-
# DockerTask(
287-
# name="docky_cat",
288-
# image="busybox",
289-
# executable=wf.lzin.cmd1,
290-
# bindings=[(str(tmp_path), "/tmp_dir", "ro")],
291-
# strip=True,
292-
# )
293-
# )
294-
# wf.add(
295-
# DockerTask(
296-
# name="docky_echo",
297-
# image=wf.docky_cat.lzout.stdout,
298-
# executable=wf.lzin.cmd2,
299-
# args=wf.docky_cat.lzout.stdout,
300-
# strip=True,
301-
# )
302-
# )
303-
# wf.set_output([("out", wf.docky_echo.lzout.stdout)])
304-
#
305-
# with Submitter(plugin=plugin) as sub:
306-
# wf(submitter=sub)
307-
#
308-
# res = wf.result()
309-
# assert res.output.out == "image passed to the second task: ubuntu"
310-
311-
312116
# tests with customized output_spec
313117

314118

0 commit comments

Comments
 (0)