17
17
18
18
import shellescape
19
19
20
+ from cwltool import singularity
20
21
from .utils import copytree_with_merge , docker_windows_path_adjust , onWindows
21
22
from . import docker
22
23
from .builder import Builder
@@ -425,8 +426,12 @@ def run(self, pull_image=True, rm_container=True,
425
426
try :
426
427
env = cast (MutableMapping [Text , Text ], os .environ )
427
428
if docker_req and kwargs .get ("use_container" ):
428
- img_id = str (docker .get_from_requirements (
429
- docker_req , True , pull_image ))
429
+ if container_manager == "docker" :
430
+ img_id = str (docker .get_from_requirements (
431
+ docker_req , True , pull_image ))
432
+ elif container_manager == "singularity" :
433
+ img_id = str (singularity .get_from_requirements (
434
+ docker_req , True , pull_image ))
430
435
if img_id is None :
431
436
if self .builder .find_default_container :
432
437
default_container = self .builder .find_default_container ()
@@ -437,16 +442,17 @@ def run(self, pull_image=True, rm_container=True,
437
442
if docker_req and img_id is None and kwargs .get ("use_container" ):
438
443
raise Exception ("Docker image not available" )
439
444
except Exception as e :
440
- _logger .debug ("Docker error" , exc_info = True )
445
+ container = container_manager .capitalize ()
446
+ _logger .debug ("%s error" % container , exc_info = True )
441
447
if docker_is_req :
442
448
raise UnsupportedRequirement (
443
- "Docker is required to run this tool: %s" % e )
449
+ "%s is required to run this tool: %s" % ( container , e ) )
444
450
else :
445
451
raise WorkflowException (
446
- "Docker is not available for this tool, try "
447
- "--no-container to disable Docker , or install "
452
+ "{0} is not available for this tool, try "
453
+ "--no-container to disable {0} , or install "
448
454
"a user space Docker replacement like uDocker with "
449
- "--user-space-docker-cmd.: %s" % e )
455
+ "--user-space-docker-cmd.: {1}" . format ( container , e ) )
450
456
451
457
self ._setup (kwargs )
452
458
@@ -506,7 +512,6 @@ def run(self, pull_image=True, rm_container=True,
506
512
507
513
for t , v in self .environment .items ():
508
514
runtime .append (u"--env=%s=%s" % (t , v ))
509
- runtime .append (img_id )
510
515
511
516
elif container_manager == "singularity" :
512
517
runtime = [u"singularity" , u"--quiet" , u"exec" ]
@@ -535,7 +540,7 @@ def run(self, pull_image=True, rm_container=True,
535
540
for t , v in self .environment .items ():
536
541
env ["SINGULARITYENV_" + t ] = v
537
542
538
- runtime .append ("docker://" + img_id )
543
+ runtime .append (img_id )
539
544
540
545
self ._execute (
541
546
runtime , env , rm_tmpdir = rm_tmpdir , move_outputs = move_outputs )
0 commit comments