Coverage for /Users/ajo/work/jumpstarter/jumpstarter/packages/jumpstarter/jumpstarter/driver/decorators.py: 81%
16 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:21 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:21 +0200
1from inspect import isasyncgenfunction, iscoroutinefunction, isfunction, isgeneratorfunction
2from typing import Final
4MARKER_MAGIC: Final[str] = "07c9b9cc"
5MARKER_DRIVERCALL: Final[str] = "marker_drivercall"
6MARKER_STREAMCALL: Final[str] = "marker_streamcall"
7MARKER_STREAMING_DRIVERCALL: Final[str] = "marker_streamingdrivercall"
10def export(func):
11 """
12 Decorator for exporting method as driver call
13 """
14 if isasyncgenfunction(func) or isgeneratorfunction(func):
15 setattr(func, MARKER_STREAMING_DRIVERCALL, MARKER_MAGIC)
16 elif iscoroutinefunction(func) or isfunction(func):
17 setattr(func, MARKER_DRIVERCALL, MARKER_MAGIC)
18 else:
19 raise ValueError(f"unsupported exported function {func}")
20 return func
23def exportstream(func):
24 """
25 Decorator for exporting method as stream
26 """
27 setattr(func, MARKER_STREAMCALL, MARKER_MAGIC)
28 return func