in azure/functions/extension/func_extension_base.py [0:0]
def __init__(self, file_path: str):
"""Constructor for extension. This needs to be implemented and ensure
super().__init__(file_path) is called.
The initializer serializes the extension to a tree. This speeds
up the worker lookup and reduce the overhead on each invocation.
_func_exts[<trigger_name>].<hook_name>.(ext_name, ext_impl)
(e.g. _func_exts['HttpTrigger'].pre_invocation.ext_impl)
Parameters
----------
file_path: str
The name of trigger the extension attaches to (e.g. __file__).
"""
script_root = os.getenv('AzureWebJobsScriptRoot')
if script_root is None:
raise FunctionExtensionException(
'AzureWebJobsScriptRoot environment variable is not defined. '
'Please ensure the extension is running in Azure Functions.'
)
# Split will always return ('') in if no folder exist in the path
relpath_to_project_root = os.path.relpath(
os.path.normpath(file_path),
os.path.normpath(script_root)
)
trigger_name = (relpath_to_project_root.split(os.sep) or [''])[0]
if not trigger_name or trigger_name.startswith(('.', '..')):
raise FunctionExtensionException(
'Failed to parse trigger name from filename. '
'Function extension should bind to a trigger script, '
'not share folder. Please ensure extension is create inside a'
'trigger while __file__ is passed into the argument. '
'The trigger name is resolved from os.path.relpath(file_path,'
'project_root).'
)
# This is used in ExtensionMeta._register_function_extension
self._trigger_name = trigger_name