11PROJECT_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
55define HELP
66Manage $(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
1616endef
1717export 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
3538run : env
36- flask run
39+ uwsgi --http 127.0.0.1:8081 --master --module wsgi:app --processes 4 --threads 2
3740
3841
3942.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
43+ install : env
44+ $( LOCAL_PYTHON ) -m pip install --upgrade pip setuptools wheel && \
45+ $( LOCAL_PYTHON ) -m pip install --no-cache-dir uwsgi && \
46+ $(LOCAL_PYTHON ) -m pip install -r requirements.txt && \
47+ echo Installed dependencies in \` ${VIRTUAL_ENV} \` ;
4548
4649
4750.PHONY : deploy
@@ -50,40 +53,53 @@ deploy:
5053 make run
5154
5255
56+ .PHONY : test
57+ test : env
58+ $(LOCAL_PYTHON ) -m \
59+ coverage run -m pytest -vv \
60+ --disable-pytest-warnings && \
61+ coverage html --title=' Coverage Report' -d .reports && \
62+ open .reports/index.html
63+
64+
5365.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
66+ update : env
67+ $( LOCAL_PYTHON ) -m pip install --upgrade pip setuptools wheel && \
68+ poetry update && \
69+ poetry export -f requirements.txt --output requirements.txt --without-hashes && \
70+ echo Installed dependencies in \` ${VIRTUAL_ENV} \` ;
5971
6072
6173.PHONY : format
6274format : env
63- isort --multi-line=3 .
64- black .
75+ $( LOCAL_PYTHON ) -m isort --multi-line=3 .
76+ $( LOCAL_PYTHON ) -m black .
6577
6678
6779.PHONY : lint
68- lint :
69- flake8 . --count \
80+ lint : env
81+ $( LOCAL_PYTHON ) -m flake8 . --count \
7082 --select=E9,F63,F7,F82 \
71- --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
83+ --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
7284 --show-source \
7385 --statistics
7486
7587
7688.PHONY : clean
7789clean :
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
90+ find . -name ' poetry.lock' -delete && \
91+ find . -name ' .coverage' -delete && \
92+ find . -name ' *.pyc' -delete \
93+ find . -name ' __pycache__' -delete \
94+ find . -name ' poetry.lock' -delete \
95+ find . -name ' *.log' -delete \
96+ find . -name ' .DS_Store' -delete \
97+ find . -wholename ' **/*.pyc' -delete && \
98+ find . -wholename ' *.html' -delete && \
99+ find . -type d -wholename ' __pycache__' -exec rm -rf {} + && \
100+ find . -type d -wholename ' .venv' -exec rm -rf {} + && \
101+ find . -type d -wholename ' .pytest_cache' -exec rm -rf {} + && \
102+ find . -type d -wholename ' **/.pytest_cache' -exec rm -rf {} + && \
103+ find . -type d -wholename ' ./logs/*' -exec rm -rf {} + && \
104+ find . -type d -wholename ' ./.reports/*' -exec rm -rf {} + && \
105+ find . -type d -wholename ' **/.webassets-cache' -exec rm -rf {} +
0 commit comments