Skip to content

Commit 41edbc3

Browse files
committed
Merge branch 'release/3.3.1'
2 parents 516e3b9 + e01e29a commit 41edbc3

File tree

19 files changed

+609
-331
lines changed

19 files changed

+609
-331
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ optional arguments:
9090
--kube Add kubernetes configs
9191
--dummy, --dummy-model
9292
Add dummy model
93-
--routers Add exmaple routers
94-
--swagger Eanble self-hosted swagger
93+
--routers Add example routers
94+
--swagger Enable self-hosted swagger
9595
--force Owerrite directory if it exists
9696
--quite Do not ask for feature during generation
9797
```

fastapi_template/cli.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import re
22
from argparse import ArgumentParser
33
from operator import attrgetter
4+
from termcolor import cprint
45

56
from prompt_toolkit import prompt
67
from prompt_toolkit.document import Document
78
from prompt_toolkit.shortcuts import checkboxlist_dialog, radiolist_dialog
89
from prompt_toolkit.validation import ValidationError, Validator
910

1011
from fastapi_template.input_model import (
12+
SUPPORTED_ORMS,
13+
ORMS_WITHOUT_MIGRATIONS,
1114
ORM,
1215
BuilderContext,
1316
DB_INFO,
@@ -99,14 +102,14 @@ def parse_args():
99102
)
100103
parser.add_argument(
101104
"--routers",
102-
help="Add exmaple routers",
105+
help="Add example routers",
103106
action="store_true",
104107
default=None,
105108
dest="enable_routers",
106109
)
107110
parser.add_argument(
108111
"--swagger",
109-
help="Eanble self-hosted swagger",
112+
help="Enable self-hosted swagger",
110113
action="store_true",
111114
default=None,
112115
dest="self_hosted_swagger",
@@ -199,10 +202,19 @@ def read_user_input(current_context: BuilderContext) -> BuilderContext:
199202
current_context.orm = radiolist_dialog(
200203
"ORM",
201204
text="Which ORM do you want?",
202-
values=[(orm, orm.value) for orm in list(ORM) if orm != ORM.none],
205+
values=[(orm, orm.value) for orm in SUPPORTED_ORMS[current_context.db]],
203206
).run()
204207
if current_context.orm is None:
205208
raise KeyboardInterrupt()
209+
if (
210+
current_context.orm is not None
211+
and current_context.orm != ORM.none
212+
and current_context.orm not in SUPPORTED_ORMS.get(current_context.db, [])
213+
):
214+
cprint("This ORM is not supported by chosen database.", "red")
215+
raise KeyboardInterrupt()
216+
if current_context.orm in ORMS_WITHOUT_MIGRATIONS:
217+
current_context.enable_migrations = False
206218
if current_context.ci_type is None:
207219
current_context.ci_type = radiolist_dialog(
208220
"CI",

fastapi_template/input_model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ORM(enum.Enum):
2424
ormar = "ormar"
2525
sqlalchemy = "sqlalchemy"
2626
tortoise = "tortoise"
27+
psycopg = "psycopg"
2728

2829

2930
class Database(BaseModel):
@@ -69,6 +70,28 @@ class Database(BaseModel):
6970
),
7071
}
7172

73+
SUPPORTED_ORMS = {
74+
DatabaseType.postgresql: [
75+
ORM.ormar,
76+
ORM.psycopg,
77+
ORM.tortoise,
78+
ORM.sqlalchemy,
79+
],
80+
DatabaseType.sqlite: [
81+
ORM.ormar,
82+
ORM.tortoise,
83+
ORM.sqlalchemy,
84+
],
85+
DatabaseType.mysql: [
86+
ORM.ormar,
87+
ORM.tortoise,
88+
ORM.sqlalchemy,
89+
]
90+
}
91+
92+
ORMS_WITHOUT_MIGRATIONS = [
93+
ORM.psycopg,
94+
]
7295

7396
class BuilderContext(BaseModel):
7497
"""Options for project generation."""

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ ignore =
6060
WPS404,
6161
; not perform function calls in argument defaults (for dependency injection)
6262
B008,
63+
; Model should define verbose_name in its Meta inner class
64+
DJ10,
65+
; Model should define verbose_name_plural in its Meta inner class
66+
DJ11,
6367

6468
per-file-ignores =
6569
; all tests

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
"{{cookiecutter.project_name}}/db_ormar/models/dummy_model.py",
8181
"{{cookiecutter.project_name}}/db_tortoise/dao",
8282
"{{cookiecutter.project_name}}/db_tortoise/models/dummy_model.py",
83+
"{{cookiecutter.project_name}}/db_psycopg/dao",
84+
"{{cookiecutter.project_name}}/db_psycopg/models/dummy_model.py",
8385
"{{cookiecutter.project_name}}/tests/test_dummy.py",
8486
"{{cookiecutter.project_name}}/db_sa/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
8587
"{{cookiecutter.project_name}}/db_ormar/migrations/versions/2021-08-16-16-55_2b7380507a71.py",
@@ -114,6 +116,12 @@
114116
"{{cookiecutter.project_name}}/db_ormar"
115117
]
116118
},
119+
"PsycoPG": {
120+
"enabled": "{{cookiecutter.orm == 'psycopg'}}",
121+
"resources": [
122+
"{{cookiecutter.project_name}}/db_psycopg"
123+
]
124+
},
117125
"Postgresql DB": {
118126
"enabled": "{{cookiecutter.db_info.name == 'postgresql'}}",
119127
"resources": [

fastapi_template/template/{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,91 @@ readme = "README.md"
1212

1313
[tool.poetry.dependencies]
1414
python = "^3.9"
15-
fastapi = "^0.68.0"
16-
uvicorn = "^0.15.0"
17-
pydantic = {version = "^1.8.2", extras = ["dotenv"]}
18-
yarl = "^1.6.3"
19-
ujson = "^4.2.0"
15+
fastapi = "^0.75.0"
16+
uvicorn = "^0.17.0"
17+
pydantic = {version = "^1.9.0", extras = ["dotenv"]}
18+
yarl = "^1.7.2"
19+
ujson = "^5.1.0"
2020
{%- if cookiecutter.orm == "sqlalchemy" %}
2121
SQLAlchemy = {version = "^1.4", extras = ["mypy", "asyncio"]}
2222
{%- if cookiecutter.enable_migrations == "True" %}
23-
alembic = "^1.6.5"
23+
alembic = "^1.7.7"
2424
{%- endif %}
2525
{%- if cookiecutter.db_info.name == "postgresql" %}
26-
asyncpg = {version = "^0.24.0", extras = ["sa"]}
26+
asyncpg = {version = "^0.25.0", extras = ["sa"]}
2727
{%- elif cookiecutter.db_info.name == "sqlite" %}
2828
aiosqlite = "^0.17.0"
2929
{%- elif cookiecutter.db_info.name == "mysql" %}
30-
aiomysql = "^0.0.21"
31-
mysqlclient = "^2.0.3"
30+
aiomysql = "^0.0.22"
31+
mysqlclient = "^2.1.0"
3232
{%- endif %}
3333
{%- endif %}
3434
{%- if cookiecutter.orm == "tortoise" %}
35-
tortoise-orm = "^0.17.7"
35+
tortoise-orm = "^0.19.0"
3636
{%- if cookiecutter.enable_migrations == "True" %}
37-
aerich = "^0.5.8"
37+
aerich = "^0.6.2"
3838
{%- endif %}
3939
{%- if cookiecutter.db_info.name == "postgresql" %}
40-
asyncpg = "^0.24.0"
40+
asyncpg = "^0.25.0"
4141
{%- elif cookiecutter.db_info.name == "sqlite" %}
4242
aiosqlite = "^0.17.0"
4343
{%- elif cookiecutter.db_info.name == "mysql" %}
4444
aiomysql = "^0.0.21"
4545
mysqlclient = "^2.0.3"
46-
cryptography = "^3.4.8"
46+
cryptography = "^36.0.2"
4747
{%- endif %}
4848
{%- endif %}
4949
{%- if cookiecutter.orm == "ormar" %}
50-
ormar = "^0.10.20"
50+
ormar = "^0.11.0"
5151
{%- if cookiecutter.enable_migrations == "True" %}
52-
alembic = "^1.6.5"
52+
alembic = "^1.7.7"
5353
{%- endif %}
5454
{%- if cookiecutter.db_info.name == "postgresql" %}
55-
asyncpg = "^0.24.0"
56-
psycopg2-binary = "^2.9.1"
55+
asyncpg = "^0.25.0"
56+
psycopg2-binary = "^2.9.3"
5757
{%- elif cookiecutter.db_info.name == "sqlite" %}
5858
aiosqlite = "^0.17.0"
5959
{%- elif cookiecutter.db_info.name == "mysql" %}
60-
aiomysql = "^0.0.21"
61-
mysqlclient = "^2.0.3"
60+
aiomysql = "^0.0.22"
61+
mysqlclient = "^2.1.0"
6262
{%- endif %}
6363
{%- endif %}
6464
{%- if cookiecutter.enable_redis == "True" %}
65-
aioredis = {version = "^2.0.0", extras = ["hiredis"]}
65+
aioredis = {version = "^2.0.1", extras = ["hiredis"]}
6666
{%- endif %}
6767
{%- if cookiecutter.self_hosted_swagger == 'True' %}
68-
aiofiles = "^0.7.0"
68+
aiofiles = "^0.8.0"
69+
{%- endif %}
70+
{%- if cookiecutter.orm == "psycopg" %}
71+
psycopg = { version = "^3.0.11", extras = ["binary", "pool"] }
6972
{%- endif %}
7073
httptools = "^0.3.0"
71-
async-exit-stack = "^1.0.1"
72-
async-generator = "^1.10"
7374

7475
[tool.poetry.dev-dependencies]
75-
pytest = "^6.0"
76-
flake8 = "^3.9.2"
76+
pytest = "^7.0"
77+
flake8 = "^4.0.1"
7778
mypy = "^0.910"
7879
isort = "^5.9.3"
7980
yesqa = "^1.2.3"
8081
pre-commit = "^2.11.0"
81-
wemake-python-styleguide = "^0.15.3"
82-
black = "==21.7b0"
82+
wemake-python-styleguide = "^0.16.1"
83+
black = "^22.3.0"
8384
autoflake = "^1.4"
8485
{%- if cookiecutter.orm == "sqlalchemy" %}
8586
SQLAlchemy = {version = "^1.4", extras = ["mypy"]}
8687
{%- endif %}
87-
pytest-cov = "^2.12.1"
88-
pytest-asyncio = "^0.15.1"
89-
nest-asyncio = "^1.5.1"
88+
pytest-cov = "^3.0.0"
89+
anyio = "^3.5.0"
9090
pytest-env = "^0.6.2"
9191
{%- if cookiecutter.enable_redis == "True" %}
92-
fakeredis = "^1.6.1"
92+
fakeredis = "^1.7.1"
9393
{%- endif %}
9494
requests = "^2.26.0"
9595
{%- if cookiecutter.orm == "tortoise" %}
9696
asynctest = "^0.13.0"
97+
nest-asyncio = "^1.5.5"
9798
{%- endif %}
99+
httpx = "^0.22.0"
98100

99101

100102
[tool.isort]
@@ -120,6 +122,7 @@ plugins = ["sqlalchemy.ext.mypy.plugin"]
120122
filterwarnings = [
121123
"error",
122124
"ignore::DeprecationWarning",
125+
"ignore:.*unclosed.*:ResourceWarning",
123126
]
124127
{%- if cookiecutter.db_info.name != "none" %}
125128
env = [
@@ -131,6 +134,15 @@ env = [
131134
]
132135
{%- endif %}
133136

137+
{%- if cookiecutter.orm == "tortoise" %}
138+
{%- if cookiecutter.enable_migrations == "True" %}
139+
[tool.aerich]
140+
tortoise_orm = "{{cookiecutter.project_name}}.db.config.TORTOISE_CONFIG"
141+
location = "./{{cookiecutter.project_name}}/db/migrations"
142+
src_folder = "./{{cookiecutter.project_name}}"
143+
{%- endif %}
144+
{%- endif %}
145+
134146
[build-system]
135147
requires = ["poetry-core>=1.0.0"]
136148
build-backend = "poetry.core.masonry.api"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"{{cookiecutter.project_name}}/db": [
33
"{{cookiecutter.project_name}}/db_sa",
44
"{{cookiecutter.project_name}}/db_ormar",
5-
"{{cookiecutter.project_name}}/db_tortoise"
5+
"{{cookiecutter.project_name}}/db_tortoise",
6+
"{{cookiecutter.project_name}}/db_psycopg"
67
]
78
}

0 commit comments

Comments
 (0)