Skip to content

Commit

Permalink
Minor code smell refactoring, updating pipelines and description adde…
Browse files Browse the repository at this point in the history
…d. (#64)
  • Loading branch information
vrdmr authored Jul 1, 2020
1 parent 8cab4c1 commit 8ef845c
Show file tree
Hide file tree
Showing 38 changed files with 113 additions and 98 deletions.
81 changes: 46 additions & 35 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
trigger:
- master
- dev
- master
- dev

schedules:
- cron: "0 8 * * 1,3,5"
displayName: Monday, Wednesday and Friday - 1 AM (PDT) build
branches:
include:
- dev
- master
exclude:
- release/*
- releases/ancient/*

jobs:
- job: Tests
pool:
vmImage: 'ubuntu-16.04'
strategy:
matrix:
Python36:
pythonVersion: '3.6'
Python37:
pythonVersion: '3.7'
Python38:
pythonVersion: '3.8'
maxParallel: 3
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
addToPath: true
- task: ShellScript@2
inputs:
disableAutoCwd: true
scriptPath: .ci/build.sh
displayName: 'Build'
- bash: |
chmod +x .ci/run_tests.sh
.ci/run_tests.sh
displayName: 'Run Tests'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: cobertura
summaryFileLocation: coverage.xml
- bash: |
rm coverage.xml
displayName: 'Clearing coverage.xml file'
- job: Tests
pool:
vmImage: 'ubuntu-16.04'
strategy:
matrix:
Python36:
pythonVersion: '3.6'
Python37:
pythonVersion: '3.7'
Python38:
pythonVersion: '3.8'
maxParallel: 3
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(pythonVersion)'
addToPath: true
- task: ShellScript@2
inputs:
disableAutoCwd: true
scriptPath: .ci/build.sh
displayName: 'Build'
- bash: |
chmod +x .ci/run_tests.sh
.ci/run_tests.sh
displayName: 'Run Tests'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: cobertura
summaryFileLocation: coverage.xml
- bash: |
rm coverage.xml
displayName: 'Clearing coverage.xml file'
2 changes: 2 additions & 0 deletions azure/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from pkgutil import extend_path
import typing

__path__: typing.Iterable[str] = extend_path(__path__, __name__)
2 changes: 2 additions & 0 deletions azure/functions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from ._abc import TimerRequest, InputStream, Context, Out # NoQA
from ._eventhub import EventHubEvent # NoQA
from ._eventgrid import EventGridEvent, EventGridOutputEvent # NoQA
Expand All @@ -12,6 +13,7 @@
from ._servicebus import ServiceBusMessage # NoQA
from ._durable_functions import OrchestrationContext # NoQA
from .meta import get_binding_registry # NoQA

# Import binding implementations to register them
from . import blob # NoQA
from . import cosmosdb # NoQA
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_abc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import abc
import datetime
import io
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_cosmosdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import collections
import json

Expand Down
4 changes: 2 additions & 2 deletions azure/functions/_durable_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import Union
from . import _abc
from importlib import import_module
Expand Down Expand Up @@ -35,12 +36,11 @@ def _serialize_custom_object(obj):
"function")
# Encode to json using the object's `to_json`
obj_type = type(obj)
dict_obj = {
return {
"__class__": obj.__class__.__name__,
"__module__": obj.__module__,
"__data__": obj_type.to_json(obj)
}
return dict_obj


def _deserialize_custom_object(obj: dict) -> object:
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_eventgrid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import datetime
import typing

Expand Down
5 changes: 3 additions & 2 deletions azure/functions/_eventhub.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import datetime
import typing

from azure.functions import _abc as funcabc
from azure.functions import _abc as func_abc
from azure.functions import meta


class EventHubEvent(funcabc.EventHubEvent):
class EventHubEvent(func_abc.EventHubEvent):
"""A concrete implementation of Event Hub message type."""

def __init__(self, *,
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import collections.abc
import io
import json
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_http_wsgi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import Callable, Dict, List, Optional, Any
from io import BytesIO, StringIO
from os import linesep
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_kafka.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import abc
import typing

Expand Down
1 change: 1 addition & 0 deletions azure/functions/_queue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import datetime
import json
import typing
Expand Down
2 changes: 1 addition & 1 deletion azure/functions/_thirdparty/typing_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_args(tp, evaluate=None):
get_args(Callable[[], T][int], evaluate=True) == ([], int,)
"""
if NEW_TYPING:
if evaluate is not None and not evaluate:
if not (evaluate is None or evaluate):
raise ValueError('evaluate can only be True in Python 3.7')
if isinstance(tp, _GenericAlias):
res = tp.__args__
Expand Down
1 change: 1 addition & 0 deletions azure/functions/_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from typing import List, Tuple, Optional
from datetime import datetime

Expand Down
6 changes: 2 additions & 4 deletions azure/functions/blob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import io
from typing import Optional, Union, Any

Expand Down Expand Up @@ -96,10 +97,7 @@ def decode(cls, data: meta.Datum, *, trigger_metadata) -> Any:
trigger_metadata, 'Properties', python_type=dict)
if properties:
length = properties.get('Length')
if length:
length = int(length)
else:
length = None
length = int(length) if length else None
else:
length = None

Expand Down
6 changes: 2 additions & 4 deletions azure/functions/cosmosdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import collections.abc
import json
import typing
Expand Down Expand Up @@ -30,15 +31,12 @@ def decode(cls,

data_type = data.type

if data_type == 'string':
if data_type in ['string', 'json']:
body = data.value

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

elif data_type == 'json':
body = data.value

else:
raise NotImplementedError(
f'unsupported queue payload type: {data_type}')
Expand Down
3 changes: 2 additions & 1 deletion azure/functions/durable_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import typing
import json

Expand Down Expand Up @@ -61,7 +62,7 @@ def decode(cls,

# Durable functions extension always returns a string of json
# See durable functions library's call_activity_task docs
if data_type == 'string' or data_type == 'json':
if data_type in ['string', 'json']:
try:
callback = _durable_functions._deserialize_custom_object
result = json.loads(data.value, object_hook=callback)
Expand Down
1 change: 1 addition & 0 deletions azure/functions/eventgrid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import collections
import datetime
import json
Expand Down
21 changes: 7 additions & 14 deletions azure/functions/eventhub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
from typing import Dict, Any, List, Union, Optional, Mapping

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

if (data_type == 'string' or data_type == 'bytes'
or data_type == 'json'):
if data_type in ['string', 'bytes', 'json']:
return cls.decode_single_event(data, trigger_metadata)

elif (data_type == 'collection_bytes'
or data_type == 'collection_string'):
elif data_type in ['collection_bytes', 'collection_string']:
return cls.decode_multiple_events(data, trigger_metadata)

else:
Expand All @@ -48,15 +47,12 @@ def decode(
@classmethod
def decode_single_event(cls, data,
trigger_metadata) -> _eventhub.EventHubEvent:
if data.type == 'string':
if data.type in ['string', 'json']:
body = data.value.encode('utf-8')

elif data.type == 'bytes':
body = data.value

elif data.type == 'json':
body = data.value.encode('utf-8')

return _eventhub.EventHubEvent(body=body)

@classmethod
Expand All @@ -70,8 +66,8 @@ def decode_multiple_events(
parsed_data = data.value.string

events = []
for i in range(len(parsed_data)):
event = _eventhub.EventHubEvent(body=parsed_data[i])
for parsed_datum in parsed_data:
event = _eventhub.EventHubEvent(body=parsed_datum)
events.append(event)

return events
Expand Down Expand Up @@ -119,15 +115,12 @@ def decode(
def decode_single_event(
cls, data, trigger_metadata: Mapping[str, meta.Datum]
) -> _eventhub.EventHubEvent:
if data.type == 'string':
if data.type in ['string', 'json']:
body = data.value.encode('utf-8')

elif data.type == 'bytes':
body = data.value

elif data.type == 'json':
body = data.value.encode('utf-8')

return _eventhub.EventHubEvent(
body=body,
trigger_metadata=trigger_metadata,
Expand Down
1 change: 1 addition & 0 deletions azure/functions/http.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import json
import typing

Expand Down
Loading

0 comments on commit 8ef845c

Please sign in to comment.