Skip to content

Commit e9d586c

Browse files
committed
Switch to FastAPI
1 parent b5fc961 commit e9d586c

File tree

121 files changed

+840
-2593
lines changed

Some content is hidden

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

121 files changed

+840
-2593
lines changed

Diff for: .gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ ansible/site.yml
1313
build
1414
cbsd.conf
1515
coverage.xml
16-
database.db
1716
fstab
1817
junit.xml
1918
local_config.py
2019
project.mk
2120
site.retry
22-
test.db
2321
vars.mk
2422

2523
dist/
2624
*.egg-info/
25+
*.sqlite

Diff for: LICENSE

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
BSD 2-Clause License
22

3-
Copyright (c) 2017, Goran Mekić
3+
Copyright (c) 2021, Goran Mekić
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without
77
modification, are permitted provided that the following conditions are met:
88

9-
* Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
1111

12-
* Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
1515

1616
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

Diff for: MANIFEST.in

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
include README.md
22
include LICENSE
3-
include common_config.py
4-
include config.py
53
include name.py
6-
graft migrations
4+
graft alembic
75
graft tests
86
graft freenit/project
9-
graft freenit/static
10-
graft freenit/templates

Diff for: README.md

+1-18
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
# Backend Startkit
2-
Template to get my favourite SQL stack up and running
3-
4-
5-
![diagram](https://github.com/mekanix/backend-startkit/raw/master/backend.png)
6-
7-
## Forking
8-
The `name.py` is special! Although it ends with .py, it is read by shell scripts and CBSD/Reggae `Makefile` (if you're using it). Because it's not regular Python file, it has some limitations. It should consist of one line:
9-
10-
```
11-
app_name="application" # noqa: E225
12-
```
13-
14-
There must be no space around `=` in the previous example, otherwise shell scripts won't work. The `noqa` part prevents `flake8` failing the test, because it normally requires spaces around `=`.
15-
16-
On fork, edit `name.py` and rename `application` directory acordingly.
17-
18-
[Backend Tutorial](https://github.com/freenit-framework/backend-tutorial)
1+
# fastapi-playground

Diff for: alembic.ini

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# sys.path path, will be prepended to sys.path if present.
11+
# defaults to the current working directory.
12+
prepend_sys_path = .
13+
14+
# timezone to use when rendering the date
15+
# within the migration file as well as the filename.
16+
# string value is passed to dateutil.tz.gettz()
17+
# leave blank for localtime
18+
# timezone =
19+
20+
# max length of characters to apply to the
21+
# "slug" field
22+
# truncate_slug_length = 40
23+
24+
# set to 'true' to run the environment during
25+
# the 'revision' command, regardless of autogenerate
26+
# revision_environment = false
27+
28+
# set to 'true' to allow .pyc and .pyo files without
29+
# a source .py file to be detected as revisions in the
30+
# versions/ directory
31+
# sourceless = false
32+
33+
# version location specification; this defaults
34+
# to alembic/versions. When using multiple version
35+
# directories, initial revisions must be specified with --version-path
36+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
37+
38+
# the output encoding used when revision files
39+
# are written from script.py.mako
40+
# output_encoding = utf-8
41+
42+
sqlalchemy.url = sqlite:///db.sqlite
43+
44+
45+
[post_write_hooks]
46+
# post_write_hooks defines scripts or Python functions that are run
47+
# on newly generated revision scripts. See the documentation for further
48+
# detail and examples
49+
50+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
51+
# hooks = black
52+
# black.type = console_scripts
53+
# black.entrypoint = black
54+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
55+
56+
# Logging configuration
57+
[loggers]
58+
keys = root,sqlalchemy,alembic
59+
60+
[handlers]
61+
keys = console
62+
63+
[formatters]
64+
keys = generic
65+
66+
[logger_root]
67+
level = WARN
68+
handlers = console
69+
qualname =
70+
71+
[logger_sqlalchemy]
72+
level = WARN
73+
handlers =
74+
qualname = sqlalchemy.engine
75+
76+
[logger_alembic]
77+
level = INFO
78+
handlers =
79+
qualname = alembic
80+
81+
[handler_console]
82+
class = StreamHandler
83+
args = (sys.stderr,)
84+
level = NOTSET
85+
formatter = generic
86+
87+
[formatter_generic]
88+
format = %(levelname)-5.5s [%(name)s] %(message)s
89+
datefmt = %H:%M:%S

Diff for: alembic/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

Diff for: alembic/env.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import sys
3+
4+
import freenit.app
5+
from alembic import context
6+
from freenit.migration import run_migrations_offline, run_migrations_online
7+
8+
9+
sys.path.append(os.getcwd())
10+
11+
12+
if context.is_offline_mode():
13+
run_migrations_offline()
14+
else:
15+
run_migrations_online()

Diff for: alembic/script.py.mako

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
${imports if imports else ""}
11+
12+
# revision identifiers, used by Alembic.
13+
revision = ${repr(up_revision)}
14+
down_revision = ${repr(down_revision)}
15+
branch_labels = ${repr(branch_labels)}
16+
depends_on = ${repr(depends_on)}
17+
18+
19+
def upgrade():
20+
${upgrades if upgrades else "pass"}
21+
22+
23+
def downgrade():
24+
${downgrades if downgrades else "pass"}

Diff for: alembic/versions/14eb8b6e464c_initial.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""initial
2+
3+
Revision ID: 14eb8b6e464c
4+
Revises:
5+
Create Date: 2021-07-18 12:28:52.118800
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "14eb8b6e464c"
14+
down_revision = None
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table(
22+
"users",
23+
sa.Column("id", sa.CHAR(36), nullable=False),
24+
sa.Column("email", sa.String(length=255), nullable=False),
25+
sa.Column("hashed_password", sa.String(length=255), nullable=False),
26+
sa.Column("is_active", sa.Boolean(), nullable=False),
27+
sa.Column("is_superuser", sa.Boolean(), nullable=False),
28+
sa.Column("is_verified", sa.Boolean(), nullable=False),
29+
sa.PrimaryKeyConstraint("id"),
30+
)
31+
op.create_index(op.f("ix_users_email"), "users", ["email"], unique=True)
32+
# ### end Alembic commands ###
33+
34+
35+
def downgrade():
36+
# ### commands auto generated by Alembic - please adjust! ###
37+
op.drop_index(op.f("ix_users_email"), table_name="users")
38+
op.drop_table("users")
39+
# ### end Alembic commands ###
File renamed without changes.

Diff for: ansible/roles/devel/tasks/main.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
---
21
- name: install devel packages
32
with_items: "{{ devel_packages }}"
4-
pkgng:
3+
package:
54
name: "{{ item.name }}"

Diff for: application.py

-7
This file was deleted.

Diff for: backend.dia

-1.78 KB
Binary file not shown.

Diff for: backend.png

-12.2 KB
Binary file not shown.

Diff for: bin/build.sh

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
#!/bin/sh
22

3-
4-
set -e
5-
6-
export BIN_DIR=`dirname $0`
7-
export PROJECT_ROOT="${BIN_DIR}/.."
3+
BIN_DIR=`dirname $0`
4+
PROJECT_DIR="${BIN_DIR}"
85
. ${BIN_DIR}/common.sh
9-
setup
106

117

12-
if [ "${OFFLINE}" != "yes" ]; then
13-
pip install -U --upgrade-strategy eager -e '.[dev]'
14-
fi
8+
setup no
9+
pip install -U pip
10+
pip install -U wheel
11+
pip install -U --upgrade-strategy eager -e ".[build]"
12+
1513

16-
cd ${PROJECT_ROOT}
1714
rm -rf *.egg-info build dist
1815
python setup.py sdist bdist_wheel

Diff for: bin/common.sh

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ export BIN_DIR=`dirname $0`
55
export PROJECT_ROOT="${BIN_DIR}/.."
66
. "${PROJECT_ROOT}/name.py"
77
export VIRTUALENV=${VIRTUALENV:="${app_name}"}
8-
export FLASK_ENV=${FLASK_ENV:="production"}
9-
export PY_VERSION=${PY_VERSION:="3.8"}
8+
export FREENIT_ENV=${FREENIT_ENV:="prod"}
109
export SYSPKG=${SYSPKG:="no"}
11-
export DBTYPE=${DBTYPE:="sql"}
1210

1311

1412
setup() {
@@ -23,10 +21,7 @@ setup() {
2321
if [ "${update}" != "no" ]; then
2422
pip install -U pip
2523
pip install -U wheel
26-
pip install -U --upgrade-strategy eager -e ".[${DBTYPE}]"
24+
pip install -U --upgrade-strategy eager -e .
2725
fi
2826
fi
29-
if [ -e "${BIN_DIR}/../migrations/main/001_initial.py" ]; then
30-
# flask migration run
31-
fi
3227
}

Diff for: bin/devel.sh

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
#!/bin/sh
22

3-
43
BIN_DIR=`dirname $0`
5-
export FLASK_PORT=${FLASK_PORT:=5000}
6-
export FLASK_ENV="development"
4+
export FREENIT_ENV="dev"
75
export OFFLINE=${OFFLINE:="no"}
8-
export SYSPKG="no"
96

107

118
. ${BIN_DIR}/common.sh
129
setup no
1310

14-
if [ "${SYSPKG}" = "no" ]; then
15-
if [ "${OFFLINE}" != "yes" ]; then
16-
pip install -U --upgrade-strategy eager -e '.[dev]'
17-
fi
11+
if [ ! -e "alembic/versions" ]; then
12+
mkdir alembic/versions
13+
alembic revision --autogenerate -m initial
14+
alembic upgrade head
1815
fi
1916

20-
2117
echo "Backend"
2218
echo "==============="
23-
uwsgi --master --http 0.0.0.0:${FLASK_PORT} ${WEBSOCKET_FLAGS} --python-auto-reload 1 --honour-stdin --wsgi-file devel.py
19+
uvicorn main:app --host 0.0.0.0 --port 5000 --reload

0 commit comments

Comments
 (0)