From 248776ddd5b15dcb9ce2b40b9b0e8df1df4a4160 Mon Sep 17 00:00:00 2001 From: muzammil360 Date: Tue, 7 Nov 2023 17:16:36 +0500 Subject: [PATCH 1/3] Added ci pipeline --- .github/workflows/api-ci.yml | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/api-ci.yml diff --git a/.github/workflows/api-ci.yml b/.github/workflows/api-ci.yml new file mode 100644 index 0000000..8a369cb --- /dev/null +++ b/.github/workflows/api-ci.yml @@ -0,0 +1,48 @@ +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: | + # python -m pip install --upgrade pip + pip install flake8 black + # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + 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 From b4463e19e7a2e5defc9f725d1683ee25f9c6c4b7 Mon Sep 17 00:00:00 2001 From: muzammil360 Date: Tue, 7 Nov 2023 17:19:48 +0500 Subject: [PATCH 2/3] formatting --- api/server.py | 13 +++++++------ api/test_detections.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/server.py b/api/server.py index 5b37fd5..ca35a0a 100644 --- a/api/server.py +++ b/api/server.py @@ -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()) # ==================== @@ -17,6 +18,7 @@ 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} @@ -24,19 +26,18 @@ def read_item(item_id: int, q: Union[str, None] = None): @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) diff --git a/api/test_detections.py b/api/test_detections.py index b1b6391..f2ec00c 100644 --- a/api/test_detections.py +++ b/api/test_detections.py @@ -1,6 +1,6 @@ from fastapi.testclient import TestClient -from .server import app +from .server import app client = TestClient(app) @@ -8,4 +8,4 @@ def test_read_root(): response = client.get("/") assert response.status_code == 200 - assert response.json() == {"msg": "Hello World"} \ No newline at end of file + assert response.json() == {"msg": "Hello World"} From a1e4b482ad9020f975ba6414ca9e26e8e0ac7aad Mon Sep 17 00:00:00 2001 From: muzammil360 Date: Tue, 7 Nov 2023 17:43:02 +0500 Subject: [PATCH 3/3] update ci file --- .github/workflows/api-ci.yml | 2 -- README.md | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/api-ci.yml b/.github/workflows/api-ci.yml index 8a369cb..267e5d0 100644 --- a/.github/workflows/api-ci.yml +++ b/.github/workflows/api-ci.yml @@ -26,9 +26,7 @@ jobs: - name: Install dependencies run: | - # python -m pip install --upgrade pip pip install flake8 black - # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi pip install -r requirements.txt - name: Lint with flake8 diff --git a/README.md b/README.md index cbd7663..b16be64 100644 --- a/README.md +++ b/README.md @@ -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