Skip to content

Commit a8f2ba5

Browse files
committed
Update to Flask v3 & related dependencies.
1 parent 0eac4f4 commit a8f2ba5

28 files changed

+801
-773
lines changed

.env.example

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FLASK_ENV=development
2-
FLASK_APP=wsgi.py
3-
FLASK_DEBUG=True
4-
LESS_BIN=/usr/local/bin/lessc
2+
SECRET_KEY="HGuitfI&uf6i7r&ujHFc"
3+
FLASK_DEBUG=False
4+
LESS_BIN="/Users/myuser/.nvm/versions/node/v18.18.1/bin/lessc"

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ wheels/
2323
.installed.cfg
2424
*.egg
2525
MANIFEST
26-
dist/
2726

2827
# PyInstaller
2928
# Usually these files are written by a python script from a static
@@ -107,4 +106,5 @@ venv.bak/
107106
.DS_Store
108107

109108
# idea
109+
.vscode
110110
.idea

Makefile

+70-32
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,96 @@
1-
SRCPATH := $(CURDIR)
2-
PROJECTNAME := $(shell basename $(CURDIR))
1+
PROJECT_NAME := $(shell basename $CURDIR)
2+
VIRTUAL_ENV := $(CURDIR)/.venv
3+
LOCAL_PYTHON := $(VIRTUAL_ENV)/bin/python3
34

45
define HELP
5-
Manage $(PROJECTNAME). Usage:
6+
Manage $(PROJECT_NAME). Usage:
7+
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.
615

7-
make run - Run $(PROJECTNAME).
8-
make deploy - Install requirements and run app for the first time.
9-
make update - Update pip dependencies via Python Poetry.
10-
make format - Format code with Python's `Black` library.
11-
make clean - Remove cached files and lock files.
1216
endef
1317
export HELP
1418

15-
.PHONY: run deploy update format clean help
16-
17-
18-
requirements: .requirements.txt
19-
20-
21-
.requirements.txt: requirements.txt
22-
$(shell . .venv/bin/activate && pip install -r requirements.txt)
2319

20+
.PHONY: run install deploy update format lint clean help
2421

2522
all help:
2623
@echo "$$HELP"
2724

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
2832

2933
.PHONY: run
30-
run:
31-
$(shell . .venv/bin/activate && python3 wsgi.py)
34+
run: env
35+
$(LOCAL_PYTHON) -m gunicorn -w 4 wsgi:app
3236

37+
.PHONY: install
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}\`;
3343

3444
.PHONY: deploy
3545
deploy:
36-
$(shell . ./deploy.sh)
46+
make install && \
47+
make run
3748

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
3856

3957
.PHONY: update
40-
update:
41-
poetry shell && poetry update
42-
pip freeze > requirements.txt
43-
exit
44-
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}\`;
4563

4664
.PHONY: format
47-
format: requirements
48-
$(shell . .venv/bin/activate)
49-
$(shell isort -rc ./)
50-
$(shell black ./)
65+
format: env
66+
$(LOCAL_PYTHON) -m isort --multi-line=3 . && \
67+
$(LOCAL_PYTHON) -m black .
68+
69+
.PHONY: lint
70+
lint: env
71+
$(LOCAL_PYTHON) -m flake8 . --count \
72+
--select=E9,F63,F7,F82 \
73+
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
74+
--show-source \
75+
--statistics
5176

5277

5378
.PHONY: clean
5479
clean:
55-
find . -name '*.pyc' -delete
56-
find . -name '__pycache__' -delete
57-
find . -name 'poetry.lock' -delete
58-
find . -name 'Pipefile.lock' -delete
80+
find . -name '.coverage' -delete && \
81+
find . -name '*.pyc' -delete && \
82+
find . -name '__pycache__' -delete && \
83+
find . -name 'poetry.lock' -delete && \
84+
find . -name '*.log' -delete && \
85+
find . -name '.DS_Store' -delete && \
86+
find . -name 'Pipfile' -delete && \
87+
find . -name 'Pipfile.lock' -delete && \
88+
find . -wholename '**/*.pyc' -delete && \
89+
find . -wholename '**/*.html' -delete && \
90+
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
91+
find . -type d -wholename '.venv' -exec rm -rf {} + && \
92+
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
93+
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + && \
94+
find . -type d -wholename '**/*.log' -exec rm -rf {} + && \
95+
find . -type d -wholename './.reports/*' -exec rm -rf {} + && \
96+
find . -type d -wholename '**/.webassets-cache' -exec rm -rf {} +

Pipfile

-17
This file was deleted.

Pipfile.lock

-160
This file was deleted.

README.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
# Flask-Assets Tutorial
22

3-
![Python](https://img.shields.io/badge/Python-v3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4-
![Flask](https://img.shields.io/badge/Flask-v1.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5-
![Flask-Assets](https://img.shields.io/badge/Flask--Assets-v2.0-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-Assets](https://img.shields.io/badge/Flask--Assets-v2.1.0-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
6+
![Gunicorn](https://img.shields.io/badge/Gunicorn-v21.2.0-blue.svg?longCache=true&logo=gunicorn&style=flat-square&logoColor=white&colorB=a3be8c&colorA=4c566a)
67
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)
78
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-assets-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-assets-tutorial/issues)
89
[![GitHub Stars](https://img.shields.io/github/stars/hackersandslackers/flask-assets-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-assets-tutorial/stargazers)
910
[![GitHub Forks](https://img.shields.io/github/forks/hackersandslackers/flask-assets-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-assets-tutorial/network)
1011

1112
![Flask Assets Tutorial](https://github.com/hackersandslackers/flask-assets-tutorial/blob/master/.github/[email protected]?raw=true)
1213

13-
Build and code-split your frontend assets across Blueprints using Flask-Assets. Accompanying tutorial on Hackers and Slackers here: https://hackersandslackers.com/flask-assets/
14+
Build and code-split your frontend assets across Blueprints using Flask-Assets.
1415

15-
# Getting Started
16+
* **Tutorial**: [https://hackersandslackers.com/flask-assets/](https://hackersandslackers.com/flask-assets/)
17+
* **Demo**: [https://flaskassets.hackersandslackers.app/](https://flaskassets.hackersandslackers.app/)
18+
19+
## Getting Started
1620

1721
Get set up locally in two steps:
1822

1923
### Environment Variables
2024

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

23-
* `FLASK_APP`: Entry point of your application; should be `wsgi.py`.
24-
* `FLASK_ENV`: The environment in which run your application; either `development` or `production`.
27+
* `ENVIRONMENT`: The environment in which to run your application (either `development` or `production`).
28+
* `FLASK_DEBUG`: Set to `True` to enable Flask's debug mode (default to `False` in prod).
2529
* `SECRET_KEY`: Randomly generated string of characters used to encrypt your app's data.
2630
* `LESS_BIN`: Path to your local LESS installation via `which lessc`.
2731

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

3438
```shell
35-
$ git clone https://github.com/hackersandslackers/flask-assets-tutorial.git
36-
$ cd flask-assets-tutorial
37-
$ make deploy
38-
```
39+
git clone https://github.com/hackersandslackers/flask-assets-tutorial.git
40+
cd flask-assets-tutorial
41+
make deploy
42+
```
3943

4044
-----
4145

0 commit comments

Comments
 (0)