Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1d674e4

Browse files
Bump dependencies.
1 parent e5bd958 commit 1d674e4

File tree

15 files changed

+573
-558
lines changed

15 files changed

+573
-558
lines changed

‎.env.example‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
FLASK_ENV=production
1+
ENVIRONMENT=production
2+
FLASK_DEBUG=False
23
SECRET_KEY=YOURSECRETKEY
34
SQLALCHEMY_DATABASE_URI=mysql+pymysql://[USER]:[PASSWORD]@[HOST]:[PORT]/[DATABASE_NAME]

‎.flake8‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
select = E9,F63,F7,F82
3+
exclude = .git,.github,__pycache__,.pytest_cache,.venv,logs,creds
4+
max-line-length = 120

‎Makefile‎

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,93 @@
11
PROJECT_NAME := $(shell basename $CURDIR)
2-
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
3-
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3
2+
VIRTUAL_ENV := $(CURDIR)/.venv
3+
LOCAL_PYTHON := $(VIRTUAL_ENV)/bin/python3
44

55
define HELP
66
Manage $(PROJECT_NAME). Usage:
77

8-
make run - Run $(PROJECT_NAME).
9-
make install - Create virtual env, install dependencies, and run project.
10-
make deploy - Install and run script by running `make install` and `make run` in succession.
11-
make update - Update pip dependencies via Poetry and export output to requirements.txt.
12-
make format - Format code with Pythons `Black` library.
13-
make lint - Check code formatting with `flake8`.
14-
make clean - Remove cached files and lock files.
8+
make run - Run $(PROJECT_NAME) locally.
9+
make install - Create local virtualenv & install dependencies.
10+
make deploy - Set up project & run locally.
11+
make update - Update dependencies via Poetry and output resulting `requirements.txt`.
12+
make format - Run Python code formatter & sort dependencies.
13+
make lint - Check code formatting with flake8.
14+
make clean - Remove extraneous compiled files, caches, logs, etc.
1515

1616
endef
1717
export HELP
1818

1919

2020
.PHONY: run install deploy update format lint clean help
2121

22-
requirements: .requirements.txt
23-
env: ./.venv/bin/activate
24-
25-
26-
.requirements.txt: requirements.txt
27-
$(shell . .venv/bin/activate && pip install -r requirements.txt)
28-
29-
3022
all help:
3123
@echo "$$HELP"
3224

25+
env: $(VIRTUAL_ENV)
26+
27+
$(VIRTUAL_ENV):
28+
if [ ! -d $(VIRTUAL_ENV) ]; then \
29+
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
30+
python3 -m venv $(VIRTUAL_ENV); \
31+
fi
3332

3433
.PHONY: run
3534
run: env
36-
flask run
37-
35+
$(LOCAL_PYTHON) -m main
3836

3937
.PHONY: install
40-
install:
41-
if [ ! -d "./.venv" ]; then python3 -m venv $(VIRTUAL_ENVIRONMENT); fi
42-
. .venv/bin/activate
43-
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel
44-
$(LOCAL_PYTHON) -m pip install -r requirements.txt
45-
38+
install: env
39+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
40+
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
41+
npm i -g less && \
42+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4643

4744
.PHONY: deploy
4845
deploy:
49-
make install
46+
make install&&\
5047
make run
5148

49+
.PHONY: test
50+
test: env
51+
$(LOCAL_PYTHON) -m \
52+
coverage run -m pytest -vv \
53+
--disable-pytest-warnings && \
54+
coverage html --title='Coverage Report' -d .reports && \
55+
open .reports/index.html
5256

5357
.PHONY: update
54-
update:
55-
if [ ! -d "./.venv" ]; then python3 -m venv $(VIRTUAL_ENVIRONMENT); fi
56-
.venv/bin/python3 -m pip install --upgrade pip setuptools wheel
57-
poetry update
58-
poetry export -f requirements.txt --output requirements.txt --without-hashes
59-
58+
update: env
59+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
60+
poetry update && \
61+
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
62+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
6063

6164
.PHONY: format
6265
format: env
63-
isort --multi-line=3 .
64-
black .
65-
66+
$(LOCAL_PYTHON) -m isort --multi-line=3 . && \
67+
$(LOCAL_PYTHON) -m black .
6668

6769
.PHONY: lint
68-
lint:
69-
flake8 . --count \
70+
lint: env
71+
$(LOCAL_PYTHON) -m flake8 . --count \
7072
--select=E9,F63,F7,F82 \
71-
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
73+
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
7274
--show-source \
7375
--statistics
7476

75-
7677
.PHONY: clean
7778
clean:
78-
find . -name '*.pyc' -delete
79-
find . -name '__pycache__' -delete
80-
find . -name 'poetry.lock' -delete
81-
find . -name '*.log' -delete
82-
find . -name '.DS_Store' -delete
83-
find . -wholename 'logs/*.json' -delete
84-
find . -wholename '.pytest_cache' -delete
85-
find . -wholename '**/.pytest_cache' -delete
86-
find . -wholename './logs/*.json' -delete
87-
find . -wholename './logs' -delete
88-
find . -wholename '*.html' -delete
89-
find . -wholename '**/.webassets-cache' -delete
79+
find . -name '.coverage' -delete && \
80+
find . -name '*.pyc' -delete \
81+
find . -name '__pycache__' -delete \
82+
find . -name 'poetry.lock' -delete \
83+
find . -name '*.log' -delete \
84+
find . -name '.DS_Store' -delete \
85+
find . -wholename '**/*.pyc' -delete && \
86+
find . -wholename '**/*.html' -delete && \
87+
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
88+
find . -type d -wholename '.venv' -exec rm -rf {} + && \
89+
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
90+
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + && \
91+
find . -type d -wholename '**/*.log' -exec rm -rf {} + && \
92+
find . -type d -wholename './.reports/*' -exec rm -rf {} + && \
93+
find . -type d -wholename '**/.webassets-cache' -exec rm -rf {} +

