@@ -634,12 +634,10 @@ class FlowGroupEntry:
634
634
635
635
Operation functions can be marked for inclusion into a :class:`FlowGroup`
636
636
by decorating the functions with a corresponding :class:`FlowGroupEntry`.
637
- If the operation requires specific directives, :meth:`~.with_directives`
638
- accepts keyword arguments that are mapped to directives and returns a
639
- decorator that can be applied to the operation to mark it for inclusion in
640
- the group and indicate that it should be executed using the specified
641
- directives. This overrides the default directives specified by
642
- :meth:`flow.directives`.
637
+ If the operation requires group specific directives, calling the
638
+ :class:`FlowGroupEntry` with the keyword argument ``directives`` allows the
639
+ setting of directives for the exclusively for the group. Doing this overrides
640
+ the default directives specified by :meth:`FlowProject.operation`.
643
641
644
642
Parameters
645
643
----------
@@ -673,7 +671,7 @@ def __init__(
673
671
# `@operation`.
674
672
self .group_aggregator = group_aggregator
675
673
676
- def __call__ (self , func ):
674
+ def __call__ (self , func = None , / , * , directives = None ):
677
675
"""Add the function into the group's operations.
678
676
679
677
This call operator allows the class to be used as a decorator.
@@ -683,12 +681,23 @@ def __call__(self, func):
683
681
func : callable
684
682
The function to decorate.
685
683
684
+ directives : dict
685
+ Directives to use for resource requests and execution.
686
+ The directives specified in this decorator are only applied when
687
+ executing the operation through the :class:`FlowGroup`.
688
+ To apply directives to an individual operation executed outside of the
689
+ group, see :meth:`.FlowProject.operation`.
690
+
686
691
Returns
687
692
-------
688
- callable
693
+ func
689
694
The decorated function.
690
-
691
695
"""
696
+ if func is None :
697
+ return functools .partial (self ._internal_call , directives = directives )
698
+ return self ._internal_call (func , directives = directives )
699
+
700
+ def _internal_call (self , func , / , * , directives ):
692
701
if not any (
693
702
func == op_func for _ , op_func in self ._project ._OPERATION_FUNCTIONS
694
703
):
@@ -702,6 +711,13 @@ def __call__(self, func):
702
711
f"Cannot reregister operation '{ func } ' with the group '{ self .name } '."
703
712
)
704
713
func ._flow_groups [self ._project ].add (self .name )
714
+ if directives is None :
715
+ return func
716
+
717
+ if hasattr (func , "_flow_group_operation_directives" ):
718
+ func ._flow_group_operation_directives [self .name ] = directives
719
+ else :
720
+ func ._flow_group_operation_directives = {self .name : directives }
705
721
return func
706
722
707
723
def _set_directives (self , func , directives ):
@@ -729,6 +745,9 @@ def with_directives(self, directives):
729
745
To apply directives to an individual operation executed outside of the
730
746
group, see :meth:`.FlowProject.operation`.
731
747
748
+ Note:
749
+ This method has been deprecated and will be removed in 0.24.0.
750
+
732
751
Parameters
733
752
----------
734
753
directives : dict
@@ -740,6 +759,13 @@ def with_directives(self, directives):
740
759
A decorator which registers the operation with the group using the
741
760
specified directives.
742
761
"""
762
+ _deprecated_warning (
763
+ deprecation = "@FlowGroupEntry.with_directives" ,
764
+ alternative = "Use the directives keyword argument in base decorator e.g. "
765
+ "@FlowGroupEntry(directives={...})." ,
766
+ deprecated_in = "0.23.0" ,
767
+ removed_in = "0.24.0" ,
768
+ )
743
769
744
770
def decorator (func ):
745
771
self ._set_directives (func , directives )
@@ -763,7 +789,7 @@ class FlowGroup:
763
789
764
790
group = FlowProject.make_group(name='example_group')
765
791
766
- @group.with_directives( {"nranks": 4})
792
+ @group(directives= {"nranks": 4})
767
793
@FlowProject.operation({"nranks": 2, "executable": "python3"})
768
794
def op1(job):
769
795
pass
0 commit comments