1
1
PROJECT_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
4
4
5
5
define HELP
6
6
Manage $(PROJECT_NAME ) . Usage:
7
7
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 .
15
15
16
16
endef
17
17
export HELP
18
18
19
19
20
20
.PHONY : run install deploy update format lint clean help
21
21
22
- requirements : .requirements.txt
23
- env : ./.venv/bin/activate
24
-
25
-
26
- .requirements.txt : requirements.txt
27
- $(shell . .venv/bin/activate && pip install -r requirements.txt)
28
-
29
-
30
22
all help :
31
23
@echo " $$ HELP"
32
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
33
32
34
33
.PHONY : run
35
34
run : env
36
- flask run
37
-
35
+ $(LOCAL_PYTHON ) -m main
38
36
39
37
.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
45
-
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} \` ;
46
43
47
44
.PHONY : deploy
48
45
deploy :
49
- make install
46
+ make install && \
50
47
make run
51
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
52
56
53
57
.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
59
-
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} \` ;
60
63
61
64
.PHONY : format
62
65
format : env
63
- isort --multi-line=3 .
64
- black .
65
-
66
+ $(LOCAL_PYTHON ) -m isort --multi-line=3 . && \
67
+ $(LOCAL_PYTHON ) -m black .
66
68
67
69
.PHONY : lint
68
- lint :
69
- flake8 . --count \
70
+ lint : env
71
+ $( LOCAL_PYTHON ) -m flake8 . --count \
70
72
--select=E9,F63,F7,F82 \
71
- --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs \
73
+ --exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
72
74
--show-source \
73
75
--statistics
74
76
75
-
76
77
.PHONY : clean
77
78
clean :
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
79
+ find . -name ' .coverage' -delete && \
80
+ find . -name ' *.pyc' -delete \
81
+ find . -name ' __pycache__' -delete \
82
+ find . -name ' poetry.lock' -delete \
83
+ find . -name ' *.log' -delete \
84
+ find . -name ' .DS_Store' -delete \
85
+ find . -wholename ' **/*.pyc' -delete && \
86
+ find . -wholename ' **/*.html' -delete && \
87
+ find . -type d -wholename ' __pycache__' -exec rm -rf {} + && \
88
+ find . -type d -wholename ' .venv' -exec rm -rf {} + && \
89
+ find . -type d -wholename ' .pytest_cache' -exec rm -rf {} + && \
90
+ find . -type d -wholename ' **/.pytest_cache' -exec rm -rf {} + && \
91
+ find . -type d -wholename ' **/*.log' -exec rm -rf {} + && \
92
+ find . -type d -wholename ' ./.reports/*' -exec rm -rf {} + && \
93
+ find . -type d -wholename ' **/.webassets-cache' -exec rm -rf {} +
0 commit comments