Skip to content

Commit e2735d8

Browse files
committed
Merge tag '3.3.2' into develop
3.3.2
2 parents b362ae1 + 465bbf3 commit e2735d8

46 files changed

Lines changed: 917 additions & 67 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
name: Testing fastapi-template
22

3-
on:
4-
push:
5-
branches-ignore:
6-
- master
7-
tags-ignore:
8-
- "*"
3+
on:
94
pull_request:
10-
branches:
5+
branches:
116
- 'release/**'
127

138
jobs:
@@ -39,5 +34,9 @@ jobs:
3934
uses: knowsuchagency/poetry-install@v1
4035
env:
4136
POETRY_VIRTUALENVS_CREATE: false
37+
- name: Setup GIT
38+
run: |
39+
git config --global user.name "fastapi_template"
40+
git config --global user.email "fastapi_template@pytest.python"
4241
- name: Run tests
43-
run: poetry run pytest -vv --exitfirst
42+
run: poetry run pytest -vv --exitfirst -n auto

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ Currently SQLAlchemy1.4, TortoiseORM and Ormar are supported.
4949
TUI and CLI and excellent code documentation.
5050

5151
Generator features:
52+
- You can choose between GraphQL and REST api;
5253
- Different databases support;
5354
- Different ORMs support;
54-
- Optional migrations for each ORM;
55+
- Optional migrations for each ORM except raw drivers;
5556
- redis support;
5657
- different CI\CD;
5758
- Kubernetes config generation;
@@ -67,23 +68,26 @@ $ python -m fastapi_template --help
6768

6869
usage: FastAPI template [-h] [--version] [--name PROJECT_NAME]
6970
[--description PROJECT_DESCRIPTION]
71+
[--api-type {rest,graphql}]
7072
[--db {none,sqlite,mysql,postgresql}]
71-
[--orm {ormar,sqlalchemy,tortoise}]
72-
[--ci {none,gitlab,github}] [--redis] [--migrations]
73-
[--kube] [--dummy] [--routers] [--swagger] [--force]
74-
[--quite]
73+
[--orm {ormar,sqlalchemy,tortoise,psycopg,piccolo}]
74+
[--ci {none,gitlab_ci,github}] [--redis]
75+
[--migrations] [--kube] [--dummy] [--routers]
76+
[--swagger] [--force] [--quite]
7577

7678
optional arguments:
7779
-h, --help show this help message and exit
7880
--version, -V Prints current version
7981
--name PROJECT_NAME Name of your awesome project
8082
--description PROJECT_DESCRIPTION
8183
Project description
84+
--api-type {rest,graphql}
85+
API type
8286
--db {none,sqlite,mysql,postgresql}
8387
Database
84-
--orm {ormar,sqlalchemy,tortoise}
88+
--orm {ormar,sqlalchemy,tortoise,psycopg,piccolo}
8589
ORM
86-
--ci {none,gitlab,github}
90+
--ci {none,gitlab_ci,github}
8791
Choose CI support
8892
--redis Add redis support
8993
--migrations Add migrations support

