Skip to content

Commit

Permalink
Merge pull request #65 from hackersandslackers/feature/python10-flask…
Browse files Browse the repository at this point in the history
…3-migration

Python v3.10 & Flask v3 Update
  • Loading branch information
toddbirchard authored Dec 17, 2023
2 parents 0eac4f4 + dc30f49 commit d8706c9
Show file tree
Hide file tree
Showing 29 changed files with 835 additions and 773 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FLASK_ENV=development
FLASK_APP=wsgi.py
FLASK_DEBUG=True
LESS_BIN=/usr/local/bin/lessc
SECRET_KEY="HGuitfI&uf6i7r&ujHFc"
FLASK_DEBUG=False
LESS_BIN="/Users/myuser/.nvm/versions/node/v18.18.1/bin/lessc"
34 changes: 34 additions & 0 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip" # caching pip dependencies

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ wheels/
.installed.cfg
*.egg
MANIFEST
dist/

# PyInstaller
# Usually these files are written by a python script from a static
Expand Down Expand Up @@ -107,4 +106,5 @@ venv.bak/
.DS_Store

# idea
.vscode
.idea
102 changes: 70 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,58 +1,96 @@
SRCPATH := $(CURDIR)
PROJECTNAME := $(shell basename $(CURDIR))
PROJECT_NAME := $(shell basename $CURDIR)
VIRTUAL_ENV := $(CURDIR)/.venv
LOCAL_PYTHON := $(VIRTUAL_ENV)/bin/python3

define HELP
Manage $(PROJECTNAME). Usage:
Manage $(PROJECT_NAME). Usage:

make run - Run $(PROJECT_NAME) locally.
make install - Create local virtualenv & install dependencies.
make deploy - Set up project & run locally.
make update - Update dependencies via Poetry and output resulting `requirements.txt`.
make format - Run Python code formatter & sort dependencies.
make lint - Check code formatting with flake8.
make clean - Remove extraneous compiled files, caches, logs, etc.

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

.PHONY: run deploy update format clean help


requirements: .requirements.txt


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

.PHONY: run install deploy update format lint clean help

all help:
@echo "$$HELP"

env: $(VIRTUAL_ENV)

$(VIRTUAL_ENV):
if [ ! -d $(VIRTUAL_ENV) ]; then \
echo "Creating Python virtual env in \`${VIRTUAL_ENV}\`"; \
python3 -m venv $(VIRTUAL_ENV); \
fi

.PHONY: run
run:
$(shell . .venv/bin/activate && python3 wsgi.py)
run: env
$(LOCAL_PYTHON) -m gunicorn -w 4 wsgi:app

.PHONY: install
install: env
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
npm i -g less && \
echo Installed dependencies in \`${VIRTUAL_ENV}\`;

.PHONY: deploy
deploy:
$(shell . ./deploy.sh)
make install && \
make run

.PHONY: test
test: env
$(LOCAL_PYTHON) -m \
coverage run -m pytest -vv \
--disable-pytest-warnings && \
coverage html --title='Coverage Report' -d .reports && \
open .reports/index.html

.PHONY: update
update:
poetry shell && poetry update
pip freeze > requirements.txt
exit

update: env
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
poetry update && \
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
echo Installed dependencies in \`${VIRTUAL_ENV}\`;

.PHONY: format
format: requirements
$(shell . .venv/bin/activate)
$(shell isort -rc ./)
$(shell black ./)
format: env
$(LOCAL_PYTHON) -m isort --multi-line=3 . && \
$(LOCAL_PYTHON) -m black .

.PHONY: lint
lint: env
$(LOCAL_PYTHON) -m flake8 . --count \
--select=E9,F63,F7,F82 \
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
--show-source \
--statistics


.PHONY: clean
clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete
find . -name 'poetry.lock' -delete
find . -name 'Pipefile.lock' -delete
find . -name '.coverage' -delete && \
find . -name '*.pyc' -delete && \
find . -name '__pycache__' -delete && \
find . -name 'poetry.lock' -delete && \
find . -name '*.log' -delete && \
find . -name '.DS_Store' -delete && \
find . -name 'Pipfile' -delete && \
find . -name 'Pipfile.lock' -delete && \
find . -wholename '**/*.pyc' -delete && \
find . -wholename '**/*.html' -delete && \
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
find . -type d -wholename '.venv' -exec rm -rf {} + && \
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + && \
find . -type d -wholename '**/*.log' -exec rm -rf {} + && \
find . -type d -wholename './.reports/*' -exec rm -rf {} + && \
find . -type d -wholename '**/.webassets-cache' -exec rm -rf {} +
17 changes: 0 additions & 17 deletions Pipfile

This file was deleted.

160 changes: 0 additions & 160 deletions Pipfile.lock

This file was deleted.

Loading

0 comments on commit d8706c9

Please sign in to comment.