Skip to content

Commit 8ef845c

Browse files
authored
Minor code smell refactoring, updating pipelines and description added. (#64)
1 parent 8cab4c1 commit 8ef845c

38 files changed

+113
-98
lines changed

azure-pipelines.yml

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
11
trigger:
2-
- master
3-
- dev
2+
- master
3+
- dev
4+
5+
schedules:
6+
- cron: "0 8 * * 1,3,5"
7+
displayName: Monday, Wednesday and Friday - 1 AM (PDT) build
8+
branches:
9+
include:
10+
- dev
11+
- master
12+
exclude:
13+
- release/*
14+
- releases/ancient/*
415

516
jobs:
6-
- job: Tests
7-
pool:
8-
vmImage: 'ubuntu-16.04'
9-
strategy:
10-
matrix:
11-
Python36:
12-
pythonVersion: '3.6'
13-
Python37:
14-
pythonVersion: '3.7'
15-
Python38:
16-
pythonVersion: '3.8'
17-
maxParallel: 3
18-
steps:
19-
- task: UsePythonVersion@0
20-
inputs:
21-
versionSpec: '$(pythonVersion)'
22-
addToPath: true
23-
- task: ShellScript@2
24-
inputs:
25-
disableAutoCwd: true
26-
scriptPath: .ci/build.sh
27-
displayName: 'Build'
28-
- bash: |
29-
chmod +x .ci/run_tests.sh
30-
.ci/run_tests.sh
31-
displayName: 'Run Tests'
32-
- task: PublishCodeCoverageResults@1
33-
inputs:
34-
codeCoverageTool: cobertura
35-
summaryFileLocation: coverage.xml
36-
- bash: |
37-
rm coverage.xml
38-
displayName: 'Clearing coverage.xml file'
17+
- job: Tests
18+
pool:
19+
vmImage: 'ubuntu-16.04'
20+
strategy:
21+
matrix:
22+
Python36:
23+
pythonVersion: '3.6'
24+
Python37:
25+
pythonVersion: '3.7'
26+
Python38:
27+
pythonVersion: '3.8'
28+
maxParallel: 3
29+
steps:
30+
- task: UsePythonVersion@0
31+
inputs:
32+
versionSpec: '$(pythonVersion)'
33+
addToPath: true
34+
- task: ShellScript@2
35+
inputs:
36+
disableAutoCwd: true
37+
scriptPath: .ci/build.sh
38+
displayName: 'Build'
39+
- bash: |
40+
chmod +x .ci/run_tests.sh
41+
.ci/run_tests.sh
42+
displayName: 'Run Tests'
43+
- task: PublishCodeCoverageResults@1
44+
inputs:
45+
codeCoverageTool: cobertura
46+
summaryFileLocation: coverage.xml
47+
- bash: |
48+
rm coverage.xml
49+
displayName: 'Clearing coverage.xml file'

azure/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
from pkgutil import extend_path
45
import typing
6+
57
__path__: typing.Iterable[str] = extend_path(__path__, __name__)

azure/functions/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
from ._abc import TimerRequest, InputStream, Context, Out # NoQA
45
from ._eventhub import EventHubEvent # NoQA
56
from ._eventgrid import EventGridEvent, EventGridOutputEvent # NoQA
@@ -12,6 +13,7 @@
1213
from ._servicebus import ServiceBusMessage # NoQA
1314
from ._durable_functions import OrchestrationContext # NoQA
1415
from .meta import get_binding_registry # NoQA
16+
1517
# Import binding implementations to register them
1618
from . import blob # NoQA
1719
from . import cosmosdb # NoQA

azure/functions/_abc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import abc
45
import datetime
56
import io

azure/functions/_cosmosdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import collections
45
import json
56

azure/functions/_durable_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
from typing import Union
45
from . import _abc
56
from importlib import import_module
@@ -35,12 +36,11 @@ def _serialize_custom_object(obj):
3536
"function")
3637
# Encode to json using the object's `to_json`
3738
obj_type = type(obj)
38-
dict_obj = {
39+
return {
3940
"__class__": obj.__class__.__name__,
4041
"__module__": obj.__module__,
4142
"__data__": obj_type.to_json(obj)
4243
}
43-
return dict_obj
4444

4545

4646
def _deserialize_custom_object(obj: dict) -> object:

azure/functions/_eventgrid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import datetime
45
import typing
56

azure/functions/_eventhub.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import datetime
45
import typing
56

6-
from azure.functions import _abc as funcabc
7+
from azure.functions import _abc as func_abc
78
from azure.functions import meta
89

910

10-
class EventHubEvent(funcabc.EventHubEvent):
11+
class EventHubEvent(func_abc.EventHubEvent):
1112
"""A concrete implementation of Event Hub message type."""
1213

1314
def __init__(self, *,

azure/functions/_http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import collections.abc
45
import io
56
import json

azure/functions/_http_wsgi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
from typing import Callable, Dict, List, Optional, Any
45
from io import BytesIO, StringIO
56
from os import linesep

azure/functions/_kafka.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import abc
45
import typing
56

azure/functions/_queue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import datetime
45
import json
56
import typing

azure/functions/_thirdparty/typing_inspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ def get_args(tp, evaluate=None):
301301
get_args(Callable[[], T][int], evaluate=True) == ([], int,)
302302
"""
303303
if NEW_TYPING:
304-
if evaluate is not None and not evaluate:
304+
if not (evaluate is None or evaluate):
305305
raise ValueError('evaluate can only be True in Python 3.7')
306306
if isinstance(tp, _GenericAlias):
307307
res = tp.__args__

azure/functions/_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
from typing import List, Tuple, Optional
45
from datetime import datetime
56

azure/functions/blob.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import io
45
from typing import Optional, Union, Any
56

@@ -96,10 +97,7 @@ def decode(cls, data: meta.Datum, *, trigger_metadata) -> Any:
9697
trigger_metadata, 'Properties', python_type=dict)
9798
if properties:
9899
length = properties.get('Length')
99-
if length:
100-
length = int(length)
101-
else:
102-
length = None
100+
length = int(length) if length else None
103101
else:
104102
length = None
105103

azure/functions/cosmosdb.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import collections.abc
45
import json
56
import typing
@@ -30,15 +31,12 @@ def decode(cls,
3031

3132
data_type = data.type
3233

33-
if data_type == 'string':
34+
if data_type in ['string', 'json']:
3435
body = data.value
3536

3637
elif data_type == 'bytes':
3738
body = data.value.decode('utf-8')
3839

39-
elif data_type == 'json':
40-
body = data.value
41-
4240
else:
4341
raise NotImplementedError(
4442
f'unsupported queue payload type: {data_type}')

azure/functions/durable_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import typing
45
import json
56

@@ -61,7 +62,7 @@ def decode(cls,
6162

6263
# Durable functions extension always returns a string of json
6364
# See durable functions library's call_activity_task docs
64-
if data_type == 'string' or data_type == 'json':
65+
if data_type in ['string', 'json']:
6566
try:
6667
callback = _durable_functions._deserialize_custom_object
6768
result = json.loads(data.value, object_hook=callback)

azure/functions/eventgrid.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import collections
45
import datetime
56
import json

azure/functions/eventhub.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import json
45
from typing import Dict, Any, List, Union, Optional, Mapping
56

@@ -33,12 +34,10 @@ def decode(
3334
) -> Union[_eventhub.EventHubEvent, List[_eventhub.EventHubEvent]]:
3435
data_type = data.type
3536

36-
if (data_type == 'string' or data_type == 'bytes'
37-
or data_type == 'json'):
37+
if data_type in ['string', 'bytes', 'json']:
3838
return cls.decode_single_event(data, trigger_metadata)
3939

40-
elif (data_type == 'collection_bytes'
41-
or data_type == 'collection_string'):
40+
elif data_type in ['collection_bytes', 'collection_string']:
4241
return cls.decode_multiple_events(data, trigger_metadata)
4342

4443
else:
@@ -48,15 +47,12 @@ def decode(
4847
@classmethod
4948
def decode_single_event(cls, data,
5049
trigger_metadata) -> _eventhub.EventHubEvent:
51-
if data.type == 'string':
50+
if data.type in ['string', 'json']:
5251
body = data.value.encode('utf-8')
5352

5453
elif data.type == 'bytes':
5554
body = data.value
5655

57-
elif data.type == 'json':
58-
body = data.value.encode('utf-8')
59-
6056
return _eventhub.EventHubEvent(body=body)
6157

6258
@classmethod
@@ -70,8 +66,8 @@ def decode_multiple_events(
7066
parsed_data = data.value.string
7167

7268
events = []
73-
for i in range(len(parsed_data)):
74-
event = _eventhub.EventHubEvent(body=parsed_data[i])
69+
for parsed_datum in parsed_data:
70+
event = _eventhub.EventHubEvent(body=parsed_datum)
7571
events.append(event)
7672

7773
return events
@@ -119,15 +115,12 @@ def decode(
119115
def decode_single_event(
120116
cls, data, trigger_metadata: Mapping[str, meta.Datum]
121117
) -> _eventhub.EventHubEvent:
122-
if data.type == 'string':
118+
if data.type in ['string', 'json']:
123119
body = data.value.encode('utf-8')
124120

125121
elif data.type == 'bytes':
126122
body = data.value
127123

128-
elif data.type == 'json':
129-
body = data.value.encode('utf-8')
130-
131124
return _eventhub.EventHubEvent(
132125
body=body,
133126
trigger_metadata=trigger_metadata,

azure/functions/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
3+
34
import json
45
import typing
56

0 commit comments

Comments
 (0)