1- SRCPATH := $(shell pwd )
2- PROJECTNAME := $(shell basename $( CURDIR ))
3- ENTRYPOINT := $(PROJECTNAME ) .ini
1+ PROJECT_NAME := $(shell basename $CURDIR )
2+ VIRTUAL_ENV := $(CURDIR ) /.venv
3+ LOCAL_PYTHON := $(VIRTUAL_ENV ) /bin/python3
44
55define HELP
6- Manage $(PROJECTNAME ) . Usage:
7-
8- make run - Run $(PROJECTNAME ) .
9- make deploy - Pull latest build and deploy to production.
10- make update - Update pip dependencies via Python Poetry.
11- make format - Format code with Python's `Black` library.
12- make lint - Check code formatting with flake8
13- make clean - Remove cached files and lock files.
14- endef
15- export HELP
16-
6+ Manage $(PROJECT_NAME ) . Usage:
177
18- .PHONY : run restart deploy update format lint clean help
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.
1915
20- requirements : .requirements.txt
21- env : ./.venv/bin/activate
16+ endef
17+ export HELP
2218
23- .requirements.txt : requirements.txt
24- $(shell . .venv/bin/activate && pip install -r requirements.txt)
2519
20+ .PHONY : run install deploy update format lint clean help
2621
2722all help :
2823 @echo " $$ HELP"
2924
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+
33+ .PHONY : dev
34+ dev : env
35+ $(LOCAL_PYTHON ) -m main --reload
3036
3137.PHONY : run
3238run : env
33- python main.py
39+ $( LOCAL_PYTHON ) -m main
3440
41+ .PHONY : install
42+ install : env
43+ $(LOCAL_PYTHON ) -m pip install --upgrade pip setuptools wheel && \
44+ $(LOCAL_PYTHON ) -m pip install -r requirements.txt && \
45+ echo Installed dependencies in \` ${VIRTUAL_ENV} \` ;
3546
3647.PHONY : deploy
3748deploy :
38- make clean
39- $( shell . ./deploy.sh)
49+ make install && \
50+ make run
4051
52+ .PHONY : test
53+ test : env
54+ $(LOCAL_PYTHON ) -m \
55+ coverage run -m pytest -vv \
56+ --disable-pytest-warnings && \
57+ coverage html --title=' Coverage Report' -d .reports && \
58+ open .reports/index.html
4159
4260.PHONY : update
4361update : env
44- .venv/bin/python3 -m pip install --upgrade pip setuptools wheel
45- poetry update
46- poetry export -f requirements.txt --output requirements.txt --without-hashes
47-
62+ $( LOCAL_PYTHON ) -m pip install --upgrade pip setuptools wheel && \
63+ poetry update && \
64+ poetry export -f requirements.txt --output requirements.txt --without-hashes && \
65+ echo Installed dependencies in \` ${VIRTUAL_ENV} \` ;
4866
4967.PHONY : format
5068format : env
51- $(shell . .venv/bin/activate && isort ./)
52- $(shell . .venv/bin/activate && black ./)
53-
69+ $(LOCAL_PYTHON ) -m isort --multi-line=3 . && \
70+ $(LOCAL_PYTHON ) -m black .
5471
5572.PHONY : lint
56- lint :
57- flake8 . --count \
73+ lint : env
74+ $( LOCAL_PYTHON ) -m flake8 . --count \
5875 --select=E9,F63,F7,F82 \
59- --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
76+ --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
6077 --show-source \
6178 --statistics
6279
63-
6480.PHONY : clean
6581clean :
66- find . -name ' *.pyc' -delete
67- find . -name ' __pycache__' -delete
68- find . -name ' poetry.lock' -delete
69- find . -name ' Pipefile.lock' -delete
70- find . -name ' logs/*' -delete
71- find . -name ' .pytest_cache' -delete
82+ find . -name ' poetry.lock' -delete && \
83+ find . -name ' .coverage' -delete && \
84+ find . -name ' .Pipfile.lock' -delete && \
85+ find . -wholename ' **/*.pyc' -delete && \
86+ find . -type d -wholename ' __pycache__' -exec rm -rf {} + && \
87+ find . -type d -wholename ' ./.venv' -exec rm -rf {} + && \
88+ find . -type d -wholename ' .pytest_cache' -exec rm -rf {} + && \
89+ find . -type d -wholename ' **/.pytest_cache' -exec rm -rf {} + && \
90+ find . -type d -wholename ' ./logs/*.log' -exec rm -rf {} + && \
91+ find . -type d -wholename ' ./.reports/*' -exec rm -rf {} +
0 commit comments