Skip to content

Commit 1faafec

Browse files
committed
Merge branch 'release/5.1.1'
2 parents 6eec110 + e5a2d55 commit 1faafec

Some content is hidden

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

54 files changed

+1077
-844
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ jobs:
2323
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v2
26+
- uses: actions/checkout@v4
2727
- name: Set up Python
2828
uses: actions/setup-python@v2
2929
with:
30-
python-version: '3.9'
30+
python-version: '3.11'
3131
- name: Install deps
3232
run: |
3333
pip install -U pip
34-
pip install poetry==1.4.2
34+
pip install poetry==1.8.2
3535
poetry install
3636
env:
37-
POETRY_VIRTUALENVS_CREATE: false
37+
POETRY_VIRTUALENVS_CREATE: "False"
3838
- name: Setup GIT
3939
run: |
4040
git config --global user.name "fastapi_template"
4141
git config --global user.email "fastapi_template@pytest.python"
4242
- name: Run tests
43-
run: poetry run pytest -vv
43+
run: pytest -vv

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ docker run --rm -it -v "$(pwd):/projects" s3rius/fastapi_template
4545
One of the coolest features is that this project is extremely configurable.
4646
You can choose between different databases and even ORMs, or
4747
you can even generate a project without a database!
48-
Currently SQLAlchemy 2.0, TortoiseORM, Piccolo and Ormar are supported.
48+
Currently SQLAlchemy 2.0, TortoiseORM, Piccolo, Ormar and Beanie are supported.
4949

5050
This project can run as TUI or CLI and has excellent code documentation.
5151

@@ -82,11 +82,11 @@ Options:
8282
-n, --name TEXT Name of your awesome project
8383
-V, --version Prints current version
8484
--force Owerrite directory if it exists
85-
--quite Do not ask for features during generation
85+
--quiet Do not ask for features during generation
8686
--api-type [rest|graphql] Select API type for your application
87-
--db [none|sqlite|mysql|postgresql]
87+
--db [none|sqlite|mysql|postgresql|mongodb]
8888
Select a database for your app
89-
--orm [none|ormar|sqlalchemy|tortoise|psycopg|piccolo]
89+
--orm [none|ormar|sqlalchemy|tortoise|psycopg|piccolo|beanie]
9090
Choose Object–Relational Mapper lib
9191
--ci [none|gitlab_ci|github] Select a CI for your app
9292
--redis Add redis support

fastapi_template/cli.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ def disable_orm(ctx: BuilderContext) -> Optional[MenuEntry]:
4141
return None
4242

4343

44-
def do_not_ask_features_if_quite(ctx: BuilderContext) -> Optional[List[MenuEntry]]:
45-
if ctx.quite:
44+
def do_not_ask_features_if_quiet(ctx: BuilderContext) -> Optional[List[MenuEntry]]:
45+
if ctx.quiet:
4646
return [SKIP_ENTRY]
4747
return None
4848

@@ -158,7 +158,7 @@ def checker(ctx: BuilderContext) -> bool:
158158
),
159159
additional_info=Database(
160160
name="mysql",
161-
image="bitnami/mysql:8.0.30",
161+
image="mysql:8.4",
162162
async_driver="mysql+aiomysql",
163163
driver_short="mysql",
164164
driver="mysql",
@@ -178,13 +178,30 @@ def checker(ctx: BuilderContext) -> bool:
178178
),
179179
additional_info=Database(
180180
name="postgresql",
181-
image="postgres:13.8-bullseye",
181+
image="postgres:16.3-bullseye",
182182
async_driver="postgresql+asyncpg",
183183
driver_short="postgres",
184184
driver="postgresql",
185185
port=5432,
186186
),
187187
),
188+
MenuEntry(
189+
code="mongodb",
190+
user_view="MongoDB",
191+
description=(
192+
"{name} is one of the most popular NoSQL databases out there.".format(
193+
name=colored("MongoDB", color="green"),
194+
)
195+
),
196+
additional_info=Database(
197+
name="mongodb",
198+
image="mongo:7.0",
199+
async_driver="beanie",
200+
driver_short="mongodb",
201+
driver="mongodb",
202+
port=27017
203+
),
204+
)
188205
],
189206
)
190207

