Skip to content

Commit cf747d6

Browse files
committed
lint + public build
1 parent 9ff0466 commit cf747d6

File tree

19 files changed

+140
-70
lines changed

19 files changed

+140
-70
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ignore = W503,E402,E731
77

88
exclude = .git, __pycache__, build, dist, .eggs, .github, .local, docs/,
99
Samples, azure_functions_worker/protos/,
10-
azure_functions_worker/_thirdparty/typing_inspect.py,
10+
azure_functions_worker/utils/typing_inspect.py,
1111
tests/unittests/test_typing_inspect.py,
1212
tests/unittests/broken_functions/syntax_error/main.py,
1313
tests/protos/,

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# For all file changes, github would automatically
1111
# include the following people in the PRs.
1212

13-
* @vrdmr @gavin-aguiar @YunchuWang @pdthummar @hallvictoria
13+
* @vrdmr @gavin-aguiar @hallvictoria

azure_functions_worker/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
from .handle_event import worker_init_request, functions_metadata_request, function_environment_reload_request, invocation_request, functions_load_request
4+
from .handle_event import (worker_init_request,
5+
functions_metadata_request,
6+
function_environment_reload_request,
7+
invocation_request,
8+
functions_load_request)
59

6-
__all__ = ('worker_init_request', 'functions_metadata_request', 'function_environment_reload_request', 'invocation_request', 'functions_load_request')
10+
__all__ = ('worker_init_request',
11+
'functions_metadata_request',
12+
'function_environment_reload_request',
13+
'invocation_request',
14+
'functions_load_request')

azure_functions_worker/bindings/context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def retry_context(self) -> RetryContext:
5050

5151

5252
def get_context(invoc_request, name: str,
53-
directory: str) -> Context:
53+
directory: str) -> Context:
5454
""" For more information refer:
5555
https://aka.ms/azfunc-invocation-context
5656
"""

azure_functions_worker/bindings/datumdef.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
to_nullable_timestamp,
1515
)
1616

17-
from ..logging import logger
18-
1917
try:
2018
from http.cookies import SimpleCookie
2119
except ImportError:
@@ -69,8 +67,9 @@ def __repr__(self):
6967
def from_typed_data(cls, protos):
7068
try:
7169
td = protos.TypedData
72-
except Exception as ex:
73-
# Todo: better catch for Datum.from_typed_data(http.body) -- if the data being sent in is already protos.TypedData
70+
except Exception:
71+
# Todo: better catch for Datum.from_typed_data(http.body)
72+
# if the data being sent in is already protos.TypedData
7473
td = protos
7574
tt = td.WhichOneof('data')
7675
if tt == 'http':
@@ -116,7 +115,7 @@ def from_typed_data(cls, protos):
116115
return cls(val, tt)
117116

118117

119-
def datum_as_proto(datum: Datum, protos):
118+
def datum_as_proto(datum: Datum, protos):
120119
if datum.type == 'string':
121120
return protos.TypedData(string=datum.value)
122121
elif datum.type == 'bytes':

