Skip to content

Commit

Permalink
Added ci pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
muzammil360 authored Nov 7, 2023
2 parents 65814b5 + a1e4b48 commit ed0d302
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/api-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Python application

on:
pull_request:
branches:
- main

env:
PYTHON_VERSION: 3.8
WORKING_DIR: ./api

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ${{ env.WORKING_DIR }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
pip install flake8 black
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Format with black
run: |
# check if the code format is in compliance with black
black . --check
- name: Test with pytest
run: |
pytest
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pytest
- pytest # test framework
- pytest-asyncio # for async functions

## dev dependencies
- flake8 # code linting
- black # code formatting

## useful commands
```
pip freeze > requirements.txt
Expand Down
13 changes: 7 additions & 6 deletions api/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# WARNING: following code is needed to workaround a bug which comes while running unit tests
# https://stackoverflow.com/questions/60359157/valueerror-set-wakeup-fd-only-works-in-main-thread-on-windows-on-python-3-8-wit
# https://stackoverflow.com/questions/60359157/valueerror-set-wakeup-fd-only-works-in-main-thread-on-windows-on-python-3-8-wit
import sys, asyncio

if sys.platform == "win32" and (3, 8, 0) <= sys.version_info < (3, 9, 0):
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# ====================
Expand All @@ -17,26 +18,26 @@
def read_root():
return {"msg": "Hello World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}


@app.get("/ping")
def get_ping():
return {"msg": "Pong"}
return {"msg": "Pong"}


# =========== v1 api =============


class Detections(BaseModel):
person: float
car: float
dog: float


@app.post("/v1/detections")
def post_detections() -> Detections:
return Detections(person=0.1,car=0.2,dog=0.3)



return Detections(person=0.1, car=0.2, dog=0.3)
4 changes: 2 additions & 2 deletions api/test_detections.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from fastapi.testclient import TestClient

from .server import app
from .server import app

client = TestClient(app)


def test_read_root():
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"msg": "Hello World"}
assert response.json() == {"msg": "Hello World"}

0 comments on commit ed0d302

Please sign in to comment.