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
3
4
4
5
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.
6
15
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.
12
16
endef
13
17
export HELP
14
18
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)
23
19
20
+ .PHONY : run install deploy update format lint clean help
24
21
25
22
all help :
26
23
@echo " $$ HELP"
27
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
28
32
29
33
.PHONY : run
30
- run :
31
- $(shell . .venv/bin/activate && python3 wsgi.py)
34
+ run : env
35
+ $(LOCAL_PYTHON ) -m gunicorn -w 4 wsgi:app
32
36
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} \` ;
33
43
34
44
.PHONY : deploy
35
45
deploy :
36
- $(shell . ./deploy.sh)
46
+ make install && \
47
+ make run
37
48
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
38
56
39
57
.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} \` ;
45
63
46
64
.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
51
76
52
77
53
78
.PHONY : clean
54
79
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 {} +
0 commit comments