azure_functions_worker/functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def is_context_required(params, bound_params: dict,
136136
def validate_function_params(params: dict, bound_params: dict,
137137
annotations: dict, func_name: str,
138138
protos):
139-
logger.info("Params: %s, BoundParams: %s, Annotations: %s, FuncName: %s", params, bound_params, annotations, func_name)
139+
logger.info("Params: %s, BoundParams: %s, Annotations: %s, FuncName: %s",
140+
params, bound_params, annotations, func_name)
140141
if set(params) - set(bound_params):
141142
raise FunctionLoadError(
142143
func_name,

azure_functions_worker/handle_event.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import sys
88

9-
from datetime import datetime
109
from typing import List, Optional
1110

1211
from .functions import FunctionInfo, Registry
@@ -22,7 +21,9 @@
2221
from .otel import otel_manager, initialize_azure_monitor, configure_opentelemetry
2322

2423
from .bindings.context import get_context
25-
from .bindings.meta import load_binding_registry, is_trigger_binding, from_incoming_proto, to_outgoing_param_binding, to_outgoing_proto
24+
from .bindings.meta import (load_binding_registry, is_trigger_binding,
25+
from_incoming_proto, to_outgoing_param_binding,
26+
to_outgoing_proto)
2627
from .bindings.out import Out
2728
from .utils.constants import (FUNCTION_DATA_CACHE,
2829
RAW_HTTP_BODY_BYTES,
@@ -56,7 +57,6 @@
5657
protos = None
5758

5859

59-
# Protos will be the retry / binding / metadata protos object that we populate and return
6060
async def worker_init_request(request):
6161
logger.info("Library Worker: received worker_init_request")
6262
global result, _host, protos, _function_data_cache_enabled
@@ -83,14 +83,14 @@ async def worker_init_request(request):
8383
if otel_manager.get_azure_monitor_available():
8484
capabilities[WORKER_OPEN_TELEMETRY_ENABLED] = TRUE
8585

86-
8786
# loading bindings registry and saving results to a static
8887
# dictionary which will be later used in the invocation request
8988
load_binding_registry()
9089

9190
try:
92-
result = asyncio.create_task(load_function_metadata(init_request.function_app_directory,
93-
caller_info="worker_init_request"))
91+
result = asyncio.create_task(load_function_metadata(
92+
init_request.function_app_directory,
93+
caller_info="worker_init_request"))
9494
if get_app_setting(setting=PYTHON_ENABLE_INIT_INDEXING):
9595
capabilities[HTTP_URI] = \
9696
initialize_http_server(_host)
@@ -130,11 +130,10 @@ async def functions_metadata_request(request):
130130

131131
else:
132132
return protos.FunctionMetadataResponse(
133-
use_default_metadata_indexing=False,
134-
function_metadata_results=metadata_result,
135-
result=protos.StatusResult(
136-
status=protos.StatusResult.Success))
137-
133+
use_default_metadata_indexing=False,
134+
function_metadata_results=metadata_result,
135+
result=protos.StatusResult(
136+
status=protos.StatusResult.Success))
138137

139138

140139
async def functions_load_request(request):
@@ -152,7 +151,6 @@ async def functions_load_request(request):
152151
async def invocation_request(request):
153152
logger.info("Library Worker: received worker_invocation_request")
154153
global protos
155-
invocation_time = datetime.now()
156154
invoc_request = request.request.invocation_request
157155
invocation_id = invoc_request.invocation_id
158156
function_id = invoc_request.function_id
@@ -256,22 +254,22 @@ async def invocation_request(request):
256254
# Actively flush customer print() function to console
257255
sys.stdout.flush()
258256
return protos.InvocationResponse(
259-
invocation_id=invocation_id,
260-
return_value=return_value,
261-
result=protos.StatusResult(
262-
status=protos.StatusResult.Success),
263-
output_data=output_data)
257+
invocation_id=invocation_id,
258+
return_value=return_value,
259+
result=protos.StatusResult(
260+
status=protos.StatusResult.Success),
261+
output_data=output_data)
264262

265263
except Exception as ex:
266264
if http_v2_enabled:
267265
http_coordinator.set_http_response(invocation_id, ex)
268266
global metadata_result
269267
metadata_result = ex
270268
return protos.InvocationResponse(
271-
invocation_id=invocation_id,
272-
result=protos.StatusResult(
273-
status=protos.StatusResult.Failure,
274-
exception=serialize_exception(ex)))
269+
invocation_id=invocation_id,
270+
result=protos.StatusResult(
271+
status=protos.StatusResult.Failure,
272+
exception=serialize_exception(ex)))
275273

276274

277275
async def function_environment_reload_request(request):
@@ -308,9 +306,10 @@ async def function_environment_reload_request(request):
308306
global _host, result, protos
309307
_host = request.properties.get("host")
310308
protos = request.properties.get("protos")
311-
result = asyncio.create_task(load_function_metadata(directory,
312-
caller_info="environment_reload_request"))
313-
if get_app_setting(setting=PYTHON_ENABLE_INIT_INDEXING): # PYTHON_ENABLE_HTTP_STREAMING
309+
result = asyncio.create_task(load_function_metadata(
310+
directory,
311+
caller_info="environment_reload_request"))
312+
if get_app_setting(setting=PYTHON_ENABLE_INIT_INDEXING):
314313
capabilities[HTTP_URI] = \
315314
initialize_http_server(_host)
316315
capabilities[REQUIRES_ROUTE_PARAMETERS] = TRUE
@@ -324,18 +323,18 @@ async def function_environment_reload_request(request):
324323
func_env_reload_request.function_app_directory)
325324

326325
return protos.FunctionEnvironmentReloadResponse(
327-
capabilities=capabilities,
328-
worker_metadata=get_worker_metadata(protos),
329-
result=protos.StatusResult(
330-
status=protos.StatusResult.Success))
326+
capabilities=capabilities,
327+
worker_metadata=get_worker_metadata(protos),
328+
result=protos.StatusResult(
329+
status=protos.StatusResult.Success))
331330

332331
except Exception as ex:
333332
global metadata_exception
334333
metadata_exception = ex
335334
return protos.FunctionEnvironmentReloadResponse(
336-
result=protos.StatusResult(
337-
status=protos.StatusResult.Failure,
338-
exception=serialize_exception(ex)))
335+
result=protos.StatusResult(
336+
status=protos.StatusResult.Failure,
337+
exception=serialize_exception(ex)))
339338

