-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
80 lines (65 loc) · 2.33 KB
/
Makefile
File metadata and controls
80 lines (65 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
PROJECT_NAME := $(shell basename $CURDIR)
VIRTUAL_ENVIRONMENT := $(CURDIR)/.venv
LOCAL_PYTHON := $(VIRTUAL_ENVIRONMENT)/bin/python3
LOCAL_PYTHON_ACTIVATE := $(VIRTUAL_ENVIRONMENT)/bin/activate
define HELP
Manage $(PROJECT_NAME). Usage:
make run - Run $(PROJECT_NAME) locally.
make install - Create local virtualenv & install dependencies.
make update - Update dependencies via Poetry and output resulting `requirements.txt`.
make format - Run Python code formatter & sort dependencies.
make lint - Check code formatting with flake8.
make clean - Remove extraneous compiled files, caches, logs, etc.
endef
export HELP
.PHONY: run install update format lint clean help
all help:
@echo "$$HELP"
env: $(VIRTUAL_ENVIRONMENT)
$(VIRTUAL_ENVIRONMENT):
if [ ! -d $(VIRTUAL_ENVIRONMENT) ]; then \
echo "Creating Python virtual environment..."; \
python3 -m venv $(VIRTUAL_ENVIRONMENT); \
fi
.PHONY: run
run: env
$(LOCAL_PYTHON) -m example
.PHONY: install
install: env
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
$(LOCAL_PYTHON) -m pip install -r requirements.txt && \
echo "Installed dependencies in virtualenv \`${VIRTUAL_ENVIRONMENT}\`";
.PHONY: test
test: env
$(LOCAL_PYTHON) -m \
coverage run -m pytest -v \
--disable-pytest-warnings && \
coverage html --title='Coverage Report' -d .reports && \
open .reports/index.html
.PHONY: update
update: env
$(LOCAL_PYTHON) -m pip install --upgrade pip setuptools wheel && \
poetry update && \
poetry export -f requirements.txt --output requirements.txt --without-hashes && \
echo "Updated dependencies in virtualenv \`${VIRTUAL_ENVIRONMENT}\`";
.PHONY: format
format: env
source $(LOCAL_PYTHON_ACTIVATE) \
isort --multi-line=3 . \
&& black .
.PHONY: lint
lint: env
$(LOCAL_PYTHON) -m flake8 . --count \
--select=E9,F63,F7,F82 \
--exclude .git,.github,__pycache__,.pytest_cache,.venv,logs,creds,.venv,docs,logs,.reports \
--show-source \
--statistics
.PHONY: clean
clean:
find . -name 'poetry.lock' -delete && \
find . -name '.coverage' -delete && \
find . -wholename '**/*.pyc' -delete && \
find . -type d -wholename '__pycache__' -exec rm -rf {} + && \
find . -type d -wholename '.venv' -exec rm -rf {} + && \
find . -type d -wholename '.pytest_cache' -exec rm -rf {} + && \
find . -type d -wholename '**/.pytest_cache' -exec rm -rf {} + &&