Skip to content

Commit d47f15c

Browse files
committed
support podman even when not installed as "docker" alias
1 parent 0099f11 commit d47f15c

19 files changed

+96
-34
lines changed

cwltool/builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
from cwl_utils import expression
1818
from cwl_utils.file_formats import check_format
1919
from rdflib import Graph
20-
from ruamel.yaml.comments import CommentedMap
2120
from schema_salad.avro.schema import Names, Schema, make_avsc_object
2221
from schema_salad.exceptions import ValidationException
2322
from schema_salad.sourceline import SourceLine
2423
from schema_salad.utils import convert_to_dict, json_dumps
2524
from schema_salad.validate import validate
2625
from typing_extensions import TYPE_CHECKING, Type # pylint: disable=unused-import
2726

27+
from ruamel.yaml.comments import CommentedMap
28+
2829
from .errors import WorkflowException
2930
from .loghandler import _logger
3031
from .mutation import MutationManager

cwltool/command_line_tool.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
)
3131

3232
import shellescape
33-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3433
from schema_salad.avro.schema import Schema
3534
from schema_salad.exceptions import ValidationException
3635
from schema_salad.ref_resolver import file_uri, uri_file_path
@@ -39,14 +38,16 @@
3938
from schema_salad.validate import validate_ex
4039
from typing_extensions import TYPE_CHECKING, Type
4140

41+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
42+
4243
from .builder import (
4344
INPUT_OBJ_VOCAB,
4445
Builder,
4546
content_limit_respected_read_bytes,
4647
substitute,
4748
)
4849
from .context import LoadingContext, RuntimeContext, getdefault
49-
from .docker import DockerCommandLineJob
50+
from .docker import DockerCommandLineJob, PodmanCommandLineJob
5051
from .errors import UnsupportedRequirement, WorkflowException
5152
from .flatten import flatten
5253
from .job import CommandLineJob, JobBase
@@ -460,6 +461,8 @@ def make_job_runner(self, runtimeContext: RuntimeContext) -> Type[JobBase]:
460461
raise UnsupportedRequirement(
461462
"Both Docker and MPI have been hinted - don't know what to do"
462463
)
464+
if runtimeContext.podman:
465+
return PodmanCommandLineJob
463466
return DockerCommandLineJob
464467
if dockerRequired:
465468
raise UnsupportedRequirement(

cwltool/context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
Union,
1818
)
1919

20-
# move to a regular typing import when Python 3.3-3.6 is no longer supported
21-
from ruamel.yaml.comments import CommentedMap
2220
from schema_salad.avro.schema import Names
2321
from schema_salad.ref_resolver import Loader
2422
from schema_salad.utils import FetcherCallableType
2523
from typing_extensions import TYPE_CHECKING
2624

25+
# move to a regular typing import when Python 3.3-3.6 is no longer supported
26+
from ruamel.yaml.comments import CommentedMap
27+
2728
from .builder import Builder
2829
from .mpi import MpiConfig
2930
from .mutation import MutationManager

cwltool/cwlrdf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
from rdflib import Graph
66
from rdflib.query import ResultRow
7-
from ruamel.yaml.comments import CommentedMap
87
from schema_salad.jsonld_context import makerdf
98
from schema_salad.utils import ContextType
109

10+
from ruamel.yaml.comments import CommentedMap
11+
1112
from .cwlviewer import CWLViewer
1213
from .process import Process
1314

cwltool/docker.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ def __init__(
9090
) -> None:
9191
"""Initialize a command line builder using the Docker software container engine."""
9292
super().__init__(builder, joborder, make_path_mapper, requirements, hints, name)
93+
self.docker_exec = "docker"
9394

