43
43
from .mock import MockMixin
44
44
45
45
if ty .TYPE_CHECKING :
46
- from pydra .engine .specs import TaskDef , OutputsType
47
46
from .converter_helpers import Converter
48
47
49
48
@@ -501,7 +500,6 @@ def matching_exts(
501
500
def convert (
502
501
cls ,
503
502
fileset : "FileSet" ,
504
- worker : ty .Optional [str ] = None ,
505
503
** kwargs : ty .Any ,
506
504
) -> Self :
507
505
"""Convert a given file-set into the format specified by the class
@@ -510,12 +508,8 @@ def convert(
510
508
----------
511
509
fileset : FileSet
512
510
the file-set object to convert
513
- plugin : str
514
- the "execution plugin" used to run the conversion task
515
- task_name : str
516
- the name given to the converter task
517
511
**kwargs
518
- args to pass to the conversion process
512
+ args to pass to customise the converter task definition
519
513
520
514
Returns
521
515
-------
@@ -525,12 +519,14 @@ def convert(
525
519
import attrs
526
520
527
521
# Make unique, yet somewhat recognisable task name
528
- task = cls .get_converter (source_format = type (fileset ), ** kwargs )
529
- if task is None :
530
- return copy (fileset ) # type: ignore[return-value]
531
- task = attrs .evolve (task , in_file = fileset )
532
- outputs = task (worker = worker )
533
- out_file = outputs .out_file
522
+ converter = cls .get_converter (source_format = type (fileset ))
523
+ if converter is None :
524
+ assert isinstance (fileset , cls )
525
+ return copy (fileset )
526
+ kwargs [converter .in_file ] = fileset
527
+ task_def = attrs .evolve (converter .task_def , ** kwargs )
528
+ outputs = task_def ()
529
+ out_file = getattr (outputs , converter .out_file )
534
530
if not isinstance (out_file , cls ):
535
531
out_file = cls (out_file )
536
532
return out_file # type: ignore
@@ -539,8 +535,7 @@ def convert(
539
535
def get_converter (
540
536
cls ,
541
537
source_format : ty .Type [DataType ],
542
- ** kwargs : ty .Any ,
543
- ) -> "TaskDef[OutputsType] | None" :
538
+ ) -> "Converter | None" :
544
539
"""Get a converter that converts from the source format type
545
540
into the format specified by the class
546
541
@@ -577,7 +572,7 @@ def get_converter(
577
572
else :
578
573
import_extras_module (unclassified )
579
574
try :
580
- converter_def = converters [source_format ]
575
+ converter = converters [source_format ]
581
576
except KeyError :
582
577
# If no direct mapping check for mapping from source super types and wildcard
583
578
# matches
@@ -608,36 +603,30 @@ def get_converter(
608
603
f"from PyPI (e.g. pip install { extras_mod .pypi } ) or check it isn't broken"
609
604
)
610
605
raise FormatConversionError (msg ) from None
611
- converter_def = available_converters [0 ]
606
+ converter = available_converters [0 ]
612
607
# Store mapping for future reference
613
- converters [source_format ] = converter_def
614
- if kwargs :
615
- task_def = copy (converter_def .task_def )
616
- for key , val in kwargs .items ():
617
- setattr (task_def , key , val )
618
- else :
619
- task_def = converter_def .task_def
620
- return task_def
608
+ converters [source_format ] = converter
609
+ return converter
621
610
622
611
@classmethod
623
612
def get_converters_dict (
624
613
cls , klass : ty .Optional [ty .Type [DataType ]] = None
625
- ) -> ty .Dict [ty .Type [DataType ], "Converter[ty.Any] " ]:
614
+ ) -> ty .Dict [ty .Type [DataType ], "Converter" ]:
626
615
# Only access converters to the specific class, not superclasses (which may not
627
616
# be able to convert to the specific type)
628
617
if klass is None :
629
618
klass = cls
630
619
# import related extras module for the target class
631
620
import_extras_module (klass )
632
- converters_dict : ty .Dict [ty .Type [DataType ], "Converter[ty.Any] " ]
621
+ converters_dict : ty .Dict [ty .Type [DataType ], "Converter" ]
633
622
try :
634
623
converters_dict = klass .__dict__ ["converters" ]
635
624
except KeyError :
636
625
converters_dict = klass .converters = {}
637
626
return converters_dict
638
627
639
628
@classmethod
640
- def get_converter_defs (cls , source_format : type ) -> ty .List ["Converter[ty.Any] " ]:
629
+ def get_converter_defs (cls , source_format : type ) -> ty .List ["Converter" ]:
641
630
"""Search the registered converters to find any matches and return list of
642
631
task and associated key-word args to perform the conversion between source and
643
632
target formats
@@ -669,7 +658,7 @@ def get_converter_defs(cls, source_format: type) -> ty.List["Converter[ty.Any]"]
669
658
def register_converter (
670
659
cls ,
671
660
source_format : ty .Type ["FileSet" ],
672
- converter : "Converter[T] " ,
661
+ converter : "Converter" ,
673
662
) -> None :
674
663
"""Registers a converter task within a class attribute. Called by the
675
664
@fileformats.core.converter decorator.
0 commit comments