340339

341340
async def load_function_metadata(function_app_directory, caller_info):

azure_functions_worker/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import time
1010

1111
from datetime import timedelta
12-
from typing import Dict, Optional, Union
12+
from typing import Dict, Optional
1313

1414

1515
from .functions import Registry
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
2-
# Licensed under the MIT License.
2+
# Licensed under the MIT License.

azure_functions_worker/utils/current.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@ def run_sync_func(invocation_id, context, func, params):
2828
return result(params)
2929
finally:
3030
context.thread_local_storage.invocation_id = None
31-

azure_functions_worker/utils/env_state.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33
import os
4-
import sys
54
from typing import Callable, Optional
65

76

azure_functions_worker/utils/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def get_worker_metadata(protos):
2626
f"{sys.version_info.minor}",
2727
worker_version=VERSION,
2828
worker_bitness=platform.machine(),
29-
custom_properties={})
29+
custom_properties={})

azure_functions_worker/utils/tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ def serialize_exception(exc: Exception, protos):
5353
except Exception:
5454
stack_trace = ''
5555

56-
return protos.RpcException(message=message, stack_trace=stack_trace)
56+
return protos.RpcException(message=message, stack_trace=stack_trace)

azure_functions_worker/utils/validators.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
import re
55

6-
from .constants import PYTHON_THREADPOOL_THREAD_COUNT, PYTHON_THREADPOOL_THREAD_COUNT_MIN
7-
86

97
class InvalidFileNameError(Exception):
108

eng/ci/public-build.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ resources:
2828

2929
variables:
3030
- template: /eng/templates/utils/variables.yml@self
31-
- name: codeql.excludePathPatterns
32-
value: deps/,build/
33-
- name: codeql.compiled.enabled
34-
value: true
35-
- name: codeql.runSourceLanguagesInSourceAnalysis
36-
value: true
37-
- name: codeql.sourceLanguages
38-
value: python, powershell
3931

4032
extends:
4133
template: v1/1ES.Unofficial.PipelineTemplate.yml@1es
@@ -44,19 +36,23 @@ extends:
4436
name: 1es-pool-azfunc-public
4537
image: 1es-windows-2022
4638
os: windows
39+
40+
sdl:
41+
codeql:
42+
compiled:
43+
enabled: true # still only runs for default branch
44+
sourceLanguages: python, powershell
45+
excludePathPatterns: deps/,build/
46+
runSourceLanguagesInSourceAnalysis: true
47+
4748
settings:
4849
skipBuildTagsForGitHubPullRequests: ${{ variables['System.PullRequest.IsFork'] }}
50+
4951
stages:
5052
- stage: Build
5153
jobs:
5254
- template: /eng/templates/jobs/build.yml@self
5355
- stage: RunUnitTests
5456
dependsOn: Build
5557
jobs:
56-
- template: /eng/templates/jobs/ci-unit-tests.yml@self
57-
- stage: RunEmulatorTests
58-
dependsOn: Build
59-
jobs:
60-
- template: /eng/templates/jobs/ci-emulator-tests.yml@self
61-
parameters:
62-
PoolName: 1es-pool-azfunc-public
58+
- template: /eng/templates/jobs/ci-unit-tests.yml@self

eng/templates/jobs/build.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@ jobs:
77
image: 1es-ubuntu-22.04
88
os: linux
99

10+
variables:
11+
# Extract the version number from the branch name
12+
pythonVersion: $[substring(variables['Build.SourceBranchName'], 4, 2)] # Extract last two digits from dev-xxx
13+
1014
steps:
15+
- script: |
16+
echo "Branch name: $(Build.SourceBranchName)"
17+
# Extract the last two digits (minor version) from the branch name
18+
version=$(echo $(Build.SourceBranchName) | sed 's/dev-\([0-9]*\)/\1/')
19+
minor_version=${version: -2} # Get last two digits
20+
echo "Extracted minor version: $minor_version"
21+
echo "##vso[task.setvariable variable=pythonVersion]$minor_version"
22+
displayName: 'Extract Python version from branch name'
1123
- task: UsePythonVersion@0
1224
inputs:
13-
versionSpec: "3.13"
25+
versionSpec: '3.$(pythonVersion)'
1426
- bash: |
1527
python --version
1628
displayName: 'Check python version'
1729
- bash: |
1830
python -m pip install --upgrade pip
19-
python -m pip install .
31+
python -m pip install build
32+
python -m build
2033
displayName: 'Build python worker'
2134
- bash: |
2235
pip install pip-audit
File renamed without changes.

0 commit comments

Comments
 (0)