Skip to content

Commit cbe1788

Browse files
committed
Upgrade to Python 3.10; resolve dependency changes; minor refactor.
1 parent 9d114b6 commit cbe1788

File tree

11 files changed

+442
-530
lines changed

11 files changed

+442
-530
lines changed

.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: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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:
@@ -19,51 +19,54 @@ export HELP
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

3325

26+
env: $(VIRTUAL_ENV)
27+
28+
$(VIRTUAL_ENV):
29+
if [ ! -d $(VIRTUAL_ENV) ]; then \
30+
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
31+
python3 -m venv $(VIRTUAL_ENV); \
32+
fi
33+
3434
.PHONY: run
3535
run: env
36-
flask run
36+
$(LOCAL_PYTHON) -m gunicorn -w 4 wsgi:app
3737

3838

39-
.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
39+
requirements: .requirements.txt
40+
env: ./.venv/bin/activate
41+
4542

43+
.requirements.txt: requirements.txt
44+
$(shell . .venv/bin/activate && pip install -r requirements.txt)
45+
46+
.PHONY: install
47+
install: env
48+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
49+
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
50+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4651

4752
.PHONY: deploy
4853
deploy:
49-
make install
54+
make install && \
5055
make run
5156

52-
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
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}\`;
5963

6064

6165
.PHONY: format
6266
format: env
63-
isort --multi-line=3 .
67+
isort --multi-line=3 . && \
6468
black .
6569

66-
6770
.PHONY: lint
6871
lint:
6972
flake8 . --count \
@@ -72,18 +75,20 @@ lint:
7275
--show-source \
7376
--statistics
7477

75-
7678
.PHONY: clean
7779
clean:
78-
find . -name '*.pyc' -delete
79-
find . -name '__pycache__' -delete
80+
find . -name 'poetry.lock' -delete
81+
find . -name '.coverage' -delete
82+
find . -name '**/*.pyc' -delete
8083
find . -name 'poetry.lock' -delete
8184
find . -name '*.log' -delete
8285
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
86+
find . -wholename '**/*.pyc' -delete
87+
find . -wholename '**/*.html' -delete
88+
find . -type d -wholename '**/__pycache__/' -exec rm -rf {} \;
89+
find . -type d -wholename '.venv' -exec rm -rf {} \;
90+
find . -type d -wholename '.pytest_cache' -exec rm -rf {} \;
91+
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} \;
92+
find . -type d -wholename '**/*.log' -exec rm -rf {} \;
93+
find . -type d -wholename './.reports/*' -exec rm -rf {} \;
94+
find . -type d -wholename '**/.webassets-cache/' -exec rm -rf {} \;

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Flask-WTF 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-WTF](https://img.shields.io/badge/Flask--WTF-v1.0.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-v3.10-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4+
![Flask](https://img.shields.io/badge/Flask-v3.0.0-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5+
![Flask-WTF](https://img.shields.io/badge/Flask--WTF-v1.2.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
66
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)
77
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-wtform-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-wtform-tutorial/issues)
88
[![GitHub Stars](https://img.shields.io/github/stars/hackersandslackers/flask-wtform-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-wtform-tutorial/stargazers)
@@ -12,10 +12,10 @@
1212

1313
Handle user input in your Flask app by creating forms with the Flask-WTForm library.
1414

15-
* **Tutorial**: https://hackersandslackers.com/flask-wtforms-forms/
16-
* **Demo**: https://flaskwtf.hackersandslackers.app/
17-
=
18-
# Getting Started
15+
* **Tutorial**: [https://hackersandslackers.com/flask-wtforms-forms/](https://hackersandslackers.com/flask-wtforms-forms/)
16+
* **Demo**: [https://flaskwtf.hackersandslackers.app/](https://flaskwtf.hackersandslackers.app/)
17+
18+
## Getting Started
1919

2020
Get set up locally:
2121

@@ -24,22 +24,20 @@ Get set up locally:
2424
Get up and running with `make deploy`:
2525

2626
```shell
27-
$ git clone https://github.com/hackersandslackers/flask-wtform-tutorial.git
28-
$ cd flask-wtform-tutorial
29-
$ make deploy
30-
```
27+
git clone https://github.com/hackersandslackers/flask-wtform-tutorial.git
28+
cd flask-wtform-tutorial
29+
make deploy
30+
```
3131

3232
### Environment Variables
3333

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

36-
* `FLASK_APP`: Entry point of your application (should be `wsgi.py`).
37-
* `FLASK_ENV`: The environment to run your app in (either `development` or `production`).
3836
* `SECRET_KEY`: Randomly generated string of characters used to encrypt your app's data.
37+
* `FLASK_DEBUG`: Whether to run Flask in "debug" mode (either `True` or `False`).
3938

4039
*Remember never to commit secrets saved in .env files to Github.*
4140

42-
4341
-----
4442

4543
**Hackers and Slackers** tutorials are free of charge. If you found this tutorial helpful, a [small donation](https://www.buymeacoffee.com/hackersslackers) would be greatly appreciated to keep us in business. All proceeds go towards coffee, and all coffee goes towards more content.

config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class Config:
1212
"""Set Flask configuration vars from .env file."""
1313

1414
# General Config
15+
FLASK_APP = "wsgi.py"
16+
FLASK_DEBUG = environ.get("FLASK_DEBUG")
1517
SECRET_KEY = environ.get("SECRET_KEY")
16-
FLASK_APP = environ.get("FLASK_APP")
17-
FLASK_ENV = environ.get("FLASK_ENV")
1818

1919
# Static Assets
2020
STATIC_FOLDER = "static"

deploy.sh

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

flask_wtforms_tutorial/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ def create_app():
1111

1212
with app.app_context():
1313
# Import parts of our flask_wtforms_tutorial
14-
from . import routes
14+
from flask_wtforms_tutorial import routes
1515

1616
return app

flask_wtforms_tutorial/routes.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
from flask import current_app as app
33
from flask import redirect, render_template, url_for
44

5-
from .forms import ContactForm, SignupForm
5+
from flask_wtforms_tutorial.forms import ContactForm, SignupForm
66

77

88
@app.route("/")
99
def home():
1010
"""Landing page."""
11-
return render_template(
12-
"index.jinja2", template="home-template", title="Flask-WTF tutorial"
13-
)
11+
return render_template("index.jinja2", template="home-template", title="Flask-WTF tutorial")
1412

1513

1614
@app.route("/contact", methods=["GET", "POST"])
@@ -19,9 +17,7 @@ def contact():
1917
form = ContactForm()
2018
if form.validate_on_submit():
2119
return redirect(url_for("success"))
22-
return render_template(
23-
"contact.jinja2", form=form, template="form-template", title="Contact Form"
24-
)
20+
return render_template("contact.jinja2", form=form, template="form-template", title="Contact Form")
2521

2622

2723
@app.route("/signup", methods=["GET", "POST"])
@@ -30,9 +26,7 @@ def signup():
3026
form = SignupForm()
3127
if form.validate_on_submit():
3228
return redirect(url_for("success"))
33-
return render_template(
34-
"signup.jinja2", form=form, template="form-template", title="Signup Form"
35-
)
29+
return render_template("signup.jinja2", form=form, template="form-template", title="Signup Form")
3630

3731

3832
@app.route("/success", methods=["GET", "POST"])

0 commit comments

Comments
 (0)