‎README.md‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Flask-SQLAlchemy Tutorial
22

3-
![Python](https://img.shields.io/badge/Python-v^3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4-
![Flask](https://img.shields.io/badge/Flask-v2.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5-
![Flask-SQLAlchemy](https://img.shields.io/badge/Flask--SQLAlchemy-2.5.1-red.svg?longCache=true&style=flat-square&logo=flask&logoColor=white&colorA=4c566a&colorB=5e81ac)
3+
![Python](https://img.shields.io/badge/Python-v^3.10-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4+
![Flask](https://img.shields.io/badge/Flask-v2.3.3-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5+
![Flask-SQLAlchemy](https://img.shields.io/badge/Flask--SQLAlchemy-3.1.1-red.svg?longCache=true&style=flat-square&logo=flask&logoColor=white&colorA=4c566a&colorB=5e81ac)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c)
77
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-sqlalchemy-tutorial.svg?style=flat-square&colorA=4c566a&colorB=ebcb8b&logo=Github)](https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/issues)
88
[![GitHub Stars](https://img.shields.io/github/stars/hackersandslackers/flask-sqlalchemy-tutorial.svg?style=flat-square&colorB=ebcb8b&colorA=4c566a&logo=Github)](https://github.com/hackersandslackers/flask-sqlalchemy-tutorial/stargazers)
@@ -13,19 +13,18 @@
1313
Connect your Flask app to a database using Flask-SQLAlchemy.
1414

1515
* **Tutorial**: https://hackersandslackers.com/manage-database-models-with-flask-sqlalchemy/
16-
1716
* **Demo**: https://flasksqlalchemy.hackersandslackers.app
1817

19-
# Getting Started
18+
## Getting Started
2019

2120
Get set up locally in two steps:
2221

2322
### Environment Variables
2423

2524
Replace the values in **.env.example** with your values and rename this file to **.env**:
2625

27-
* `FLASK_APP`: Entry point of your application; should be `wsgi.py`.
28-
* `FLASK_ENV`: The environment in which to run your application; either `development` or `production`.
26+
* `ENVIRONMENT`: The environment in which to run your application; either `development` or `production`.
27+
* `FLASK_DEBUG`: Whether to run Flask in "debug mode".
2928
* `SECRET_KEY`: Randomly generated string of characters used to encrypt your app's data.
3029
* `SQLALCHEMY_DATABASE_URI`: SQLAlchemy connection URI to a SQL database.
3130

@@ -36,10 +35,10 @@ Replace the values in **.env.example** with your values and rename this file to
3635
Get up and running with `make deploy`:
3736

3837
```shell
39-
$ git clone https://github.com/hackersandslackers/flask-sqlalchemy-tutorial.git
40-
$ cd flask-sqlalchemy-tutorial
41-
$ make deploy
42-
```
38+
git clone https://github.com/hackersandslackers/flask-sqlalchemy-tutorial.git
39+
cd flask-sqlalchemy-tutorial
40+
make deploy
41+
```
4342

4443
-----
4544

‎config.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
"""Flask configuration variables."""
2-
from os import environ, path
3-
4-
from dotenv import load_dotenv
5-
6-
basedir = path.abspath(path.dirname(__file__))
7-
load_dotenv(path.join(basedir, ".env"))
2+
from os import environ
83

94

105
class Config:
116
"""Set Flask configuration from .env file."""
127

138
# General Config
14-
SECRET_KEY = environ.get("SECRET_KEY")
15-
FLASK_APP = environ.get("FLASK_APP")
9+
ENVIRONMENT = environ.get("ENVIRONMENT")
10+
11+
# Flask Config
12+
FLASK_APP = "main.py"
13+
FLASK_DEBUG = environ.get("FLASK_DEBUG")
1614
FLASK_ENV = environ.get("FLASK_ENV")
1715

1816
# Database

‎deploy.sh‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎flask_sqlalchemy_tutorial/models.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44

55
class User(db.Model):
6-
"""Data model for user accounts."""
6+
"""User account data model."""
7+
8+
__tablename__ = "user"
79

8-
__tablename__ = "flasksqlalchemy-tutorial-users"
910
id = db.Column(db.Integer, primary_key=True)
1011
username = db.Column(db.String(64), index=True, unique=True, nullable=False)
1112
email = db.Column(db.String(80), index=True, unique=True, nullable=False)
@@ -14,4 +15,4 @@ class User(db.Model):
1415
admin = db.Column(db.Boolean, nullable=False)
1516

1617
def __repr__(self):
17-
return "<User {}>".format(self.username)
18+
return f"<User id={self.id}, username={self.username}, email={self.email}>"

‎flask_sqlalchemy_tutorial/routes.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Application routes."""
2-
from datetime import datetimeasdt
2+
from datetime import datetime
33

44
from flask import current_app as app
55
from flask import make_response, redirect, render_template, request, url_for
@@ -21,7 +21,7 @@ def user_records():
2121
new_user = User(
2222
username=username,
2323
email=email,
24-
created=dt.now(),
24+
created=datetime.now(),
2525
bio="In West Philadelphia born and raised, \
2626
on the playground is where I spent most of my days",
2727
admin=False,
6.74 KB
Loading[フレーム]
12.5 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /