@@ -317,38 +317,13 @@ def __init__(
317
317
318
318
@property
319
319
def command_args (self ):
320
- """Get command line arguments, returns a list if task has a state """
320
+ """Get command line arguments"""
321
321
if is_lazy (self .inputs ):
322
322
raise Exception ("can't return cmdline, self.inputs has LazyFields" )
323
- orig_inputs = attr .asdict (self .inputs , recurse = False )
324
323
if self .state :
325
- command_args_list = []
326
- self .state .prepare_states (self .inputs )
327
- for ii , el in enumerate (self .state .states_ind ):
328
- command_args_list .append (self ._command_args_single (el , index = ii ))
329
- self .inputs = attr .evolve (self .inputs , ** orig_inputs )
330
- return command_args_list
331
- else :
332
- command_args = self ._command_args_single ()
333
- self .inputs = attr .evolve (self .inputs , ** orig_inputs )
334
- return command_args
335
-
336
- def _command_args_single (self , state_ind = None , index = None ):
337
- """Get command line arguments for a single state
324
+ raise NotImplementedError
338
325
339
- Parameters
340
- ----------
341
- state_ind : dict[str, int]
342
- Keys are inputs being mapped over, values are indices within that input
343
- index : int
344
- Index in flattened list of states
345
- """
346
- if index is not None :
347
- modified_inputs = template_update (
348
- self .inputs , output_dir = self .output_dir [index ], state_ind = state_ind
349
- )
350
- else :
351
- modified_inputs = template_update (self .inputs , output_dir = self .output_dir )
326
+ modified_inputs = template_update (self .inputs , output_dir = self .output_dir )
352
327
if modified_inputs is not None :
353
328
self .inputs = attr .evolve (self .inputs , ** modified_inputs )
354
329
@@ -366,15 +341,13 @@ def _command_args_single(self, state_ind=None, index=None):
366
341
):
367
342
continue
368
343
if name == "executable" :
369
- pos_args .append (
370
- self ._command_shelltask_executable (field , state_ind , index )
371
- )
344
+ pos_args .append (self ._command_shelltask_executable (field ))
372
345
elif name == "args" :
373
- pos_val = self ._command_shelltask_args (field , state_ind , index )
346
+ pos_val = self ._command_shelltask_args (field )
374
347
if pos_val :
375
348
pos_args .append (pos_val )
376
349
else :
377
- pos_val = self ._command_pos_args (field , state_ind , index )
350
+ pos_val = self ._command_pos_args (field )
378
351
if pos_val :
379
352
pos_args .append (pos_val )
380
353
@@ -383,39 +356,35 @@ def _command_args_single(self, state_ind=None, index=None):
383
356
# pos_args values are each a list of arguments, so concatenate lists after sorting
384
357
return sum (cmd_args , [])
385
358
386
- def _field_value (self , field , state_ind , index , check_file = False ):
359
+ def _field_value (self , field , check_file = False ):
387
360
"""
388
361
Checking value of the specific field, if value is not set, None is returned.
389
- If state_ind and ind, taking a specific element of the field.
390
362
check_file has no effect, but subclasses can use it to validate or modify
391
363
filenames.
392
364
"""
393
- name = f"{ self .name } .{ field .name } "
394
365
value = getattr (self .inputs , field .name )
395
- if self .state and name in state_ind :
396
- value = value [state_ind [name ]]
397
366
if value == attr .NOTHING :
398
367
value = None
399
368
return value
400
369
401
- def _command_shelltask_executable (self , field , state_ind , index ):
370
+ def _command_shelltask_executable (self , field ):
402
371
"""Returining position and value for executable ShellTask input"""
403
372
pos = 0 # executable should be the first el. of the command
404
- value = self ._field_value (field , state_ind , index )
373
+ value = self ._field_value (field )
405
374
if value is None :
406
375
raise ValueError ("executable has to be set" )
407
376
return pos , ensure_list (value , tuple2list = True )
408
377
409
- def _command_shelltask_args (self , field , state_ind , index ):
378
+ def _command_shelltask_args (self , field ):
410
379
"""Returining position and value for args ShellTask input"""
411
380
pos = - 1 # assuming that args is the last el. of the command
412
- value = self ._field_value (field , state_ind , index , check_file = True )
381
+ value = self ._field_value (field , check_file = True )
413
382
if value is None :
414
383
return None
415
384
else :
416
385
return pos , ensure_list (value , tuple2list = True )
417
386
418
- def _command_pos_args (self , field , state_ind , index ):
387
+ def _command_pos_args (self , field ):
419
388
"""
420
389
Checking all additional input fields, setting pos to None, if position not set.
421
390
Creating a list with additional parts of the command that comes from
@@ -443,7 +412,7 @@ def _command_pos_args(self, field, state_ind, index):
443
412
# Shift negatives down to allow args to be -1
444
413
pos += 1 if pos >= 0 else - 1
445
414
446
- value = self ._field_value (field , state_ind , index , check_file = True )
415
+ value = self ._field_value (field , check_file = True )
447
416
if field .metadata .get ("readonly" , False ) and value is not None :
448
417
raise Exception (f"{ field .name } is read only, the value can't be provided" )
449
418
elif (
@@ -453,12 +422,7 @@ def _command_pos_args(self, field, state_ind, index):
453
422
):
454
423
return None
455
424
456
- # getting stated inputs
457
- inputs_dict_st = attr .asdict (self .inputs , recurse = False )
458
- if state_ind is not None :
459
- for k , v in state_ind .items ():
460
- k = k .split ("." )[1 ]
461
- inputs_dict_st [k ] = inputs_dict_st [k ][v ]
425
+ inputs_dict = attr .asdict (self .inputs , recurse = False )
462
426
463
427
cmd_add = []
464
428
# formatter that creates a custom command argument
@@ -470,10 +434,10 @@ def _command_pos_args(self, field, state_ind, index):
470
434
if argnm == "field" :
471
435
call_args_val [argnm ] = value
472
436
elif argnm == "inputs" :
473
- call_args_val [argnm ] = inputs_dict_st
437
+ call_args_val [argnm ] = inputs_dict
474
438
else :
475
- if argnm in inputs_dict_st :
476
- call_args_val [argnm ] = inputs_dict_st [argnm ]
439
+ if argnm in inputs_dict :
440
+ call_args_val [argnm ] = inputs_dict [argnm ]
477
441
else :
478
442
raise AttributeError (
479
443
f"arguments of the formatter function from { field .name } "
@@ -534,21 +498,12 @@ def cmdline(self):
534
498
raise Exception ("can't return cmdline, self.inputs has LazyFields" )
535
499
# checking the inputs fields before returning the command line
536
500
self .inputs .check_fields_input_spec ()
501
+ if self .state :
502
+ raise NotImplementedError
537
503
if isinstance (self , ContainerTask ):
538
- if self .state :
539
- cmdline = []
540
- for con , com in zip (self .container_args , self .command_args ):
541
- cmdline .append (" " .join (con + com ))
542
- else :
543
- cmdline = " " .join (self .container_args + self .command_args )
504
+ cmdline = " " .join (self .container_args + self .command_args )
544
505
else :
545
- if self .state :
546
- cmdline = []
547
- for el in self .command_args :
548
- cmdline .append (" " .join (el ))
549
- else :
550
- cmdline = " " .join (self .command_args )
551
-
506
+ cmdline = " " .join (self .command_args )
552
507
return cmdline
553
508
554
509
def _run_task (self ):
@@ -628,18 +583,17 @@ def __init__(
628
583
** kwargs ,
629
584
)
630
585
631
- def _field_value (self , field , state_ind , index , check_file = False ):
586
+ def _field_value (self , field , check_file = False ):
632
587
"""
633
588
Checking value of the specific field, if value is not set, None is returned.
634
- If state_ind and ind, taking a specific element of the field.
635
589
If check_file is True, checking if field is a a local file
636
590
and settings bindings if needed.
637
591
"""
638
- value = super ()._field_value (field , state_ind , index )
592
+ value = super ()._field_value (field )
639
593
if value and check_file and is_local_file (field ):
640
594
# changing path to the cpath (the directory should be mounted)
641
595
lpath = Path (str (value ))
642
- cdir = self .bind_paths (index )[lpath .parent ][0 ]
596
+ cdir = self .bind_paths ()[lpath .parent ][0 ]
643
597
cpath = cdir .joinpath (lpath .name )
644
598
value = str (cpath )
645
599
return value
@@ -655,7 +609,7 @@ def container_check(self, container_type):
655
609
if self .inputs .image is attr .NOTHING :
656
610
raise AttributeError ("Container image is not specified" )
657
611
658
- def bind_paths (self , index = None ):
612
+ def bind_paths (self ):
659
613
"""Get bound mount points
660
614
661
615
Returns
@@ -667,10 +621,7 @@ def bind_paths(self, index=None):
667
621
output_dir_cpath = None
668
622
if self .inputs .bindings is None :
669
623
self .inputs .bindings = []
670
- if index is None :
671
- output_dir = self .output_dir
672
- else :
673
- output_dir = self .output_dir [index ]
624
+ output_dir = self .output_dir
674
625
for binding in self .inputs .bindings :
675
626
binding = list (binding )
676
627
if len (binding ) == 3 :
@@ -691,15 +642,15 @@ def bind_paths(self, index=None):
691
642
bind_paths [output_dir ] = (self .output_cpath , "rw" )
692
643
return bind_paths
693
644
694
- def binds (self , opt , index = None ):
645
+ def binds (self , opt ):
695
646
"""
696
647
Specify mounts to bind from local filesystems to container and working directory.
697
648
698
649
Uses py:meth:`bind_paths`
699
650
700
651
"""
701
652
bargs = []
702
- for lpath , (cpath , mode ) in self .bind_paths (index ).items ():
653
+ for lpath , (cpath , mode ) in self .bind_paths ().items ():
703
654
bargs .extend ([opt , f"{ lpath } :{ cpath } :{ mode } " ])
704
655
return bargs
705
656
@@ -775,31 +726,15 @@ def container_args(self):
775
726
raise Exception ("can't return container_args, self.inputs has LazyFields" )
776
727
self .container_check ("docker" )
777
728
if self .state :
778
- self .state .prepare_states (self .inputs )
779
- cargs_list = []
780
- for ii , el in enumerate (self .state .states_ind ):
781
- if f"{ self .name } .image" in el :
782
- cargs_list .append (
783
- self ._container_args_single (
784
- self .inputs .image [el [f"{ self .name } .image" ]], index = ii
785
- )
786
- )
787
- else :
788
- cargs_list .append (
789
- self ._container_args_single (self .inputs .image , index = ii )
790
- )
791
- return cargs_list
792
- else :
793
- return self ._container_args_single (self .inputs .image )
729
+ raise NotImplementedError
794
730
795
- def _container_args_single (self , image , index = None ):
796
731
cargs = ["docker" , "run" ]
797
732
if self .inputs .container_xargs is not None :
798
733
cargs .extend (self .inputs .container_xargs )
799
734
800
- cargs .extend (self .binds ("-v" , index ))
735
+ cargs .extend (self .binds ("-v" ))
801
736
cargs .extend (["-w" , str (self .output_cpath )])
802
- cargs .append (image )
737
+ cargs .append (self . inputs . image )
803
738
804
739
return cargs
805
740
@@ -869,30 +804,14 @@ def container_args(self):
869
804
raise Exception ("can't return container_args, self.inputs has LazyFields" )
870
805
self .container_check ("singularity" )
871
806
if self .state :
872
- self .state .prepare_states (self .inputs )
873
- cargs_list = []
874
- for ii , el in enumerate (self .state .states_ind ):
875
- if f"{ self .name } .image" in el :
876
- cargs_list .append (
877
- self ._container_args_single (
878
- self .inputs .image [el [f"{ self .name } .image" ]], index = ii
879
- )
880
- )
881
- else :
882
- cargs_list .append (
883
- self ._container_args_single (self .inputs .image , index = ii )
884
- )
885
- return cargs_list
886
- else :
887
- return self ._container_args_single (self .inputs .image )
807
+ raise NotImplementedError
888
808
889
- def _container_args_single (self , image , index = None ):
890
809
cargs = ["singularity" , "exec" ]
891
810
892
811
if self .inputs .container_xargs is not None :
893
812
cargs .extend (self .inputs .container_xargs )
894
813
895
- cargs .extend (self .binds ("-B" , index ))
814
+ cargs .extend (self .binds ("-B" ))
896
815
cargs .extend (["--pwd" , str (self .output_cpath )])
897
- cargs .append (image )
816
+ cargs .append (self . inputs . image )
898
817
return cargs
0 commit comments