-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (61 loc) · 2.45 KB
/
Makefile
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
.PHONY:clean venv test coverage lint format deploy
all:clean test coverage lint
MIN_TEST_COVERAGE=70
INITIAL_PYTHON?=python3
VENV_DIR?=.venv
LIBRARY=genweb
VENV_PYTHON?=$(VENV_DIR)/bin/python
VENV_PIP?=$(VENV_DIR)/bin/pip
SET_ENV?=. $(VENV_DIR)/bin/activate
SOURCES=$(shell find $(LIBRARY) -type f -iname "*.py")
TESTS=$(shell find tests -type f -iname "test_*.py")
FORMAT_FILE=$(VENV_DIR)/format.txt
LINT_FILE=$(VENV_DIR)/lint.txt
COVERAGE_FILE=.coverage
DEPLOY_FILE=$(VENV_DIR)/deploy.txt
PROJECT_FILE=pyproject.toml
SLEEP_TIME_IN_SECONDS=1
TEST_SERVER_TEST_DIR=test_published
PROD_SERVER_TEST_DIR=prod_published
BUILD_LOG=$(VENV_DIR)/build_log.txt
PIP_INSTALL=$(VENV_PIP) install --quiet --upgrade
PIP_INSTALL_TEST=pip install --no-cache-dir --quiet
SETTINGS_TOOL=devopsdriver.manage_settings
$(VENV_DIR)/touchfile: $(PROJECT_FILE)
@test -d $(VENV_DIR) || $(INITIAL_PYTHON) -m venv $(VENV_DIR)
@echo Ensuring pip is latest version
@$(SET_ENV); $(PIP_INSTALL) pip
@echo Fetching requirements
@$(SET_ENV); $(PIP_INSTALL) .
@touch $@
venv: $(VENV_DIR)/touchfile
$(COVERAGE_FILE): $(VENV_DIR)/touchfile $(SOURCES) $(TESTS)
@$(SET_ENV); $(PIP_INSTALL) ".[test]"
@$(SET_ENV); $(VENV_PYTHON) -m coverage run --source $(LIBRARY) -m pytest
test: $(COVERAGE_FILE)
coverage: $(COVERAGE_FILE)
@$(SET_ENV); $(VENV_PYTHON) -m coverage report -m --sort=cover --skip-covered --fail-under=$(MIN_TEST_COVERAGE)
@if grep --quiet "test+coverage&message=$(MIN_TEST_COVERAGE)%" README.md; then true; else echo "Update README.md test coverage" && false; fi
$(FORMAT_FILE): $(VENV_DIR)/touchfile $(SOURCES)
@$(SET_ENV); $(PIP_INSTALL) ".[dev]"
@$(SET_ENV); $(VENV_PYTHON) -m black $(LIBRARY) &> $@
format: $(FORMAT_FILE)
@cat $^
@perl -i -pe's/test\+coverage\&message=..%/test\+coverage\&message=$(MIN_TEST_COVERAGE)%/g' README.md
$(LINT_FILE): $(VENV_DIR)/touchfile $(SOURCES)
@$(SET_ENV); $(PIP_INSTALL) ".[dev]"
-@$(SET_ENV); $(VENV_PYTHON) -m pylint --disable cyclic-import $(LIBRARY) --output $@
-@$(SET_ENV); $(VENV_PYTHON) -m black $(LIBRARY) --check >> $@ 2>&1
lint: $(LINT_FILE)
@cat $^
@if grep --quiet "would be reformatted" $^; then echo "black failure!" && false; else true; fi
@if grep --quiet "rated at 10.00/10" $^; then true; else echo "pylint failure!" && false; fi
clean:
@rm -Rf $(VENV_DIR)
@rm -f $(strip $(COVERAGE_FILE))*
@rm -Rf `find . -type d -name __pycache__`
@rm -Rf .pytest_cache
@rm -Rf dist
@rm -Rf build
@rm -Rf *.egg-info
@find . -iname "*.pyc" -delete