Skip to content

Commit

Permalink
ENH: modernize setup and add lume command manager to ease development… (
Browse files Browse the repository at this point in the history
#25)

* ENH: modernize setup and add lume command manager to ease development. Add also a new github workflow for ci
* ENH: use pydantic instead of dataclasses
* ENH: add CONCURRENT_TEST to do or not to do some assertions which depends on time and external server
  • Loading branch information
acostapazo authored Dec 29, 2021
1 parent cfad84f commit d35ff7c
Show file tree
Hide file tree
Showing 24 changed files with 203 additions and 103 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: ci

on:
pull_request:
paths-ignore:
- '*.md'
- 'alice/VERSION'
branches:
- master

env:
ONBOARDING_API_KEY: ${{ secrets.ONBOARDING_API_KEY }}
ONBOARDING_SANDBOX_TOKEN: ${{ secrets.ONBOARDING_SANDBOX_TOKEN }}
CONCURRENT_TESTING: True

jobs:
ci:
strategy:
max-parallel: 4
matrix:
os: [ macOS-latest, ubuntu-latest ]
python-version: [3.7, 3.8, 3.9]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('dev-requirements.txt') }}
- name: Install Requirements
run: |
pip install lume
lume -install
- name: Lint
run: lume -lint
- name: Check Requirements
run: lume -check-requirements
- name: Test [pytest]
run: lume -test
- name: Example [Onboarding]
run: python examples/onboarding.py
- name: Example [Onboarding with Identification]
run: python examples/onboarding_with_identification.py
- name: Example [Onboarding with Certificate]
run: python examples/onboarding_with_certificate.py
- name: Example [Onboarding with Screening]
run: python examples/onboarding_with_screening.py
- name: Example [Auth]
run: python examples/auth.py
- name: Example [Sandbox]
run: python examples/sandbox.py
47 changes: 13 additions & 34 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,55 +11,34 @@ env:
ONBOARDING_API_KEY: ${{ secrets.ONBOARDING_API_KEY }}
ONBOARDING_SANDBOX_TOKEN: ${{ secrets.ONBOARDING_SANDBOX_TOKEN }}
ALICE_GITHUB_ACCESS_TOKEN: ${{ secrets.ALICE_GITHUB_ACCESS_TOKEN }}
CONCURRENT_TESTING: True

jobs:
ci:
strategy:
max-parallel: 4
matrix:
os: [ macOS-latest, ubuntu-latest ]
python-version: [3.8]
python-version: [3.7, 3.8, 3.9]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v1
if: startsWith(runner.os, 'Linux')
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v1
if: startsWith(runner.os, 'macOS')
with:
path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/cache@v1
if: startsWith(runner.os, 'Windows')
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
pip install -r requirements/dev.txt
- name: Lint with black & flake8
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('dev-requirements.txt') }}
- name: Install Requirements
run: |
black .
flake8 alice
- name: Install package
run: |
pip install -e . # Dependencies are also included in the setup.py
pip install lume
lume -install
- name: Lint
run: lume -lint
- name: Test [pytest]
run: |
pytest --tb=no
run: lume -test
- name: Example [Onboarding]
run: python examples/onboarding.py
- name: Example [Onboarding with Identification]
Expand Down Expand Up @@ -96,7 +75,7 @@ jobs:
- name: Git - Commit VERSION File
run: |
git config --global user.email "[email protected]"
git config --global user.name "ALiCE Biometrics"
git config --global user.name "Alice Biometrics"
git commit -m "Update version to ${RELEASE_VERSION}"
- name: Push changes
uses: alice-biometrics/github-push-action@master
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

The aim of this Python package is to manage the authentication and backend operations against ALiCE Onboarding API.

If you want more information about how to integrate with ALiCE technology, please contact us at [email protected].
If you want more information about how to integrate with Alice technology, please contact us at [email protected].

