Skip to content

Commit d8706c9

Browse files
authored
Merge pull request #65 from hackersandslackers/feature/python10-flask3-migration
Python v3.10 & Flask v3 Update
2 parents 0eac4f4 + dc30f49 commit d8706c9

29 files changed

+835
-773
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
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"

.github/workflows/pythonapp.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.10"
21+
cache: "pip" # caching pip dependencies
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install flake8 pytest
27+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28+
29+
- name: Lint with flake8
30+
run: |
31+
# stop the build if there are Python syntax errors or undefined names
32+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
34+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

.gitignore

Lines changed: 1 addition & 1 deletion
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

Lines changed: 70 additions & 32 deletions
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

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

Pipfile.lock

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

0 commit comments

Comments
 (0)