Skip to content

Commit

Permalink
CI tests using git workflows (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg authored Mar 8, 2020
1 parent d98373a commit 177309d
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 99 deletions.
16 changes: 16 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[flake8]

# Ignore line too long error
ignore = E501

exclude =
.git,
__pycache__,
build,
dist,

per-file-ignores =

# allow top level module exposing
__init__.py:F401
test/__init__.py:F401
31 changes: 31 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make install_pipenv PIPENV_PYTHON_VERSION=${{ matrix.python-version }}
- name: Lint
run: make lint
- name: Test
run: make test
36 changes: 30 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
PIPENV_PYTHON_VERSION ?= 3.6


.PHONY: all
all:
$(error please pick a target)

.PHONY: upload
upload: clean
python setup.py sdist bdist_wheel
pipenv run upload
upload: clean build lint test
python -m pipenv run upload

.PHONY: build
build:
python -m pipenv run build

.PHONE: clean
.PHONY: clean
clean:
rm -rf dist
rm -rf dist build nuclio_sdk.egg-info

.PHONY: clean_pyc
clean_pyc:
find . -name '*.pyc' -exec rm {} \;

.PHONY: flake8
flake8:
pipenv run flake8
python -m pipenv run flake8

.PHONY: test
test:
python -m pipenv run test

.PHONY: lint
lint:
python -m pipenv run lint

.PHONY: install_pipenv
install_pipenv:
python -m pip install --user pipenv
python -m pipenv --python ${PIPENV_PYTHON_VERSION}
ifeq ($(PIPENV_PYTHON_VERSION), 2.7)
python -m pipenv install -r requirements.py2.txt
else
python -m pipenv install --dev
endif
9 changes: 5 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ name = "pypi"

[packages]
nuclio-sdk = {editable = true,path = "."}
requests = "*"
twine = "*"
bleach = "==3.1.1"

[dev-packages]
flake8 = "*"
twine = "*"
bleach = "==3.1.1"

[requires]
python_version = "3.7"

[scripts]
build = "python setup.py sdist bdist_wheel"
test = "python -m unittest discover -s nuclio_sdk/test -p 'test_*.py' -v"
upload = "twine upload dist/*"
flake8 = "flake8 nuclio_sdk"
lint = "flake8 nuclio_sdk"
143 changes: 77 additions & 66 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions nuclio_sdk/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def to_json(self):
if isinstance(self.timestamp, datetime.datetime):
obj['timestamp'] = str(self.timestamp)

# TEMP: this should be done only on python3
if isinstance(obj['body'], bytes):
obj['body'] = base64.b64encode(obj['body']).decode('ascii')

return json.dumps(obj)

def get_header(self, header_key):
Expand Down Expand Up @@ -131,13 +135,13 @@ def decode_body(body, content_type):

try:
decoded_body = base64.b64decode(body)
except:
except: # noqa E722
return body

if content_type == 'application/json':
try:
return json.loads(decoded_body)
except:
except: # noqa E722
pass

return decoded_body
Expand Down
15 changes: 15 additions & 0 deletions nuclio_sdk/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2017 The Nuclio Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


class ExceptionWithResponse(IOError):

def __init__(self, status_code, body=None, content_type=None):
Expand Down
18 changes: 18 additions & 0 deletions nuclio_sdk/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2017 The Nuclio Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys

PYTHON3 = sys.version_info[0] == 3
PYTHON2 = sys.version_info[0] == 2
Loading

0 comments on commit 177309d

Please sign in to comment.