94-
@staticmethod
9595
def get_image(
96+
self,
9697
docker_requirement: Dict[str, str],
9798
pull_image: bool,
9899
force_pull: bool,
@@ -117,7 +118,7 @@ def get_image(
117118

118119
for line in (
119120
subprocess.check_output( # nosec
120-
["docker", "images", "--no-trunc", "--all"]
121+
[self.docker_exec, "images", "--no-trunc", "--all"]
121122
)
122123
.decode("utf-8")
123124
.splitlines()
@@ -151,7 +152,7 @@ def get_image(
151152
if (force_pull or not found) and pull_image:
152153
cmd = [] # type: List[str]
153154
if "dockerPull" in docker_requirement:
154-
cmd = ["docker", "pull", str(docker_requirement["dockerPull"])]
155+
cmd = [self.docker_exec, "pull", str(docker_requirement["dockerPull"])]
155156
_logger.info(str(cmd))
156157
subprocess.check_call(cmd, stdout=sys.stderr) # nosec
157158
found = True
@@ -160,7 +161,7 @@ def get_image(
160161
with open(os.path.join(dockerfile_dir, "Dockerfile"), "w") as dfile:
161162
dfile.write(docker_requirement["dockerFile"])
162163
cmd = [
163-
"docker",
164+
self.docker_exec,
164165
"build",
165166
"--tag=%s" % str(docker_requirement["dockerImageId"]),
166167
dockerfile_dir,
@@ -169,7 +170,7 @@ def get_image(
169170
subprocess.check_call(cmd, stdout=sys.stderr) # nosec
170171
found = True
171172
elif "dockerLoad" in docker_requirement:
172-
cmd = ["docker", "load"]
173+
cmd = [self.docker_exec, "load"]
173174
_logger.info(str(cmd))
174175
if os.path.exists(docker_requirement["dockerLoad"]):
175176
_logger.info(
@@ -203,7 +204,7 @@ def get_image(
203204
found = True
204205
elif "dockerImport" in docker_requirement:
205206
cmd = [
206-
"docker",
207+
self.docker_exec,
207208
"import",
208209
str(docker_requirement["dockerImport"]),
209210
str(docker_requirement["dockerImageId"]),
@@ -225,8 +226,8 @@ def get_from_requirements(
225226
force_pull: bool,
226227
tmp_outdir_prefix: str,
227228
) -> Optional[str]:
228-
if not shutil.which("docker"):
229-
raise WorkflowException("docker executable is not available")
229+
if not shutil.which(self.docker_exec):
230+
raise WorkflowException(f"{self.docker_exec} executable is not available")
230231

231232
if self.get_image(
232233
cast(Dict[str, str], r), pull_image, force_pull, tmp_outdir_prefix
@@ -341,10 +342,10 @@ def create_runtime(
341342
runtime = [user_space_docker_cmd, "--quiet", "run", "--nobanner"]
342343
else:
343344
runtime = [user_space_docker_cmd, "run"]
344-
elif runtimeContext.podman:
345-
runtime = ["podman", "run", "-i", "--userns=keep-id"]
346345
else:
347-
runtime = ["docker", "run", "-i"]
346+
runtime = [self.docker_exec, "run", "-i"]
347+
if runtimeContext.podman:
348+
runtime.append("--userns=keep-id")
348349
self.append_volume(
349350
runtime, os.path.realpath(self.outdir), self.builder.outdir, writable=True
350351
)
@@ -460,3 +461,20 @@ def create_runtime(
460461
)
461462

462463
return runtime, cidfile_path
464+
465+
466+
class PodmanCommandLineJob(DockerCommandLineJob):
467+
"""Runs a CommandLineJob in a software container using the podman engine."""
468+
469+
def __init__(
470+
self,
471+
builder: Builder,
472+
joborder: CWLObjectType,
473+
make_path_mapper: Callable[..., PathMapper],
474+
requirements: List[CWLObjectType],
475+
hints: List[CWLObjectType],
476+
name: str,
477+
) -> None:
478+
"""Initialize a command line builder using the Podman software container engine."""
479+
super().__init__(builder, joborder, make_path_mapper, requirements, hints, name)
480+
self.docker_exec = "podman"

cwltool/load_tool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
)
2222

2323
from cwl_utils.parser import cwl_v1_2, cwl_v1_2_utils
24-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2524
from schema_salad.exceptions import ValidationException
2625
from schema_salad.ref_resolver import Loader, file_uri
2726
from schema_salad.schema import validate_doc
@@ -34,6 +33,8 @@
3433
json_dumps,
3534
)
3635

36+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
37+
3738
from . import CWL_CONTENT_TYPES, process, update
3839
from .context import LoadingContext
3940
from .errors import GraphTargetMissingException

cwltool/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
import argcomplete
3737
import coloredlogs
3838
import pkg_resources # part of setuptools
39-
import ruamel.yaml
40-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
41-
from ruamel.yaml.main import YAML
4239
from schema_salad.exceptions import ValidationException
4340
from schema_salad.ref_resolver import Loader, file_uri, uri_file_path
4441
from schema_salad.sourceline import cmap, strip_dup_lineno
4542
from schema_salad.utils import ContextType, FetcherCallableType, json_dumps, yaml_no_ts
4643

44+
import ruamel.yaml
45+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
46+
from ruamel.yaml.main import YAML
47+
4748
from . import CWL_CONTENT_TYPES, workflow
4849
from .argparser import arg_parser, generate_parser, get_default_args
4950
from .context import LoadingContext, RuntimeContext, getdefault

cwltool/pack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
cast,
1515
)
1616

17-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1817
from schema_salad.ref_resolver import Loader, SubLoader
1918
from schema_salad.utils import ResolveType
2019

20+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
21+
2122
from .context import LoadingContext
2223
from .load_tool import fetch_document, resolve_and_validate_document
2324
from .process import shortname, uniquename

cwltool/process.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from mypy_extensions import mypyc_attr
3636
from pkg_resources import resource_stream
3737
from rdflib import Graph
38-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3938
from schema_salad.avro.schema import (
4039
Names,
4140
Schema,
@@ -50,6 +49,8 @@
5049
from schema_salad.validate import avro_type_name, validate_ex
5150
from typing_extensions import TYPE_CHECKING
5251

52+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
53+
5354
from .builder import INPUT_OBJ_VOCAB, Builder
5455
from .context import LoadingContext, RuntimeContext, getdefault
5556
from .errors import UnsupportedRequirement, WorkflowException

cwltool/procgenerator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import copy
22
from typing import Dict, Optional, Tuple, cast
33

4-
from ruamel.yaml.comments import CommentedMap
54
from schema_salad.exceptions import ValidationException
65
from schema_salad.sourceline import indent
76

7+
from ruamel.yaml.comments import CommentedMap
8+
89
from .context import LoadingContext, RuntimeContext
910
from .errors import WorkflowException
1011
from .load_tool import load_tool

cwltool/update.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
cast,
1212
)
1313

14-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1514
from schema_salad.exceptions import ValidationException
1615
from schema_salad.ref_resolver import Loader
1716
from schema_salad.sourceline import SourceLine
1817

18+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
19+
1920
from .loghandler import _logger
2021
from .utils import CWLObjectType, CWLOutputType, aslist, visit_class, visit_field
2122

cwltool/validate_js.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from cwl_utils.expression import scanner as scan_expression
2020
from cwl_utils.sandboxjs import code_fragment_to_js, exec_js_process
2121
from pkg_resources import resource_stream
22-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2322
from schema_salad.avro.schema import (
2423
ArraySchema,
2524
EnumSchema,
@@ -31,6 +30,8 @@
3130
from schema_salad.utils import json_dumps
3231
from schema_salad.validate import validate_ex
3332

33+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
34+
3435
from .errors import WorkflowException
3536
from .loghandler import _logger
3637

cwltool/workflow.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
)
1818
from uuid import UUID
1919

20-
from ruamel.yaml.comments import CommentedMap
2120
from schema_salad.exceptions import ValidationException
2221
from schema_salad.sourceline import SourceLine, indent
2322

23+
from ruamel.yaml.comments import CommentedMap
24+
2425
from . import command_line_tool, context, procgenerator
2526
from .checker import circular_dependency_checker, loop_checker, static_checker
2627
from .context import LoadingContext, RuntimeContext, getdefault

tests/test_anon_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from typing import cast
22

33
import pytest
4-
from ruamel.yaml.comments import CommentedMap
54
from schema_salad.sourceline import cmap
65

76
from cwltool.command_line_tool import CommandLineTool
87
from cwltool.context import LoadingContext
8+
from ruamel.yaml.comments import CommentedMap
99

1010
snippet = cast(
1111
CommentedMap,

tests/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import pytest
1616
from cwl_utils.errors import JavascriptException
1717
from cwl_utils.sandboxjs import param_re
18-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1918
from schema_salad.exceptions import ValidationException
2019

2120
import cwltool.checker
@@ -29,6 +28,7 @@
2928
from cwltool.main import main
3029
from cwltool.process import CWL_IANA
3130
from cwltool.utils import CWLObjectType, dedup
31+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
3232

3333
from .util import get_data, get_main_output, needs_docker, working_directory
3434

tests/test_mpi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import pkg_resources
1010
import pytest
11-
from ruamel.yaml.comments import CommentedMap, CommentedSeq
1211
from schema_salad.avro.schema import Names
1312
from schema_salad.utils import yaml_no_ts
1413

@@ -19,6 +18,7 @@
1918
from cwltool.context import LoadingContext, RuntimeContext
2019
from cwltool.main import main
2120
from cwltool.mpi import MpiConfig, MPIRequirementName
21+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2222

2323
from .util import get_data, working_directory
2424

tests/test_path_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import IO, Any, List, cast
55

66
import pytest
7-
from ruamel.yaml.comments import CommentedMap
87
from schema_salad.sourceline import cmap
98

109
from cwltool.command_line_tool import CommandLineTool
@@ -13,6 +12,7 @@
1312
from cwltool.stdfsaccess import StdFsAccess
1413
from cwltool.update import INTERNAL_VERSION
1514
from cwltool.utils import CWLObjectType
15+
from ruamel.yaml.comments import CommentedMap
1616

1717
from .util import needs_docker
1818

tests/test_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from typing import cast
55

66
import pytest
7-
from ruamel.yaml.comments import CommentedMap
87
from schema_salad.sourceline import cmap
98

109
from cwltool.command_line_tool import CommandLineTool
@@ -13,6 +12,7 @@
1312
from cwltool.job import JobBase
1413
from cwltool.update import INTERNAL_VERSION, ORIGINAL_CWLVERSION
1514
from cwltool.utils import CWLObjectType
15+
from ruamel.yaml.comments import CommentedMap
1616

1717
from .util import get_data
1818

0 commit comments

Comments
 (0)