66which are managed by Orca-core.
77"""
88
9- from io import StringIO
109import re
1110import sys
1211import asyncio
5251
5352from orca_python import envs
5453from orca_python .exceptions import (
55- BrokenRemoteAlgorithmStubs ,
5654 InvalidDependency ,
5755 InvalidWindowArgument ,
5856 InvalidAlgorithmArgument ,
57+ BrokenRemoteAlgorithmStubs ,
5958 InvalidAlgorithmReturnType ,
6059 InvalidMetadataFieldArgument ,
6160)
@@ -207,13 +206,15 @@ def __call__(
207206 self , params : ExecutionParams , * args : Any , ** kwargs : Any
208207 ) -> returnResult : ...
209208
209+
210210@dataclass
211- class RemoteAlgorithm () :
211+ class RemoteAlgorithm :
212212 ProcessorName : str
213213 ProcessorRuntime : str
214214 Name : str
215215 Version : str
216216
217+
217218T = TypeVar ("T" , bound = AlgorithmFn )
218219
219220
@@ -331,7 +332,9 @@ def _add_algorithm(self, name: str, algorithm: Algorithm) -> None:
331332 )
332333 self ._algorithms [name ] = algorithm
333334
334- def _add_dependency (self , algorithm : str , dependency : AlgorithmFn , remote : bool = False ) -> None :
335+ def _add_dependency (
336+ self , algorithm : str , dependency : AlgorithmFn , remote : bool = False
337+ ) -> None :
335338 """
336339 Adds a dependency to an algorithm.
337340
@@ -345,22 +348,23 @@ def _add_dependency(self, algorithm: str, dependency: AlgorithmFn, remote: bool
345348 """
346349 LOGGER .debug (f"Adding dependency for algorithm: { algorithm } " )
347350 if remote :
348- # TODO: how do we resolve this - we need information about a remote
349- # algorithm but do not have it. We don't want to go further than stubs as
350- # it makes deployment messy.
351351 remoteDepMetadata = getattr (dependency , "__orca_metadata__" , None )
352352 if remoteDepMetadata is None :
353- raise BrokenRemoteAlgorithmStubs ("Could not parse metadata from Orca stubs. Rerun stub generation: `orca sync`" )
353+ raise BrokenRemoteAlgorithmStubs (
354+ "Could not parse metadata from Orca stubs. Rerun stub generation: `orca sync`"
355+ )
354356 try :
355357 remoteAlgo = RemoteAlgorithm (** remoteDepMetadata )
356358 except Exception as e :
357- raise BrokenRemoteAlgorithmStubs (f"Could not parse metadata from Orca stubs: { e } Rerun stub generation: `orca sync`" )
359+ raise BrokenRemoteAlgorithmStubs (
360+ f"Could not parse metadata from Orca stubs: { e } Rerun stub generation: `orca sync`"
361+ )
358362
359363 if algorithm not in self ._remoteDependencies :
360364 self ._remoteDependencies [algorithm ] = [remoteAlgo ]
361365 else :
362366 self ._remoteDependencies [algorithm ].append (remoteAlgo )
363-
367+
364368 return
365369
366370 dependencyAlgo = None
@@ -694,7 +698,7 @@ def Register(self) -> None:
694698 algo_msg .window_type .version = algorithm .window_type .version
695699 algo_msg .window_type .description = algorithm .window_type .description
696700
697- # Fill in metadata fields if present
701+ # fill in metadata fields if present
698702 if len (algorithm .window_type .metadataFields ) > 0 :
699703 for metadataField in algorithm .window_type .metadataFields :
700704 metadata_fields_msg = algo_msg .window_type .metadataFields .add ()
@@ -709,10 +713,12 @@ def Register(self) -> None:
709713 dep_msg .version = dep .version
710714 dep_msg .processor_name = dep .processor
711715 dep_msg .processor_runtime = dep .runtime
712-
716+
713717 # Add remote dependencies if they exist
714718 if algorithm .full_name in self ._algorithmsSingleton ._remoteDependencies :
715- for dep in self ._algorithmsSingleton ._remoteDependencies [algorithm .full_name ]:
719+ for dep in self ._algorithmsSingleton ._remoteDependencies [
720+ algorithm .full_name
721+ ]:
716722 dep_msg = algo_msg .dependencies .add ()
717723 dep_msg .name = dep .Name
718724 dep_msg .version = dep .Version
@@ -840,7 +846,7 @@ def algorithm(
840846 f"Version '{ version } ' must follow basic semantic "
841847 "versioning (e.g., '1.0.0') without release portions"
842848 )
843-
849+
844850 def inner (algo : T ) -> T :
845851 def wrapper (
846852 params : ExecutionParams ,
@@ -892,14 +898,18 @@ def wrapper(
892898 )
893899
894900 for dependency in depends_on :
895- if not getattr (dependency , "__orca_is_remote__" , False ) and not self ._algorithmsSingleton ._has_algorithm_fn (dependency ):
901+ if not getattr (
902+ dependency , "__orca_is_remote__" , False
903+ ) and not self ._algorithmsSingleton ._has_algorithm_fn (dependency ):
896904 message = (
897905 f"Cannot add function `{ dependency .__name__ } ` to dependency stack. All dependencies must "
898906 "be decorated with `@algorithm` before they can be used as dependencies."
899907 )
900908 raise InvalidDependency (message )
901909 self ._algorithmsSingleton ._add_dependency (
902- algorithm .full_name , dependency , getattr (dependency , "__orca_is_remote__" , False )
910+ algorithm .full_name ,
911+ dependency ,
912+ getattr (dependency , "__orca_is_remote__" , False ),
903913 )
904914
905915 # TODO: check for circular dependencies. It's not easy to create one in python as the function
0 commit comments