Skip to content

Commit bbbe7e1

Browse files
committed
Update dependencies & Make commands for Apple silicon.
1 parent 19aa5a1 commit bbbe7e1

File tree

12 files changed

+134
-1060
lines changed

12 files changed

+134
-1060
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
ENVIRONMENT=development
12
FLASK_APP=wsgi.py
2-
FLASK_ENV=production
3+
FLASK_DEBUG=True
34
SECRET_KEY=yoursecretkey
45
SQLALCHEMY_DATABASE_URI=mysql+pymysql://myuser:mypassword@host.example.com:1234/mydatabase
56
REDIS_URI=redis://:password@host.com:1234
67
COMPRESSOR_DEBUG=True
7-
LESS_BIN=/usr/local/bin/lessc
88
ASSETS_DEBUG=False
99
LESS_RUN_IN_DEBUG=False

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ venv.bak/
9999
# mkdocs documentation
100100
/site
101101

102-
# mypy
102+
# MyPy
103103
.mypy_cache/
104104

105+
# IDEs
106+
.idea
107+
.vscode
108+
105109
# Etc
106110
.DS_Store
107-
creds
108-
.idea
109-
.idea/*

Makefile

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
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
2422

23+
all help:
24+
@echo "$$HELP"
2525

26-
.requirements.txt: requirements.txt
27-
$(shell . .venv/bin/activate && pip install -r requirements.txt)
2826

27+
env: $(VIRTUAL_ENV)
2928

30-
all help:
31-
@echo "$$HELP"
29+
30+
$(VIRTUAL_ENV):
31+
if [ ! -d $(VIRTUAL_ENV) ]; then \
32+
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
33+
python3 -m venv $(VIRTUAL_ENV); \
34+
fi
3235

3336

3437
.PHONY: run
3538
run: env
36-
flask run
39+
export LESS_BIN=$(shell which lessc)
40+
uwsgi --http 127.0.0.1:8082 --master --module wsgi:app --processes 4 --threads 2
3741

3842

3943
.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
44+
install: env
45+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
46+
$(LOCAL_PYTHON) -m pip install --no-cache-dir uwsgi && \
47+
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
48+
npm i -g less && \
49+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
4550

4651

4752
.PHONY: deploy
@@ -50,40 +55,55 @@ deploy:
5055
make run
5156

5257

58+
.PHONY: test
59+
test: env
60+
$(LOCAL_PYTHON) -m \
61+
coverage run -m pytest -vv \
62+
--disable-pytest-warnings && \
63+
coverage html --title='Coverage Report' -d .reports && \
64+
open .reports/index.html
65+
66+
5367
.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
68+
update: env
69+
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
70+
$(LOCAL_PYTHON) -m pip install --no-cache-dir uwsgi && \
71+
poetry update && \
72+
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
73+
echo Installed dependencies in \`${VIRTUAL_ENV}\`;
5974

6075

6176
.PHONY: format
6277
format: env
63-
isort --multi-line=3 .
64-
black .
78+
$(LOCAL_PYTHON) -m isort --multi-line=3 .
79+
$(LOCAL_PYTHON) -m black .
6580

6681

6782
.PHONY: lint
68-
lint:
69-
flake8 . --count \
83+
lint: env
84+
$(LOCAL_PYTHON) -m flake8 . --count \
7085
--select=E9,F63,F7,F82 \
71-
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
86+
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
7287
--show-source \
7388
--statistics
7489

7590

7691
.PHONY: clean
7792
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
93+
find . -name 'poetry.lock' -delete && \
94+
find . -name '.coverage' -delete && \
95+
find . -name '*.pyc' -delete \
96+
find . -name '__pycache__' -delete \
97+
find . -name 'poetry.lock' -delete \
98+
find . -name '*.log' -delete \
99+
find . -name '.DS_Store' -delete \
100+
find . -wholename '**/*.pyc' -delete && \
101+
find . -wholename '*.html' -delete && \
102+
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
103+
find . -type d -wholename '.venv' -exec rm -rf {} + && \
104+
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
105+
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + && \
106+
find . -type d -wholename './logs/*' -exec rm -rf {} + && \
107+
find . -type d -wholename './.reports/*' -exec rm -rf {} + && \
108+
find . -type d -wholename '**/.webassets-cache' -exec rm -rf {} +
109+

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Flask-Session 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-v^2.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5-
![Flask-Login](https://img.shields.io/badge/Flask--Login-v0.6.0-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-v^3.9-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
4+
![Flask](https://img.shields.io/badge/Flask-v^2.2.2-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
5+
![Flask-Login](https://img.shields.io/badge/Flask--Login-v0.6.2-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
66
![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)
77
![Flask-Session](https://img.shields.io/badge/Flask--Session-v0.4.0-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
88
![Flask-SQLAlchemy](https://img.shields.io/badge/Flask--SQLAlchemy-v2.5.1-red.svg?longCache=true&style=flat-square&logo=flask&logoColor=white&colorA=4c566a&colorB=5e81ac)
@@ -18,7 +18,7 @@
1818

1919
**Tutorial**: https://hackersandslackers.com/managing-user-session-variables-with-flask-sessions-and-redis/
2020

21-
# Getting Started
21+
## Getting Started
2222

2323
Get set up locally in two steps:
2424

@@ -27,7 +27,7 @@ Get set up locally in two steps:
2727
Replace the values in **.env.example** with your values and rename this file to **.env**:
2828

2929
* `FLASK_APP`: Entry point of your application; should be `wsgi.py`.
30-
* `FLASK_ENV`: The environment in which to run your application; either `development` or `production`.
30+
* `FLASK_DEBUG`: Toggle debug mode on (`True`) or off (`False`).
3131
* `SECRET_KEY`: Randomly generated string of characters used to encrypt your app's data.
3232
* `SQLALCHEMY_DATABASE_URI`: Connection URI of a SQL database.
3333
* `SESSION_REDIS`: Connection URI of a Redis instance.
@@ -36,18 +36,17 @@ Replace the values in **.env.example** with your values and rename this file to
3636
* `LESS_RUN_IN_DEBUG` *(optional)*: Debug LESS while in `development`.
3737
* `COMPRESSOR_DEBUG` *(optional)*: Debug asset compression while in `development`.
3838

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

4241
### Installation
4342

4443
Get up and running with `make deploy`:
4544

4645
```shell
47-
$ git clone https://github.com/hackersandslackers/flask-session-tutorial.git
48-
$ cd flask-session-tutorial
49-
$ make deploy
50-
```
46+
git clone https://github.com/hackersandslackers/flask-session-tutorial.git
47+
cd flask-session-tutorial
48+
make deploy
49+
```
5150

5251
-----
5352

config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""App configuration."""
2-
from os import environ, path
2+
from os import environ, path, system
33

44
import redis
55
from dotenv import load_dotenv
@@ -12,8 +12,9 @@ class Config:
1212
"""Set Flask configuration variables from .env file."""
1313

1414
# General Config
15+
ENVIRONMENT = environ.get("ENVIRONMENT")
1516
FLASK_APP = environ.get("FLASK_APP")
16-
FLASK_ENV = environ.get("FLASK_ENV")
17+
FLASK_DEBUG = environ.get("FLASK_DEBUG")
1718
SECRET_KEY = environ.get("SECRET_KEY")
1819

1920
# Flask-Session
@@ -22,7 +23,7 @@ class Config:
2223
SESSION_REDIS = redis.from_url(REDIS_URI)
2324

2425
# Flask-Assets
25-
LESS_BIN = environ.get("LESS_BIN")
26+
LESS_BIN = system("which lessc")
2627
ASSETS_DEBUG = False
2728
LESS_RUN_IN_DEBUG = False
2829

deploy.sh

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

flask_session_tutorial/assets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def compile_auth_assets(app):
2020
assets.register("less_all", less_bundle)
2121
assets.register("js_all", js_bundle)
2222
# Build assets in development mode
23-
if app.config["FLASK_ENV"] != "production":
23+
if app.config.get("ENVIRONMENT") != "production":
2424
less_bundle.build(force=True)
2525
js_bundle.build()
2626

@@ -40,7 +40,7 @@ def compile_main_assets(app):
4040
# Register assets
4141
assets.register("less_all", less_bundle)
4242
# Build assets in development mode
43-
if app.config["FLASK_ENV"] != "production":
43+
if app.config.get("ENVIRONMENT") != "production":
4444
less_bundle.build(force=True)
4545

4646

0 commit comments

Comments
 (0)