fastapi_template/cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
SUPPORTED_ORMS,
1313
ORMS_WITHOUT_MIGRATIONS,
1414
ORM,
15+
APIType,
1516
BuilderContext,
1617
DB_INFO,
1718
DatabaseType,
@@ -47,6 +48,14 @@ def parse_args():
4748
dest="project_description",
4849
help="Project description",
4950
)
51+
parser.add_argument(
52+
"--api-type",
53+
help="API type",
54+
type=str,
55+
choices=list(map(attrgetter("value"), APIType)),
56+
default=None,
57+
dest="api_type",
58+
)
5059
parser.add_argument(
5160
"--db",
5261
help="Database",
@@ -186,6 +195,14 @@ def read_user_input(current_context: BuilderContext) -> BuilderContext:
186195
current_context.kube_name = current_context.project_name.replace("_", "-")
187196
if current_context.project_description is None:
188197
current_context.project_description = prompt("Project description: ")
198+
if current_context.api_type is None:
199+
current_context.api_type = radiolist_dialog(
200+
"API type",
201+
text="Which api type do you want?",
202+
values=[(api, api.value) for api in list(APIType)],
203+
).run()
204+
if current_context.api_type is None:
205+
raise KeyboardInterrupt()
189206
if current_context.db is None:
190207
current_context.db = radiolist_dialog(
191208
"Databases",

fastapi_template/input_model.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
from pydantic import BaseModel
55

66

7+
@enum.unique
8+
class APIType(enum.Enum):
9+
rest = "rest"
10+
graphql = "graphql"
11+
712
@enum.unique
813
class DatabaseType(enum.Enum):
914
none = "none"
@@ -25,6 +30,7 @@ class ORM(enum.Enum):
2530
sqlalchemy = "sqlalchemy"
2631
tortoise = "tortoise"
2732
psycopg = "psycopg"
33+
piccolo = "piccolo"
2834

2935

3036
class Database(BaseModel):
@@ -46,15 +52,15 @@ class Database(BaseModel):
4652
),
4753
DatabaseType.postgresql: Database(
4854
name=DatabaseType.postgresql.value,
49-
image="postgres:13.4-buster",
55+
image="postgres:13.6-bullseye",
5056
async_driver="postgresql+asyncpg",
5157
driver_short="postgres",
5258
driver="postgresql",
5359
port=5432,
5460
),
5561
DatabaseType.mysql: Database(
5662
name=DatabaseType.mysql.value,
57-
image="bitnami/mysql:8.0.26",
63+
image="bitnami/mysql:8.0.28",
5864
async_driver="mysql+aiomysql",
5965
driver_short="mysql",
6066
driver="mysql",
@@ -76,11 +82,13 @@ class Database(BaseModel):
7682
ORM.psycopg,
7783
ORM.tortoise,
7884
ORM.sqlalchemy,
85+
ORM.piccolo,
7986
],
8087
DatabaseType.sqlite: [
8188
ORM.ormar,
8289
ORM.tortoise,
8390
ORM.sqlalchemy,
91+
ORM.piccolo,
8492
],
8593
DatabaseType.mysql: [
8694
ORM.ormar,
@@ -95,7 +103,7 @@ class Database(BaseModel):
95103

96104
class BuilderContext(BaseModel):
97105
"""Options for project generation."""
98-
106+
api_type: Optional[APIType]
99107
project_name: Optional[str]
100108
kube_name: Optional[str]
101109
project_description: Optional[str]

fastapi_template/template/cookiecutter.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"project_description": {
66
"type": "string"
77
},
8+
"api_type": {
9+
"type": "dict"
10+
},
811
"db_info": {
912
"type": "dict"
1013
},

fastapi_template/template/{{cookiecutter.project_name}}/.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ ignore =
2222
D106,
2323
; First line should be in imperative mood
2424
D401,
25+
; Found wrong variable name
26+
WPS110,
2527
; Found `__init__.py` module with logic
2628
WPS326,
2729
; Found string constant over-use
@@ -64,6 +66,8 @@ ignore =
6466
DJ10,
6567
; Model should define verbose_name_plural in its Meta inner class
6668
DJ11,
69+
; Found mutable module constant.
70+
WPS407,
6771

6872
per-file-ignores =
6973
; all tests

fastapi_template/template/{{cookiecutter.project_name}}/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
# {{cookiecutter.project_name}}
22

3+
34
Start a project with:
45

56
```bash
67
docker-compose -f deploy/docker-compose.yml --project-directory . up
78
```
89

10+
If you want to develop in docker with autoreload, use this command:
11+
12+
```bash
13+
docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up
14+
```
15+
16+
This command exposes application on port 8000, mounts current directory and enables autoreload.
17+
18+
But you have to rebuild image every time you modify `poetry.lock` or `pyproject.toml` with this command:
19+
20+
```bash
21+
docker-compose -f deploy/docker-compose.yml --project-directory . build
22+
```
23+
24+
925
## Pre-commit
1026

1127
To install pre-commit simply run inside the shell:
@@ -46,6 +62,12 @@ alembic upgrade "head"
4662
{%- elif cookiecutter.orm == 'tortoise' %}
4763
# Upgrade database to the last migration.
4864
aerich upgrade
65+
66+
{%- elif cookiecutter.orm == 'piccolo' %}
67+
# You have to set a PICCOLO_CONF variable
68+
export PICCOLO_CONF="{{cookiecutter.project_name}}.piccolo_conf"
69+
# Now you can easily run migrations usuing
70+
piccolo migrations forwards all
4971
{%- endif %}
5072
```
5173

fastapi_template/template/{{cookiecutter.project_name}}/conditional_files.json

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
{
2+
"GraphQL API": {
3+
"enabled": "{{cookiecutter.api_type == 'graphql'}}",
4+
"resources": [
5+
"{{cookiecutter.project_name}}/web/gql"
6+
]
7+
},
8+
"REST API": {
9+
"enabled": "{{cookiecutter.api_type == 'rest'}}",
10+
"resources": [
11+
"{{cookiecutter.project_name}}/web/api/dummy",
12+
"{{cookiecutter.project_name}}/web/api/echo",
13+
"{{cookiecutter.project_name}}/web/api/redis"
14+
]
15+
},
216
"Redis": {
317
"enabled": "{{cookiecutter.enable_redis}}",
418
"resources": [
519
"{{cookiecutter.project_name}}/web/api/redis",
20+
"{{cookiecutter.project_name}}/web/gql/redis",
621
"{{cookiecutter.project_name}}/services/redis",
722
"{{cookiecutter.project_name}}/tests/test_redis.py",
823
"deploy/kube/redis.yml"
@@ -20,6 +35,7 @@
2035
"aerich.ini",
2136
"alembic.ini",
2237
"{{cookiecutter.project_name}}/web/api/dummy",
38+
"{{cookiecutter.project_name}}/web/gql/dummy",
2339
"{{cookiecutter.project_name}}/db_sa",
2440
"{{cookiecutter.project_name}}/tests/test_dummy.py",
2541
"deploy/kube/db.yml"
@@ -38,7 +54,8 @@
3854
"alembic.ini",
3955
"{{cookiecutter.project_name}}/db_sa/migrations",
4056
"{{cookiecutter.project_name}}/db_ormar/migrations",
41-
"{{cookiecutter.project_name}}/db_tortoise/migrations"
57+
"{{cookiecutter.project_name}}/db_tortoise/migrations",
58+
"{{cookiecutter.project_name}}/db_piccolo/migrations"
4259
]
4360
},
4461
"Alembic migrations": {
@@ -83,11 +100,14 @@
83100
"{{cookiecutter.project_name}}/db_psycopg/dao",
84101
"{{cookiecutter.project_name}}/db_psycopg/models/dummy_model.py",
85102
"{{cookiecutter.project_name}}/tests/test_dummy.py",
103+
"{{cookiecutter.project_name}}/db_piccolo/dao",
104+
"{{cookiecutter.project_name}}/db_piccolo/models/dummy_model.py",
86105
"{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
87106
"{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
88107
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_pg.sql",
89108
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_mysql.sql",
90-
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql"
109+
"{{cookiecutter.project_name}}/db_tortoise/migrations/models/1_20210928165300_init_dummy_sqlite.sql",
110+
"{{cookiecutter.project_name}}/db_piccolo/migrations/2022-04-16T17-38-51-672827.py"
91111
]
92112
},
93113
"Self-hosted swagger": {
@@ -122,6 +142,13 @@
122142
"{{cookiecutter.project_name}}/db_psycopg"
123143
]
124144
},
145+
"Piccolo": {
146+
"enabled": "{{cookiecutter.orm == 'piccolo'}}",
147+
"resources": [
148+
"{{cookiecutter.project_name}}/db_piccolo",
149+
"{{cookiecutter.project_name}}/piccolo_conf.py"
150+
]
151+
},
125152
"Postgresql DB": {
126153
"enabled": "{{cookiecutter.db_info.name == 'postgresql'}}",
127154
"resources": [
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3.9'
2+
3+
services:
4+
api:
5+
ports:
6+
- "8000:8000"
7+
volumes:
8+
- .:/app/src/
9+
environment:
10+
{{cookiecutter.project_name | upper}}_RELOAD: "True"

0 commit comments

Comments
 (0)