-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path__init__.py
More file actions
90 lines (76 loc) · 3.13 KB
/
Copy path__init__.py
File metadata and controls
90 lines (76 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Durable Task SDK for Python"""
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
from durabletask.grpc_options import GrpcChannelOptions, GrpcRetryPolicyOptions
from durabletask.payload.store import LargePayloadStorageOptions, PayloadStore
from durabletask.worker import (
ActivityWorkItemFilter,
ConcurrencyOptions,
EntityWorkItemFilter,
OrchestrationWorkItemFilter,
VersioningOptions,
WorkItemFilters,
)
__all__ = [
"ActivityWorkItemFilter",
"ConcurrencyOptions",
"EntityWorkItemFilter",
"GrpcChannelOptions",
"GrpcRetryPolicyOptions",
"LargePayloadStorageOptions",
"OrchestrationWorkItemFilter",
"PayloadStore",
"VersioningOptions",
"WorkItemFilters",
]
PACKAGE_NAME = "durabletask"
# Public names are resolved lazily so that merely importing the ``durabletask``
# package - which also happens implicitly when importing anything from the
# ``durabletask.azuremanaged`` distribution, since both share this namespace -
# does not pull in the worker dependency graph (gRPC, protobuf, entities,
# serialization, OpenTelemetry). Client-only applications would otherwise pay
# that cost at process startup.
_LAZY_EXPORTS: dict[str, str] = {
"ActivityWorkItemFilter": "durabletask.worker",
"ConcurrencyOptions": "durabletask.worker",
"EntityWorkItemFilter": "durabletask.worker",
"GrpcChannelOptions": "durabletask.grpc_options",
"GrpcRetryPolicyOptions": "durabletask.grpc_options",
"LargePayloadStorageOptions": "durabletask.payload.store",
"OrchestrationWorkItemFilter": "durabletask.worker",
"PayloadStore": "durabletask.payload.store",
"VersioningOptions": "durabletask.worker",
"WorkItemFilters": "durabletask.worker",
}
# Submodules that the previous eager imports bound as attributes of this package
# as a side effect. Attribute access keeps them reachable without an explicit
# ``import durabletask.<name>``, exactly as before, but they are now imported
# only when actually touched. This list mirrors the old surface and must not be
# extended: ``durabletask.client``, for instance, was never bound this way.
_LAZY_SUBMODULES: frozenset[str] = frozenset({
"entities",
"grpc_options",
"internal",
"payload",
"serialization",
"task",
"worker",
})
def __getattr__(name: str) -> Any:
"""Import and return a lazily exported public name or submodule (PEP 562)."""
module_name = _LAZY_EXPORTS.get(name)
if module_name is None and name not in _LAZY_SUBMODULES:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
from importlib import import_module
if module_name is not None:
value = getattr(import_module(module_name), name)
else:
value = import_module(f".{name}", __name__)
# Cache on the module so subsequent lookups bypass this hook entirely.
globals()[name] = value
return value
def __dir__() -> list[str]:
"""Include lazily exported names that have not been resolved yet."""
return sorted(set(globals()) | set(__all__) | _LAZY_SUBMODULES)