Skip to content

Commit e8bbca3

Browse files
authored
feat: V2 library worker (#1706)
* add V2 library worker * fix parameter passing * fix build-steps typo * fix parameter passing * fix parameter passing for unit & em tests * pipeline fixes * fix official build * fix mapping * python version fix + v2 specific logs * run lib unit tests * remove mypy * feedback * fix otel * this is why we have unit tests * for 3.13, log sdk version * update logs + lint * fix handle event tests * fix proxy unit tests * fix proxy depdency test * reorder patching * lint * test refactoring * slight log refactor * fix tests * add fix for typing inspect get_origin check * lint * add load req unit test
1 parent 4dc9617 commit e8bbca3

File tree

90 files changed

+6761
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+6761
-192
lines changed

.flake8

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
ignore = W503,E402,E731
77

88
exclude = .git, __pycache__, build, dist, .eggs, .github, .local, docs/,
9-
Samples, azure_functions_worker/protos/, proxy_worker/protos/,
10-
azure_functions_worker/_thirdparty/typing_inspect.py,
11-
tests/unittests/test_typing_inspect.py,
12-
tests/unittests/broken_functions/syntax_error/main.py,
13-
.env*, .vscode, venv*, *.venv*
9+
Samples, workers/azure_functions_worker/protos/, workers/proxy_worker/protos/,
10+
workers/azure_functions_worker/_thirdparty/typing_inspect.py,
11+
workers/tests/unittests/test_typing_inspect.py,
12+
workers/tests/unittests/broken_functions/syntax_error/main.py,
13+
.env*, .vscode, venv*, *.venv*,
14+
azure_functions_worker_v2/tests/protos/*,
15+
azure_functions_worker_v2/azure_functions_worker_v2/utils/typing_inspect.py
1416

1517
max-line-length = 88

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,8 @@ prof/
132132
tests/**/host.json
133133
tests/**/bin
134134
tests/**/extensions.csproj
135+
136+
# Azurite related files
137+
__blobstorage__/*
138+
__queuestorage__/*
139+
__azurite*

azure_functions_worker_v2/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# <img src="https://raw.githubusercontent.com/Azure/azure-functions-python-worker/dev/docs/Azure.Functions.svg" width = "30" alt="Functions Header Image - Lightning Logo"> Azure Functions Python Worker
2+
3+
| Branch | Build Status | CodeCov | Test Status |
4+
|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| dev | [![Build Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) | [![codecov](https://codecov.io/gh/Azure/azure-functions-python-worker/branch/dev/graph/badge.svg)](https://codecov.io/gh/Azure/azure-functions-python-worker) | [![Test Status](https://img.shields.io/azure-devops/build/azfunc/public/658/dev)](https://azfunc.visualstudio.com/public/_build/latest?definitionId=658&branchName=dev) |
6+
7+
Python support for Azure Functions is based on Python 3.13 serverless hosting on Linux and the Functions 4.0 runtime.
8+
9+
Here is the current status of Python in Azure Functions:
10+
11+
What are the supported Python versions?
12+
13+
| Azure Functions Runtime | Python 3.13 |
14+
|----------------------------------|-------------|
15+
| Azure Functions 4.0 ||
16+
17+
For information about Azure Functions Runtime, please refer to [Azure Functions runtime versions overview](https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions) page.
18+
19+
### What's available?
20+
21+
- Build, test, debug, and publish using Azure Functions Core Tools (CLI) or Visual Studio Code
22+
- Deploy Python Function project onto consumption, dedicated, elastic premium, or flex consumption plan.
23+
- Deploy Python Function project in a custom docker image onto dedicated or elastic premium plan.
24+
- Triggers / Bindings : Blob, Cosmos DB, Event Grid, Event Hub, HTTP, Kafka, MySQL, Queue, ServiceBus, SQL, Timer, and Warmup
25+
- Triggers / Bindings : Custom binding support
26+
27+
### What's new?
28+
29+
- [SDK Type Bindings for Blob](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-sdk-type-bindings-for-azure-blob-storage-with/ba-p/4146744)
30+
- [HTTP Streaming](https://techcommunity.microsoft.com/t5/azure-compute-blog/azure-functions-support-for-http-streams-in-python-is-now-in/ba-p/4146697)
31+
32+
### Get Started
33+
34+
- [Create your first Python function](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-python)
35+
- [Developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python)
36+
- [Binding API reference](https://docs.microsoft.com/en-us/python/api/azure-functions/azure.functions?view=azure-python)
37+
- [Develop using VS Code](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code)
38+
- [Create a Python Function on Linux using a custom docker image](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-function-linux-custom-image)
39+
40+
# Give Feedback
41+
42+
Issues and feature requests are tracked in a variety of places. To report this feedback, please file an issue to the relevant repository below:
43+
44+
| Item | Description | Link |
45+
|---------------|----------------------------------------------|--------------------------------------------------------------------------------|
46+
| Python Worker | Programming Model, Triggers & Bindings | [File an Issue](https://github.com/Azure/azure-functions-python-worker/issues) |
47+
| Runtime | Script Host & Language Extensibility | [File an Issue](https://github.com/Azure/azure-functions-host/issues) |
48+
| VSCode | VSCode Extension for Azure Functions | [File an Issue](https://github.com/microsoft/vscode-azurefunctions/issues) |
49+
| Core Tools | Command Line Interface for Local Development | [File an Issue](https://github.com/Azure/azure-functions-core-tools/issues) |
50+
| Templates | Code Issues with Creation Template | [File an Issue](https://github.com/Azure/azure-functions-templates/issues) |
51+
52+
# Contribute
53+
54+
This project welcomes contributions and suggestions. Most contributions require you to agree to a
55+
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
56+
the rights to use your contribution. For details, visit https://cla.microsoft.com.
57+
58+
Here are some pointers to get started:
59+
60+
- [Language worker architecture](https://github.com/Azure/azure-functions-python-worker/wiki/Worker-Architecture)
61+
- [Setting up the development environment](https://github.com/Azure/azure-functions-python-worker/wiki/Contributor-Guide)
62+
- [Adding support for a new binding](https://github.com/Azure/azure-functions-python-worker/wiki/Adding-support-for-a-new-binding-type)
63+
- [Release instructions](https://github.com/Azure/azure-functions-python-worker/wiki/Release-Instructions)
64+
65+
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
66+
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
67+
provided by the bot. You will only need to do this once across all repos using our CLA.
68+
69+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
70+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
71+
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
from .handle_event import (worker_init_request,
4+
functions_metadata_request,
5+
function_environment_reload_request,
6+
invocation_request,
7+
function_load_request)
8+
9+
__all__ = ('worker_init_request',
10+
'functions_metadata_request',
11+
'function_environment_reload_request',
12+
'invocation_request',
13+
'function_load_request')
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
import threading
4+
5+
from .retrycontext import RetryContext
6+
from .tracecontext import TraceContext
7+
8+
9+
class Context:
10+
def __init__(self,
11+
func_name: str,
12+
func_dir: str,
13+
invocation_id: str,
14+
thread_local_storage: threading.local,
15+
trace_context: TraceContext,
16+
retry_context: RetryContext) -> None:
17+
self.__func_name = func_name
18+
self.__func_dir = func_dir
19+
self.__invocation_id = invocation_id
20+
self.__thread_local_storage = thread_local_storage
21+
self.__trace_context = trace_context
22+
self.__retry_context = retry_context
23+
24+
@property
25+
def invocation_id(self) -> str:
26+
return self.__invocation_id
27+
28+
@property
29+
def thread_local_storage(self) -> threading.local:
30+
return self.__thread_local_storage
31+
32+
@property
33+
def function_name(self) -> str:
34+
return self.__func_name
35+
36+
@property
37+
def function_directory(self) -> str:
38+
return self.__func_dir
39+
40+
@property
41+
def trace_context(self) -> TraceContext:
42+
return self.__trace_context
43+
44+
@property
45+
def retry_context(self) -> RetryContext:
46+
return self.__retry_context
47+
48+
49+
def get_context(invoc_request, name: str,
50+
directory: str) -> Context:
51+
""" For more information refer:
52+
https://aka.ms/azfunc-invocation-context
53+
"""
54+
trace_context = TraceContext(
55+
invoc_request.trace_context.trace_parent,
56+
invoc_request.trace_context.trace_state,
57+
invoc_request.trace_context.attributes)
58+
59+
retry_context = RetryContext(
60+
invoc_request.retry_context.retry_count,
61+
invoc_request.retry_context.max_retry_count,
62+
invoc_request.retry_context.exception)
63+
64+
return Context(
65+
name, directory, invoc_request.invocation_id,
66+
threading.local(), trace_context, retry_context)

0 commit comments

Comments
 (0)