Skip to content

Commit ecc2fab

Browse files
committed
ci: check code style and run unittest
1 parent fd40494 commit ecc2fab

File tree

4 files changed

+127
-7
lines changed

4 files changed

+127
-7
lines changed

.github/workflows/ci.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: ci
5+
6+
on:
7+
push:
8+
branches: [ "main", "dev" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
services:
19+
redis:
20+
image: redis
21+
strategy:
22+
matrix:
23+
python-version: [3.9, "3.10", 3.11, 3.12, 3.13]
24+
steps:
25+
- uses: actions/checkout@v4
26+
- name: Setup Python
27+
id: setup-python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
allow-prereleases: true
32+
- uses: actions/cache@v4
33+
with:
34+
path: ~/.cache/pip
35+
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-pip-
38+
- name: Install and configure Poetry
39+
run: |
40+
pip install -U pip poetry
41+
poetry config virtualenvs.create false
42+
- name: Install dependencies
43+
run: poetry install -E mysql -E postgres
44+
- name: Check code style and Type Hint
45+
run: fast check
46+
- name: build
47+
run: poetry build
48+
- name: Test with pytest
49+
run: fast test
50+
- name: Upload Coverage
51+
run: |
52+
pip install --upgrade coveralls
53+
coveralls --service=github
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
COVERALLS_FLAG_NAME: ${{ matrix.python-version }}
57+
COVERALLS_PARALLEL: true
58+
59+
coveralls:
60+
name: Indicate completion to coveralls.io
61+
needs: test
62+
runs-on: ubuntu-latest
63+
container: python:3-slim
64+
steps:
65+
- name: Finished
66+
run: |
67+
pip3 install --upgrade coveralls
68+
coveralls --service=github --finish
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
Template for python backend project using FastAPI+TortoiseORM+poetry+aerich
77

8+
Inspired by [full-stack-fastapi-template](https://github.com/fastapi/full-stack-fastapi-template)
9+
10+
## Technology Stack and Features
11+
12+
-[**FastAPI**](https://fastapi.tiangolo.com) for the Python backend API.
13+
- 🧰 [TortoiseORM](https://tortoise.github.io) for the Python SQL database interactions (ORM).
14+
- 🔍 [Pydantic](https://docs.pydantic.dev), used by FastAPI, for the data validation and settings management.
15+
- ✅ Tests with [Pytest](https://pytest.org).
16+
817
## Quickstart
918

1019
```bash
@@ -15,3 +24,46 @@ poetry install
1524
aerich init-db
1625
python app.py
1726
```
27+
28+
## How To Use It
29+
30+
You can **just fork or clone** this repository and use it as is.
31+
32+
✨ It just works. ✨
33+
34+
### How to Use a Private Repository
35+
36+
If you want to have a private repository, GitHub won't allow you to simply fork it as it doesn't allow changing the visibility of forks.
37+
38+
But you can do the following:
39+
40+
- Create a new GitHub repo, for example `my-backend-project`.
41+
- Clone this repository manually, set the name with the name of the project you want to use, for example `my-backend-project`:
42+
43+
```bash
44+
git clone [email protected]:waketzheng/fastapi-tortoise-poetry-template.git my-backend-project
45+
```
46+
47+
- Enter into the new directory:
48+
49+
```bash
50+
cd my-backend-project
51+
```
52+
53+
- Set the new origin to your new repository, copy it from the GitHub interface, for example:
54+
55+
```bash
56+
git remote set-url origin [email protected]:octocat/my-backend-project.git
57+
```
58+
59+
- Add this repo as another "remote" to allow you to get updates later:
60+
61+
```bash
62+
git remote add upstream [email protected]:waketzheng/fastapi-tortoise-poetry-template.git
63+
```
64+
65+
- Push the code to your new repository:
66+
67+
```bash
68+
git push -u origin master
69+
```

app.py

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async def lifespan(application) -> AsyncGenerator:
2525
app = FastAPI(lifespan=lifespan)
2626
app.include_router(users_router, prefix="/users", tags=["users"])
2727
if os.getenv("FAST_CDN"):
28+
# Use faster CDN host for docs page assets instead of 'cdn.jsdelivr.net'
2829
import fastapi_cdn_host
2930

3031
fastapi_cdn_host.patch_docs(app)

tests/conftest.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@
1010
try:
1111
from app import app
1212
except ImportError:
13-
if (cwd := Path.cwd()) == (root := Path(__file__).parent.parent):
14-
dirpath = "."
15-
else:
16-
dirpath = str(root.relative_to(cwd))
17-
print(
18-
f"You may need to explicitly declare python path:\n\nexport PYTHONPATH={dirpath}\n"
19-
)
13+
PYTHONPATH = "."
14+
if (cwd := Path.cwd()) != (root := Path(__file__).parent.parent):
15+
PYTHONPATH = str(root.relative_to(cwd))
16+
print(f"You may need to explicitly declare python path:\n\nexport {PYTHONPATH=}\n")
2017
raise
2118

2219

0 commit comments

Comments
 (0)