@@ -243,7 +260,7 @@ def checker(ctx: BuilderContext) -> bool:
243260
entries=[
244261
MenuEntry(
245262
code="none",
246-
user_view="Whithout ORMs",
263+
user_view="Without ORMs",
247264
description=(
248265
"If you select this option, you will get only {what}.\n"
249266
"The rest {warn}.".format(
@@ -256,7 +273,7 @@ def checker(ctx: BuilderContext) -> bool:
256273
MenuEntry(
257274
code="ormar",
258275
user_view="Ormar",
259-
pydantic_v1=True,
276+
is_hidden=check_db(["sqlite", "mysql", "postgresql"]),
260277
description=(
261278
"{what} is a great {feature} ORM.\n"
262279
"It's compatible with pydantic models and alembic migrator.".format(
@@ -268,6 +285,7 @@ def checker(ctx: BuilderContext) -> bool:
268285
MenuEntry(
269286
code="sqlalchemy",
270287
user_view="SQLAlchemy",
288+
is_hidden=check_db(["sqlite", "mysql", "postgresql"]),
271289
description=(
272290
"{what} is the most popular python ORM.\n"
273291
"It has a {feature} and a big community around it.".format(
@@ -279,6 +297,7 @@ def checker(ctx: BuilderContext) -> bool:
279297
MenuEntry(
280298
code="tortoise",
281299
user_view="Tortoise",
300+
is_hidden=check_db(["sqlite", "mysql", "postgresql"]),
282301
description=(
283302
"{what} is a great {feature} ORM.\n"
284303
"It's easy to use, it has it's own migration tooling.".format(
@@ -312,6 +331,18 @@ def checker(ctx: BuilderContext) -> bool:
312331
)
313332
),
314333
),
334+
MenuEntry(
335+
code="beanie",
336+
user_view="Beanie",
337+
is_hidden=check_db(["mongodb"]),
338+
description=(
339+
"{what} is an asynchronous object-document mapper (ODM) for MongoDB.\n"
340+
"Data models are based on Pydantic.".format(
341+
what=colored("Beanie", color="green"),
342+
)
343+
),
344+
),
345+
315346
],
316347
)
317348

@@ -320,14 +351,8 @@ def checker(ctx: BuilderContext) -> bool:
320351
code="features",
321352
description="Additional project features",
322353
multiselect=True,
323-
before_ask=do_not_ask_features_if_quite,
354+
before_ask=do_not_ask_features_if_quiet,
324355
entries=[
325-
MenuEntry(
326-
code="pydanticv1",
327-
cli_name="pydantic-v1",
328-
user_view="Use older version of pydantic",
329-
description="Use pydantic version ^1 instead of ^2",
330-
),
331356
MenuEntry(
332357
code="enable_redis",
333358
cli_name="redis",
@@ -661,7 +686,7 @@ def run_command(callback: Callable[[BuilderContext], None]) -> None:
661686
help="Owerrite directory if it exists",
662687
),
663688
Option(
664-
["--quite"],
689+
["--quiet"],
665690
is_flag=True,
666691
help="Do not ask for features during generation",
667692
),

fastapi_template/input_model.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import abc
2-
import enum
32
from collections import UserDict
43
from typing import Any, Callable, List, Optional
54

@@ -29,7 +28,6 @@ class MenuEntry(BaseModel):
2928
description: str
3029
is_hidden: Optional[Callable[["BuilderContext"], bool]] = None
3130
additional_info: Any = None
32-
pydantic_v1: bool = False
3331

3432
@property
3533
def generated_name(self) -> str:
@@ -159,8 +157,6 @@ def ask(self, context: "BuilderContext") -> Optional["BuilderContext"]:
159157
return
160158

161159
setattr(context, self.code, chosen_entry.code)
162-
if chosen_entry.pydantic_v1:
163-
context.pydanticv1 = True
164160

165161
return context
166162

@@ -240,10 +236,6 @@ def ask(self, context: "BuilderContext") -> Optional["BuilderContext"]:
240236
for entry in chosen_entries:
241237
setattr(context, entry.code, True)
242238

243-
for ch_entry in chosen_entries:
244-
if ch_entry.pydantic_v1:
245-
context.pydanticv1 = True
246-
247239
return context
248240

249241

fastapi_template/template/cookiecutter.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@
5959
"otlp_enabled": {
6060
"type": "bool"
6161
},
62-
"pydanticv1": {
63-
"type": "bool"
64-
},
6562
"gunicorn": {
6663
"type": "bool"
6764
},

fastapi_template/template/{{cookiecutter.project_name}}/.github/workflows/tests.yml

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,24 @@ name: Testing {{cookiecutter.project_name}}
33
on: push
44

55
jobs:
6-
black:
6+
lint:
7+
strategy:
8+
matrix:
9+
cmd:
10+
- black
11+
- ruff
12+
- mypy
713
runs-on: ubuntu-latest
814
steps:
9-
- uses: actions/checkout@v2
10-
- name: Set up Python
11-
uses: actions/setup-python@v2
12-
with:
13-
python-version: '3.9'
14-
- name: Install deps
15-
uses: knowsuchagency/poetry-install@v1
16-
env:
17-
POETRY_VIRTUALENVS_CREATE: false
18-
- name: Run black check
19-
run: poetry run black --check .
20-
flake8:
21-
runs-on: ubuntu-latest
22-
steps:
23-
- uses: actions/checkout@v2
24-
- name: Set up Python
25-
uses: actions/setup-python@v2
26-
with:
27-
python-version: '3.9'
28-
- name: Install deps
29-
uses: knowsuchagency/poetry-install@v1
30-
env:
31-
POETRY_VIRTUALENVS_CREATE: false
32-
- name: Run flake8 check
33-
run: poetry run flake8 --count .
34-
mypy:
35-
runs-on: ubuntu-latest
36-
steps:
37-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
3816
- name: Set up Python
39-
uses: actions/setup-python@v2
17+
uses: actions/setup-python@v5
4018
with:
41-
python-version: '3.9'
19+
python-version: '3.11'
4220
- name: Install deps
43-
uses: knowsuchagency/poetry-install@v1
44-
env:
45-
POETRY_VIRTUALENVS_CREATE: false
46-
- name: Run mypy check
47-
run: poetry run mypy .
21+
run: poetry install
22+
- name: Run lint check
23+
run: poetry run pre-commit run -a {{ '${{' }} matrix.cmd {{ '}}' }}
4824
pytest:
4925
runs-on: ubuntu-latest
5026
{%- if ((cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite") or
@@ -63,13 +39,16 @@ jobs:
6339
{%- endif %}
6440
{%- if cookiecutter.db_info.name == "mysql" %}
6541
MYSQL_ROOT_PASSWORD: "{{ cookiecutter.project_name }}"
66-
MYSQL_ROOT_USER: "{{ cookiecutter.project_name }}"
42+
MYSQL_USER: "{{ cookiecutter.project_name }}"
6743
MYSQL_DATABASE: "{{ cookiecutter.project_name }}"
68-
MYSQL_AUTHENTICATION_PLUGIN: "mysql_native_password"
6944
{%- endif %}
70-
{%- if cookiecutter.db_info.name == "mysql" %}
45+
{%- if cookiecutter.db_info.name == "mongodb" %}
46+
MONGO_INITDB_ROOT_USERNAME: "{{ cookiecutter.project_name }}"
47+
MONGO_INITDB_ROOT_PASSWORD: "{{ cookiecutter.project_name }}"
48+
{%- endif %}
49+
{%- if cookiecutter.db_info.name == "mysql" %}
7150
options: >-
72-
--health-cmd="mysqladmin ping -u root"
51+
--health-cmd="mysqladmin ping --user={{ cookiecutter.project_name }} --password={{ cookiecutter.project_name }}"
7352
--health-interval=15s
7453
--health-timeout=5s
7554
--health-retries=6
@@ -148,6 +127,9 @@ jobs:
148127
{%- if cookiecutter.db_info.name != "sqlite" %}
149128
{{ cookiecutter.project_name | upper }}_DB_HOST: localhost
150129
{%- endif %}
130+
{%- if cookiecutter.db_info.name == "mongodb" %}
131+
{{ cookiecutter.project_name | upper }}_DB_BASE: admin
132+
{%- endif %}
151133
{%- endif %}
152134
{%- if cookiecutter.enable_rmq == "True" %}
153135
{{ cookiecutter.project_name | upper }}_RABBIT_HOST: localhost

fastapi_template/template/{{cookiecutter.project_name}}/.gitlab-ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ pytest:
6969
MYSQL_DATABASE: {{ cookiecutter.project_name }}
7070
ALLOW_EMPTY_PASSWORD: yes
7171
{%- endif %}
72+
73+
{%- if cookiecutter.db_info.name == "mongodb" %}
74+
75+
# MongoDB variables
76+
{{ cookiecutter.project_name | upper }}_DB_HOST: database
77+
{{ cookiecutter.project_name | upper }}_DB_BASE: admin
78+
MONGO_INITDB_ROOT_USERNAME: {{ cookiecutter.project_name }}
79+
MONGO_INITDB_ROOT_PASSWORD: {{ cookiecutter.project_name }}
80+
{%- endif %}
81+
7282
{%- if cookiecutter.enable_rmq == "True" %}
7383

7484
# Rabbitmq variables

fastapi_template/template/{{cookiecutter.project_name}}/.pre-commit-config.yaml

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,22 @@
22
# See https://pre-commit.com for more information
33
# See https://pre-commit.com/hooks.html for more hooks
44
repos:
5-
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v2.4.0
7-
hooks:
8-
- id: check-ast
9-
- id: trailing-whitespace
10-
- id: check-toml
11-
- id: end-of-file-fixer
12-
13-
- repo: https://github.com/asottile/add-trailing-comma
14-
rev: v2.1.0
15-
hooks:
16-
- id: add-trailing-comma
17-
18-
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
19-
rev: v2.1.0
20-
hooks:
21-
- id: pretty-format-yaml
22-
args:
23-
- --autofix
24-
- --preserve-quotes
25-
- --indent=2
26-
275
- repo: local
286
hooks:
29-
- id: autoflake
30-
name: autoflake
31-
entry: poetry run autoflake
32-
language: system
33-
types: [python]
34-
args: [--in-place, --remove-all-unused-imports, --remove-duplicate-keys]
357

368
- id: black
379
name: Format with Black
3810
entry: poetry run black
3911
language: system
4012
types: [python]
4113

42-
- id: isort
43-
name: isort
44-
entry: poetry run isort
45-
language: system
46-
types: [python]
47-
48-
- id: flake8
49-
name: Check with Flake8
50-
entry: poetry run flake8
14+
- id: ruff
15+
name: Check with Ruff
16+
entry: poetry run ruff
5117
language: system
5218
pass_filenames: false
53-
types: [python]
54-
args: [--count, .]
19+
always_run: true
20+
args: ["check", "{{cookiecutter.project_name}}", "tests", "--fix"]
5521

5622
- id: mypy
5723
name: Validate types with MyPy

0 commit comments

Comments
 (0)