Skip to content

Commit 7803668

Browse files
committed
Adding Makefile. Updating docs.
1 parent daaf171 commit 7803668

6 files changed

Lines changed: 106 additions & 6 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ __pycache__
44
*.pyc
55

66
.idea
7-
.vscode
7+
.vscode
8+
*.log

‎LICENSE‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020 vincedgy
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

‎Makefile‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# .PHONY defines parts of the makefile that are not dependant on any specific file
2+
# This is most often used to store functions
3+
.PHONY = help install test run
4+
5+
# Defines the default target that `make` will to try to make, or in the case of a phony target, execute the specified commands
6+
# This target is executed whenever we just type `make`
7+
.DEFAULT_GOAL = help
8+
9+
# Server status evaluation
10+
SERVER_PID := $(shell sh -c "ps | grep -v grep | grep 'src/main.py' | head -1 | cut -d \t -f1")
11+
ifeq ('$(strip $(SERVER_PID))','')
12+
SERVER_RUNNING=FALSE
13+
else
14+
SERVER_RUNNING=TRUE
15+
endif
16+
17+
CHILD_PID := $(shell sh -c "ps -ax | grep -i spawn_main | grep -v grep | cut -d ' ' -f1")
18+
ifeq ('$(strip $(CHILD_PID))','')
19+
HAVE_CHILD=FALSE
20+
else
21+
HAVE_CHILD=TRUE
22+
endif
23+
24+
25+
# The @ makes sure that the command itself isn't echoed in the terminal
26+
help:
27+
@echo "---------------HELP-----------------"
28+
@echo "- Setup the project : make install"
29+
@echo "- Run the server (blocking): make start"
30+
@echo "- Evaluate status of the server : make status"
31+
@echo "- Stop (killp) the server : make kill"
32+
@echo "- Run tests on a running server: make tests"
33+
@echo "------------------------------------"
34+
35+
install:
36+
@poetry install
37+
38+
status:
39+
@date
40+
@echo "Running status of server is $(SERVER_RUNNING)"
41+
@echo "Running status of child runners is $(HAVE_CHILD)"
42+
43+
do_stop_server:
44+
@-kill -9 $(SERVER_PID)
45+
do_stop_children:
46+
@-kill -9 $(CHILD_PID)
47+
kill: status do_stop_server do_stop_children
48+
@echo "Killing server on PID $(SERVER_PID) and children on PID $(CHILD_PID)"
49+
@-lsof -i tcp:5000
50+
51+
tail:
52+
@tail run.log
53+
54+
do_start:
55+
@poetry run python src/main.py >run.log 2>&1 &
56+
@$(shell sleep 3)
57+
start: do_start
58+
@echo Check run.log for logging
59+
60+
61+
tests: install
62+
@poetry run pytest
63+
64+
serve:
65+
@poetry run mkdocs serve
66+
67+
publish:
68+
@poetry run mkdocs gh-deploy
69+

‎mkdocs.yml‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
site_name: FastAPI with async and Postgresql
2-
site_url: https://vincedgy.github.io/first_mkdocs/
2+
site_url: https://vincedgy.github.io/fastapi-async-with-postgresql/
3+
site_author: vincedgy
4+
copyright: MIT
35

4-
repo_url: https://github.com/vincedgy/first_mkdocs
6+
repo_url: https://github.com/vincedgy/fastapi-async-with-postgresql
57
edit_uri: tree/main/docs
68
repo_name: GitHub
79

810
nav:
911
- Home: index.md
1012
- About: about.md
1113
theme:
12-
name: readthedocs
14+
name: mkdocs
1315
extra_css:
1416
- css/extra.css
1517
highlightjs: true

‎src/main.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def create_note(note: NoteIn):
5656
@app.put("/notes/{note_id}", response_model=Note)
5757
async def update_note(note_id: int, payload: NoteIn):
5858
"""Update one note given its id"""
59-
query = notes.select().where(text(f"id={note_id}"))
59+
query = notes.select().where(notes.c.id == note_id)
6060
row = await database.fetch_one(query=query)
6161
if row is None:
6262
logger.info("No record !")
@@ -97,7 +97,7 @@ async def get_notes(skip: int = 0, take: int = 20):
9797
@app.get("/notes/{note_id}", response_model=Note, description="Fetch one Note given the note_id")
9898
async def get_one_note_by_id(note_id: int):
9999
"""Fetch one Note given the note_id"""
100-
query = notes.select().where(text(f"id={note_id}"))
100+
query = notes.select().where(notes.c.id == note_id)
101101
row = await database.fetch_one(query=query)
102102
if row is None:
103103
logger.info("No record !")

‎src/tests/test_api.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
from src import __version__
22

3+
import requests
4+
35

46
def test_version():
7+
"""Test version"""
58
assert __version__ == '0.1.0'
9+
10+
11+
def test_get_notes():
12+
"""Request notes"""
13+
response = requests.get("http://localhost:5000/notes")
14+
assert response.status_code == 200

0 commit comments

Comments
 (0)