Skip to content

Commit

Permalink
Initial Project Setup (#1)
Browse files Browse the repository at this point in the history
* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Inital Project Setup

* Update setup.py

Co-authored-by: Jeff Yang <[email protected]>

Co-authored-by: Jeff Yang <[email protected]>
  • Loading branch information
DavianYang and Jeff Yang authored Dec 26, 2020
1 parent 82d64af commit 5c709d8
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 1 deletion.
48 changes: 48 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# https://docs.codecov.io/docs/codecovyml-reference
codecov:
bot: "codecov-io"
strict_yaml_branch: "yaml-config"
require_ci_to_pass: yes
notify:
after_n_builds: 16
wait_for_ci: yes
# https://docs.codecov.io/docs/codecov-yaml#section-expired-reports
max_report_age: off

coverage:
precision: 0 # 2 = xx.xx%, 0 = xx%
round: nearest # how coverage is rounded: down/up/nearest
range: 40...100 # custom range of coverage colors from red -> yellow -> green
status:
# https://codecov.readme.io/v1.0/docs/commit-status
project:
default:
against: auto
target: 96% # specify the target coverage for each commit status
threshold: 30% # allow this little decrease on project
# https://github.com/codecov/support/wiki/Filtering-Branches
# branches: master
if_ci_failed: error
# https://github.com/codecov/support/wiki/Patch-Status
patch:
default:
against: auto
target: 50% # specify the target "X%" coverage to hit
# threshold: 50% # allow this much decrease on patch
changes: false

parsers:
gcov:
branch_detection:
conditional: true
loop: true
macro: false
method: false
javascript:
enable_partials: false

comment:
layout: header, diff
require_changes: false
behavior: default # update if exists else create new
after_n_builds: 8
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length=88
27 changes: 27 additions & 0 deletions .github/workflows/ci_code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci_code_quality

on:
push:
branches: [main]
pull_request:

jobs:
code_quality:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.6

- run: pip install wheel pip setuptools -U
# - run: pip install ".[dev]" --progress-bar off -Uf https://download.pytorch.org/whl/cpu/torch_stable.html
- run: echo "CODEQL_PYTHON=$(which python)" >> $GITHUB_ENV

- uses: github/codeql-action/init@v1
with:
languages: python
setup-python-dependencies: false

- uses: github/codeql-action/analyze@v1
- run: bash ./scripts/run_code_quality.sh
41 changes: 41 additions & 0 deletions .github/workflows/ci_unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ci_unittest

on:
push:
branches: [main]
pull_request:
schedule:
- cron: "0 0 * * *"

jobs:
unittest:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
python_version: [3.6, 3.7, 3.8]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python_version }}

- run: echo "::set-output name=date::$(/bin/date "+%Y-%U")"
id: get-date

- run: echo "::set-output name=dir::$(pip cache dir)"
id: pip-cache

- uses: actions/cache@v2
with:
path: |
${{ steps.pip-cache.outputs.dir }}
key: ${{ steps.get-date.outputs.date }}-py${{ matrix.python_version }}
restore-keys: |
${{ steps.get-date.outputs.date }}-py${{ matrix.python_version }}
${{ steps.get-date.outputs.date }}-py
- run: pip install wheel pip setuptools -U
# - run: pip install ".[testing]" --progress-bar off -Uf https://download.pytorch.org/whl/cpu/torch_stable.html
# - run: bash ./scripts/run_tests.sh
env:
TORCH_UTILS_COLLECT_ENV: 1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -126,4 +127,4 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.pyre/
13 changes: 13 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"python.pythonPath": "~/miniconda3/envs/detection/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.flake8Enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackPath": "~/miniconda3/envs/detection/bin/black",
"python.linting.flake8Path": "~/miniconda3/envs/detection/bin/flake8",
"python.linting.pylintPath": "~/miniconda3/envs/detection/bin/pylint",
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "test_*.py"],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
}
Empty file added app/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions app/api/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from fastapi import APIRouter

from api.endpoints import detections

api_router = APIRouter()
api_router.include_router(detections.router, tags=["detections"])
Empty file added app/api/endpoints/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions app/api/endpoints/detections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import Any, List

from fastapi import APIRouter

router = APIRouter()

# http://0.0.0.0:8000/api/v1/
@router.get('/')
async def detect():
return {
"message": "Hello World"
}

Empty file added app/core/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions app/core/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import secrets
from typing import Any, Dict, List, Optional, Union

from pydantic import AnyHttpUrl, BaseSettings, HttpUrl

class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
SECRET_KEY: str = secrets.token_urlsafe(32)
# 60 minutes * 24 hours * 7 days = 7 days
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7
# SERVER_NAME: str
# SERVER_HOST: AnyHttpUrl
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []

PROJECT_NAME: str = "DL API"

class Config:
case_sensitive = True


settings = Settings()
Empty file added app/db/__init__.py
Empty file.
27 changes: 27 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import uvicorn

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from core.config import settings

from api.api import api_router

app = FastAPI(
title=settings.PROJECT_NAME, openapi_prefix=f"{settings.API_V1_STR}/openapi.json"
)

if settings.BACKEND_CORS_ORIGINS:
app.add_middleware(
CORSMiddleware,
allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)


app.include_router(api_router, prefix=settings.API_V1_STR)

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
Empty file added app/models/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# conda / mamba env update -f environment.yml

name: package

channels:
- pytorch
- conda-forge

dependencies:
- python=3.8
- cpuonly
- pip
- numpy
- pytorch
- ignite
- pytorch-lightning

- pip:
- fastapi
- uvicorn
- python-multipart
- prettytable
- coverage
- parameterized
27 changes: 27 additions & 0 deletions pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: end-of-file-fixer

- repo: https://github.com/pre-commit/mirrors-prettier
rev: ""
hooks:
- id: prettier

- repo: https://github.com/PyCQA/isort
rev: 5.5.3
hooks:
- id: isort

- repo: https://gitlab.com/PyCQA/flake8
rev: 3.8.3
hooks:
- id: flake8

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ------------
# black config
# ------------
[tool.black]
line-length = 88
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
(
/(
\.eggs # exclude a few common directories in the
| \.git # root of the project
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| assets
)/
| foo.py # also separately exclude a file named foo.py in
# the root of the project
)
'''

# ------------
# isort config
# ------------
[tool.isort]
profile="black"

# -------------
# pylint config
# -------------
[tool.pylint.reports]
output-format="colorized"
reports="yes"

[tool.pylint.typecheck]
generated-members="numpy.*,torch.*,cv2.*,np.*"

[tool.pylint.design]
max-args=6
11 changes: 11 additions & 0 deletions scripts/run_code_quality.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -xu

black . --check

flake8 . --config .flake8

isort . --color --check

pylint toydet
10 changes: 10 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#!/bin/bash

set -xu

if [[ "${TORCH_UTILS_COLLECT_ENV}" -eq 1 ]]; then
python -m torch.utils.collect_env
fi

# coverage run --source toydet -m unittest discover -bv -s ./tests/ -p "test_*.py" && coverage report
Loading

0 comments on commit 5c709d8

Please sign in to comment.