57
57
SpecInfo ,
58
58
ShellSpec ,
59
59
ShellOutSpec ,
60
- ContainerSpec ,
61
60
attr_fields ,
62
61
)
63
62
from .helpers import (
67
66
output_from_inputfields ,
68
67
parse_copyfile ,
69
68
)
70
- from .helpers_file import template_update , is_local_file
69
+ from .helpers_file import template_update
71
70
from ..utils .typing import TypeParser
72
71
from .environments import Native
73
72
@@ -342,10 +341,7 @@ def command_args(self, root=None):
342
341
343
342
pos_args = [] # list for (position, command arg)
344
343
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 ):
349
345
name , meta = field .name , field .metadata
350
346
if (
351
347
getattr (self .inputs , name ) is attr .NOTHING
@@ -527,13 +523,9 @@ def cmdline(self):
527
523
self .inputs .check_fields_input_spec ()
528
524
if self .state :
529
525
raise NotImplementedError
530
- if isinstance (self , ContainerTask ):
531
- command_args = self .container_args + self .command_args ()
532
- else :
533
- command_args = self .command_args ()
534
526
# 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 :]:
537
529
# If there are spaces in the arg, and it is not enclosed by matching
538
530
# quotes, add quotes to escape the space. Not sure if this should
539
531
# be expanded to include other special characters apart from spaces
@@ -556,11 +548,6 @@ def _prepare_bindings(self, root: str):
556
548
"""
557
549
for fld in attr_fields (self .inputs ):
558
550
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"
564
551
fileset = getattr (self .inputs , fld .name )
565
552
copy = parse_copyfile (fld )[0 ] == FileSet .CopyMode .copy
566
553
@@ -578,134 +565,6 @@ def _prepare_bindings(self, root: str):
578
565
DEFAULT_COPY_COLLATION = FileSet .CopyCollation .adjacent
579
566
580
567
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
-
709
568
def split_cmd (cmd : str ):
710
569
"""Splits a shell command line into separate arguments respecting quotes
711
570
0 commit comments