Skip to content

Commit

Permalink
setup testing CI (#62)
Browse files Browse the repository at this point in the history
* add test coverage

* remove unnecessary actions

* add flit

* refactor

* add python-multipart
  • Loading branch information
aniketmaurya committed Jun 23, 2021
1 parent 9079d9e commit de8c0af
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 84 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
@@ -0,0 +1,51 @@
name: Python Main CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
pytest:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
env:
OS: ${{ matrix.os }}
PYTHON: '3.7'

steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7

- name: Installation
run: |
python --version
pip --version
pip install flit
pip install .
pip install -r requirements/dev.txt
pip list
shell: bash

- name: Generate coverage report
run: |
pip install -r requirements/test.txt
coverage erase
coverage run -m pytest
coverage report -m
coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: false
6 changes: 6 additions & 0 deletions Makefile
Expand Up @@ -11,6 +11,12 @@ docs_serve:
test:
pytest

coverage: ## Run tests with coverage
coverage erase
coverage run -m pytest
coverage report -m
coverage xml

clean:
rm -rf dist
find . -type f -name "*.DS_Store" -ls -delete
Expand Down
7 changes: 1 addition & 6 deletions README.md
@@ -1,11 +1,6 @@
# chitra

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=alert_status)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=ncloc)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=security_rating)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![CodeFactor](https://www.codefactor.io/repository/github/aniketmaurya/chitra/badge)](https://www.codefactor.io/repository/github/aniketmaurya/chitra)
![GitHub issues](https://img.shields.io/github/issues/aniketmaurya/chitra?style=flat)
[![Documentation Status](https://readthedocs.org/projects/chitra/badge/?version=latest)](https://chitra.readthedocs.io/en/latest/?badge=latest)
[![Discord](https://img.shields.io/discord/848469007443165184?style=flat)](https://discord.gg/TdnAfDw3kB)
Expand Down
63 changes: 0 additions & 63 deletions chitra/_nbdev.py

This file was deleted.

2 changes: 0 additions & 2 deletions chitra/dataloader.py
Expand Up @@ -13,11 +13,9 @@
from .core import remove_dsstore
from .tf_image import read_image, resize_image

# Cell
AUTOTUNE = tf.data.experimental.AUTOTUNE


# Cell
def get_basename(path: tf.string):
assert isinstance(path, tf.Tensor)
return tf.strings.split(path, os.path.sep)[-1]
Expand Down
2 changes: 1 addition & 1 deletion chitra/image.py
Expand Up @@ -24,7 +24,7 @@
# Cell
from typing import Any, List, Optional, Union

DATA_FORMATS = Union[str, Image.Image, np.ndarray, tf.Tensor, torch.Tensor]
DATA_FORMATS = Union[str, Image.Image, np.ndarray, 'tf.Tensor', 'torch.Tensor']
DEFAULT_MODE = os.environ.get("CHITRA_DEFAULT_MODE", "TF")

from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage
Expand Down
2 changes: 0 additions & 2 deletions chitra/tf_image.py
Expand Up @@ -2,13 +2,11 @@

__all__ = ['read_image', 'resize_image']

# Cell
from typing import Union

import tensorflow as tf


# Cell
def read_image(path: str, channels: int = 3):
"""Reads an image file from the path and return the rgb image in tf.Tensor format."""
img: tf.Tensor = tf.io.read_file(path)
Expand Down
1 change: 0 additions & 1 deletion chitra/trainer.py
Expand Up @@ -36,7 +36,6 @@
OPT_DICT[name.lower()] = func


# Cell
@typechecked
def _get_base_cnn(
base_model: Union[str, Model],
Expand Down
10 changes: 4 additions & 6 deletions docs/index.md
@@ -1,11 +1,6 @@
# chitra

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=alert_status)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=ncloc)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=security_rating)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)
[![CodeFactor](https://www.codefactor.io/repository/github/aniketmaurya/chitra/badge)](https://www.codefactor.io/repository/github/aniketmaurya/chitra)
![GitHub issues](https://img.shields.io/github/issues/aniketmaurya/chitra?style=flat)
[![Documentation Status](https://readthedocs.org/projects/chitra/badge/?version=latest)](https://chitra.readthedocs.io/en/latest/?badge=latest)
[![Discord](https://img.shields.io/discord/848469007443165184?style=flat)](https://discord.gg/TdnAfDw3kB)
Expand Down Expand Up @@ -330,9 +325,12 @@ from chitra.trainer import create_cnn
model = create_cnn('mobilenetv2', num_classes=2)
create_api(model, run=True, api_type='image-classification')
```
<details><summary>API Docs Preview</summary>

![Preview Model Server](https://raw.githubusercontent.com/aniketmaurya/chitra/master/docs/examples/model-server/preview.png)

</details>

See [Example Section](https://chitra.readthedocs.io/en/latest/examples/model-server/model-server.html) for detailed explanation!


Expand Down
3 changes: 3 additions & 0 deletions requirements/dev.txt
@@ -0,0 +1,3 @@
-r serve.txt
-r tf.txt
-r torch.txt
1 change: 1 addition & 0 deletions requirements/serve.txt
@@ -1,3 +1,4 @@
fastapi
uvicorn
pydantic
python-multipart
2 changes: 2 additions & 0 deletions requirements/test.txt
@@ -0,0 +1,2 @@
pytest
coverage
1 change: 0 additions & 1 deletion requirements/tf.txt
@@ -1,2 +1 @@
tensorflow-serving-api
grpc
2 changes: 2 additions & 0 deletions requirements/torch.txt
@@ -0,0 +1,2 @@
torch
torchvision
4 changes: 2 additions & 2 deletions tests/test_model_server.py
@@ -1,9 +1,9 @@
from fastapi import FastAPI

from chitra.serve import create_app
from chitra.serve import create_api


def test_create_app():
model = lambda x: x + 1
app = create_app(model)
app = create_api(model)
assert isinstance(app, FastAPI)

1 comment on commit de8c0af

@codefactor-io
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeFactor found an issue: Duplicate Code

It's currently on:
chitra\dataloader.py:25-37
chitra\dataloader.py:69-81
Commit de8c0af

Please sign in to comment.