@ -2498,10 +2498,11 @@ def strip_system_libdirs(environment, for_machine: MachineChoice, link_args):
return [ l for l in link_args if l not in exclude ]
return [ l for l in link_args if l not in exclude ]
def process_method_kw ( possible : T . List [ DependencyMethods ] , kwargs ) - > T . List [ DependencyMethods ] :
def process_method_kw ( possible : T . Iterable [ DependencyMethods ] , kwargs ) - > T . List [ DependencyMethods ] :
method = kwargs . get ( ' method ' , ' auto ' )
method = kwargs . get ( ' method ' , ' auto ' ) # type: T.Union[DependencyMethods, str]
if isinstance ( method , DependencyMethods ) :
if isinstance ( method , DependencyMethods ) :
return method
return [ method ]
# TODO: try/except?
if method not in [ e . value for e in DependencyMethods ] :
if method not in [ e . value for e in DependencyMethods ] :
raise DependencyException ( ' method {!r} is invalid ' . format ( method ) )
raise DependencyException ( ' method {!r} is invalid ' . format ( method ) )
method = DependencyMethods ( method )
method = DependencyMethods ( method )
@ -2519,26 +2520,23 @@ def process_method_kw(possible: T.List[DependencyMethods], kwargs) -> T.List[Dep
# Set the detection method. If the method is set to auto, use any available method.
# Set the detection method. If the method is set to auto, use any available method.
# If method is set to a specific string, allow only that detection method.
# If method is set to a specific string, allow only that detection method.
if method == DependencyMethods . AUTO :
if method == DependencyMethods . AUTO :
methods = possible
methods = list ( possible )
elif method in possible :
elif method in possible :
methods = [ method ]
methods = [ method ]
else :
else :
raise DependencyException (
raise DependencyException (
' Unsupported detection method: {} , allowed methods are {} ' . format (
' Unsupported detection method: {} , allowed methods are {} ' . format (
method . value ,
method . value ,
mlog . format_list ( [ x . value for x in [ DependencyMethods . AUTO ] + possible ] ) ) )
mlog . format_list ( [ x . value for x in [ DependencyMethods . AUTO ] + list ( possible ) ] ) ) )
return methods
return methods
if T . TYPE_CHECKING :
if T . TYPE_CHECKING :
FactoryType = T . Callable [ [ Environment , MachineChoice , T . Dict [ str , T . Any ] ] ,
FactoryType = T . TypeVar ( ' FactoryType ' , bound = T . Callable [ . . . , T . List [ T . Callable [ [ ] , ' Dependency ' ] ] ] )
T . List [ ' DependencyType ' ] ]
FullFactoryType = T . Callable [ [ Environment , MachineChoice , T . Dict [ str , T . Any ] , T . Set [ DependencyMethods ] ] ,
T . List [ ' DependencyType ' ] ]
def factory_methods ( methods : T . Set [ DependencyMethods ] ) - > ' FactoryType ' :
def factory_methods ( methods : T . Set [ DependencyMethods ] ) - > T . Callable [ [ ' FactoryType ' ] , ' FactoryType ' ] :
""" Decorator for handling methods for dependency factory functions.
""" Decorator for handling methods for dependency factory functions.
This helps to make factory functions self documenting
This helps to make factory functions self documenting
@ -2547,13 +2545,13 @@ def factory_methods(methods: T.Set[DependencyMethods]) -> 'FactoryType':
>> > pass
>> > pass
"""
"""
def inner ( func : ' FullF actoryType ' ) - > ' FactoryType ' :
def inner ( func : ' FactoryType ' ) - > ' FactoryType ' :
@functools . wraps ( func )
@functools . wraps ( func )
def wrapped ( env : Environment , for_machine : MachineChoice , kwargs : T . Dict [ str , T . Any ] ) - > T . List [ ' DependencyType ' ] :
def wrapped ( env : Environment , for_machine : MachineChoice , kwargs : T . Dict [ str , T . Any ] ) - > T . List [ T . Callable [ [ ] , ' Dependency ' ] ] :
return func ( env , for_machine , kwargs , process_method_kw ( methods , kwargs ) )
return func ( env , for_machine , kwargs , process_method_kw ( methods , kwargs ) )
return wrapped
return T . cast ( ' FactoryType ' , wrapped )
return inner
return inner