## Table of Contents
- [Requirements](#requirements)
Expand Down
2 changes: 1 addition & 1 deletion alice/auth/auth_errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from typing import Dict

from dataclasses import dataclass
from meiga import Error
from requests import Response

Expand Down
5 changes: 3 additions & 2 deletions alice/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dataclasses import dataclass
from meiga import Error
from pydantic.dataclasses import dataclass


@dataclass
class Config:
class Config(Error):
onboarding_url: str = "https://apis.alicebiometrics.com/onboarding"
sandbox_url: str = "https://apis.alicebiometrics.com/onboarding/sandbox"
api_key: str = None
Expand Down
7 changes: 2 additions & 5 deletions alice/onboarding/device_info.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from typing import Optional

from dataclasses import dataclass
from dataclasses_json import dataclass_json
from pydantic import BaseModel


@dataclass_json
@dataclass
class DeviceInfo:
class DeviceInfo(BaseModel):
device_platform: Optional[str] = None
device_platform_version: Optional[str] = None
device_model: Optional[str] = None
1 change: 0 additions & 1 deletion alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,6 @@ def screening_monitor_open_alerts(
response = self.onboarding_client.screening_monitor_open_alerts(
start_index=start_index, size=size, verbose=verbose
)

if response.status_code == 200:
return Success(response.json())
else:
Expand Down
4 changes: 2 additions & 2 deletions alice/onboarding/onboarding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def create_user(
data = None
if user_info:
data = data if data is not None else {}
data.update(json.loads(user_info.to_json()))
data.update(user_info.dict())
if device_info:
data = data if data is not None else {}
data.update(json.loads(device_info.to_json()))
data.update(device_info.dict())

response = requests.post(f"{self.url}/user", headers=headers, data=data)

Expand Down
6 changes: 3 additions & 3 deletions alice/onboarding/onboarding_errors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import Dict
from typing import Any, Dict, Optional

from dataclasses import dataclass
from meiga import Error
from pydantic.dataclasses import dataclass
from requests import Response


@dataclass
class OnboardingError(Error):
operation: str
code: int
message: Dict[str, str]
message: Optional[Dict[str, Any]] = None

def __str__(self):
return self.__repr__()
Expand Down
7 changes: 2 additions & 5 deletions alice/onboarding/user_info.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
from typing import Optional

from dataclasses import dataclass
from dataclasses_json import dataclass_json
from pydantic import BaseModel


@dataclass_json
@dataclass
class UserInfo:
class UserInfo(BaseModel):
first_name: Optional[str] = None
last_name: Optional[str] = None
email: Optional[str] = None
14 changes: 7 additions & 7 deletions alice/public_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8
# Copyright (C) 2019+ Alice, Vigo, Spain

"""Public API of ALiCE Onboarding Python SDK"""
"""Public API of Alice Onboarding Python SDK"""

# Modules
from alice.webhooks.webhook import Webhook
Expand All @@ -10,18 +10,18 @@

modules = []

from alice.auth.auth import Auth
from alice.auth.auth_client import AuthClient
from alice.config import Config
from alice.onboarding.decision import Decision
from alice.onboarding.device_info import DeviceInfo

# Classes
from alice.onboarding.onboarding import Onboarding
from alice.onboarding.onboarding_client import OnboardingClient
from alice.onboarding.user_info import UserInfo
from alice.onboarding.device_info import DeviceInfo
from alice.onboarding.decision import Decision
from alice.auth.auth import Auth
from alice.auth.auth_client import AuthClient
from alice.sandbox.sandbox import Sandbox
from alice.sandbox.sandbox_client import SandboxClient
from alice.config import Config


classes = [
"Onboarding",
Expand Down
14 changes: 5 additions & 9 deletions alice/sandbox/sandbox_client.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import json
from requests import Response, request

from requests import request, Response

from alice.onboarding.tools import timeit, print_intro, print_response

from alice.onboarding.user_info import UserInfo
from alice.onboarding.device_info import DeviceInfo

from alice.onboarding.tools import print_intro, print_response, timeit
from alice.onboarding.user_info import UserInfo

DEFAULT_URL = "https://apis.alicebiometrics.com/onboarding/sandbox"

Expand Down Expand Up @@ -76,10 +72,10 @@ def create_user(
data = None
if user_info:
data = data if data is not None else {}
data.update(json.loads(user_info.to_json()))
data.update(user_info.dict())
if device_info:
data = data if data is not None else {}
data.update(json.loads(device_info.to_json()))
data.update(device_info.dict())

response = request("POST", self.url + "/user", headers=headers, data=data)

Expand Down
6 changes: 3 additions & 3 deletions alice/sandbox/sandbox_errors.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from typing import Dict
from typing import Any, Dict, Optional

from dataclasses import dataclass
from meiga import Error
from pydantic.dataclasses import dataclass
from requests import Response


@dataclass
class SandboxError(Error):
operation: str
code: int
message: Dict[str, str]
message: Optional[Dict[str, Any]] = None

def __repr__(self):
return f"[SandboxError: [operation: {self.operation} | code: {self.code} | message: {self.message}]]"
Expand Down
6 changes: 3 additions & 3 deletions alice/webhooks/webhooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Dict, List

from meiga import Result, Success, Failure, isSuccess
from meiga import Failure, Result, Success, isSuccess

from alice.auth.auth import Auth
from alice.config import Config
from alice.onboarding.onboarding_errors import OnboardingError
from alice.auth.auth import Auth
from alice.webhooks.webhook import Webhook
from alice.webhooks.webhooks_client import WebhooksClient

Expand Down Expand Up @@ -63,7 +63,7 @@ def get_available_events(

def create_webhook(
self, webhook: Webhook, verbose: bool = False
) -> Result[Dict, OnboardingError]:
) -> Result[str, OnboardingError]:
"""
It creates a new Webhook in the onboarding service.
Expand Down
23 changes: 23 additions & 0 deletions lume.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: onboarding-python

install:
run:
- pip install --upgrade --upgrade-strategy eager -r requirements/dev-requirements.txt -r requirements/requirements.txt
- pip install -e .
steps:
clean:
run:
- rm -f .coverage
- rm -rf output
- rm -rf .pytest_cache
- find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf
lint:
run:
- black --check .
- flake8 alice
check-requirements:
run: safety check -r requirements/requirements.txt
static-analysis:
run: mypy --namespace-packages alice
test:
run: pytest
16 changes: 16 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Configuration of py.test
[pytest]
markers=unit
addopts=tests
-v
--color=yes
--durations=10
filterwarnings =
error
ignore::DeprecationWarning

python_files=test_*.py
python_classes=Test*
python_functions=test_* should_

norecursedirs = examples alice requirements *.egg-info .git resources
12 changes: 12 additions & 0 deletions requirements/dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
black==21.11b1
flake8==4.0.1
isort==5.6.4
pytest==5.0.1
pytest-cov==2.5.1
pytest-mock==1.7.1
pytest-env==0.6.2
pytest-variables[yaml]==1.9.0
pytest-clarity==1.0.1
pre-commit==2.15.0
mypy==0.910
safety==1.10.3
Loading

0 comments on commit d35ff7c

Please sign in to comment.