1+ PROJECT_NAME := $(shell basename $CURDIR)
2+ VIRTUAL_ENV := $(CURDIR ) /.venv
3+ LOCAL_PYTHON := $(VIRTUAL_ENV ) /bin/python3
4+
5+ define HELP
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.
15+
16+ endef
17+ export HELP
18+
19+
20+ .PHONY : run install deploy update format lint clean help
21+
22+ all help :
23+ @echo " $$ HELP"
24+
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
32+ poetry config virtualenvs.path $(VIRTUAL_ENV )
33+
34+ .PHONY : run
35+ run : env
36+ $(LOCAL_PYTHON ) -m main
37+
38+ .PHONY : install
39+ install : env
40+ $(shell . $(VIRTUAL_ENV ) /bin/activate)
41+ $(LOCAL_PYTHON ) -m pip install --upgrade pip setuptools wheel && \
42+ poetry install --with dev --sync
43+ echo Installed dependencies in \` ${VIRTUAL_ENV} \` ;
44+
45+ .PHONY : deploy
46+ deploy :
47+ make install && \
48+ make run
49+
50+ .PHONY : update
51+ update : env
52+ $(LOCAL_PYTHON ) -m pip install --upgrade pip setuptools wheel && \
53+ poetry update --with dev && \
54+ poetry export -f requirements.txt --output requirements.txt --without-hashes && \
55+ echo Installed dependencies in \` ${VIRTUAL_ENV} \` ;
56+
57+ .PHONY : format
58+ format : env
59+ $(LOCAL_PYTHON ) -m isort --multi-line=3 . && \
60+ $(LOCAL_PYTHON ) -m black .
61+
62+ .PHONY : lint
63+ lint : env
64+ $(LOCAL_PYTHON ) -m flake8 . --count \
65+ --select=E9,F63,F7,F82 \
66+ --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
67+ --show-source \
68+ --statistics
69+
70+ .PHONY : clean
71+ clean :
72+ find . -name ' poetry.lock' -delete && \
73+ find . -name ' .coverage' -delete && \
74+ find . -name ' .Pipfile.lock' -delete && \
75+ find . -wholename ' **/*.pyc' -delete && \
76+ find . -type d -wholename ' __pycache__' -exec rm -rf {} + && \
77+ find . -type d -wholename ' ./.venv' -exec rm -rf {} + && \
78+ find . -type d -wholename ' .pytest_cache' -exec rm -rf {} + && \
79+ find . -type d -wholename ' **/.pytest_cache' -exec rm -rf {} + && \
80+ find . -type d -wholename ' ./logs/*.log' -exec rm -rf {} + && \
81+ find . -type d -wholename ' ./.reports/*' -exec rm -rf {} +
0 commit comments