25
25
26
26
27
27
def load_binding_registry () -> None :
28
+ """
29
+ Tries to load azure-functions from the customer's BYO. If it's
30
+ not found, it loads the builtin. If the BINDING_REGISTRY is None,
31
+ azure-functions hasn't been loaded in properly.
32
+
33
+ Tries to load the base extension only for python 3.8+.
34
+ """
35
+
28
36
func = sys .modules .get ('azure.functions' )
29
37
30
- # If fails to acquire customer's BYO azure-functions, load the builtin
31
38
if func is None :
32
39
import azure .functions as func
33
40
34
41
global BINDING_REGISTRY
35
42
BINDING_REGISTRY = func .get_binding_registry ()
36
43
37
44
if BINDING_REGISTRY is None :
38
- # If the BINDING_REGISTRY is None, azure-functions hasn't been
39
- # loaded in properly.
40
45
raise AttributeError ('BINDING_REGISTRY is None. azure-functions '
41
46
'library not found. Sys Path: %s. '
42
47
'Sys Modules: %s. '
43
48
'python-packages Path exists: %s.' ,
44
49
sys .path , sys .modules ,
45
50
os .path .exists (CUSTOMER_PACKAGES_PATH ))
46
51
47
- # The base extension supports python 3.8+
48
52
if sys .version_info .minor >= BASE_EXT_SUPPORTED_PY_MINOR_VERSION :
49
- # Import the base extension
50
53
try :
51
54
import azurefunctions .extensions .base as clients
52
55
global DEFERRED_BINDING_REGISTRY
@@ -62,14 +65,17 @@ def load_binding_registry() -> None:
62
65
def get_binding (bind_name : str ,
63
66
is_deferred_binding : typing .Optional [bool ] = False )\
64
67
-> object :
68
+ """
69
+ First checks if the binding is a non-deferred binding. This is
70
+ the most common case.
71
+ Second checks if the binding is a deferred binding.
72
+ If the binding is neither, it's a generic type.
73
+ """
65
74
binding = None
66
- # Common use case
67
75
if binding is None and not is_deferred_binding :
68
76
binding = BINDING_REGISTRY .get (bind_name )
69
- # Binding is deferred binding
70
77
if binding is None and is_deferred_binding :
71
78
binding = DEFERRED_BINDING_REGISTRY .get (bind_name )
72
- # Binding is generic
73
79
if binding is None :
74
80
binding = generic .GenericBinding
75
81
return binding
@@ -108,11 +114,11 @@ def has_implicit_output(bind_name: str) -> bool:
108
114
109
115
def from_incoming_proto (
110
116
binding : str ,
111
- is_deferred_binding : bool ,
112
117
pb : protos .ParameterBinding , * ,
113
118
pytype : typing .Optional [type ],
114
119
trigger_metadata : typing .Optional [typing .Dict [str , protos .TypedData ]],
115
- shmem_mgr : SharedMemoryManager ) -> typing .Any :
120
+ shmem_mgr : SharedMemoryManager ,
121
+ is_deferred_binding : typing .Optional [bool ] = False ) -> typing .Any :
116
122
binding = get_binding (binding , is_deferred_binding )
117
123
if trigger_metadata :
118
124
metadata = {
@@ -239,12 +245,15 @@ def deferred_bindings_decode(binding: typing.Any,
239
245
pytype : typing .Optional [type ],
240
246
datum : typing .Any ,
241
247
metadata : typing .Any ):
242
- # This cache holds deferred binding types (ie. BlobClient, ContainerClient)
243
- # That have already been created, so that the worker can reuse the
244
- # Previously created type without creating a new one.
248
+ """
249
+ This cache holds deferred binding types (ie. BlobClient, ContainerClient)
250
+ That have already been created, so that the worker can reuse the
251
+ Previously created type without creating a new one.
252
+
253
+ If cache is empty or key doesn't exist, deferred_binding_type is None
254
+ """
245
255
global deferred_bindings_cache
246
256
247
- # If cache is empty or key doesn't exist, deferred_binding_type is None
248
257
if deferred_bindings_cache .get ((pb .name ,
249
258
pytype ,
250
259
datum .value .content ), None ) is not None :
@@ -264,8 +273,12 @@ def deferred_bindings_decode(binding: typing.Any,
264
273
def check_deferred_bindings_enabled (param_anno : type ,
265
274
deferred_bindings_enabled : bool ) -> (bool ,
266
275
bool ):
267
- # The first bool represents if deferred bindings is enabled at a fx level
268
- # The second represents if the current binding is deferred binding
276
+ """
277
+ Checks if deferred bindings is enabled at fx and single binding level
278
+
279
+ The first bool represents if deferred bindings is enabled at a fx level
280
+ The second represents if the current binding is deferred binding
281
+ """
269
282
if (DEFERRED_BINDING_REGISTRY is not None
270
283
and DEFERRED_BINDING_REGISTRY .check_supported_type (param_anno )):
271
284
return True , True
0 commit comments