-
Notifications
You must be signed in to change notification settings - Fork 31
/
Makefile
116 lines (90 loc) · 3.4 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Makefile for giftless
PACKAGE_NAME := giftless
PACKAGE_DIRS := giftless
TESTS_DIR := tests
SHELL := bash
PYTHON := python
PIP := pip
PIP_COMPILE := pip-compile
PYTEST := pytest
DOCKER := docker
GIT := git
DOCKER_HOST := docker.io
DOCKER_REPO := datopian
DOCKER_IMAGE_NAME := giftless
DOCKER_IMAGE_TAG := latest
DOCKER_CACHE_FROM := docker.io/datopian/giftless:latest
PYTEST_EXTRA_ARGS :=
SOURCE_FILES := $(shell find $(PACKAGE_DIRS) $(TESTS_DIR) -type f -name "*.py")
SENTINELS := .make-cache
DIST_DIR := dist
PYVER := $(shell $(PYTHON) -c "import sys;print(f'{sys.version_info[0]}{sys.version_info[1]}')")
VERSION := $(shell $(PYTHON) -c "from importlib.metadata import version;print(version('$(PACKAGE_NAME)'))")
default: help
## Regenerate requirements files
requirements: requirements/dev.txt requirements/dev.in requirements/main.txt requirements/main.in
## Set up the development environment
dev-setup: $(SENTINELS)/dev-setup
## Run all linting checks
lint: $(SENTINELS)
pre-commit run --all-files
## Run all tests
test: $(SENTINELS)
$(PYTEST) $(PYTEST_EXTRA_ARGS) $(PACKAGE_DIRS) $(TESTS_DIR)
## Build a local Docker image
docker: requirements/main.txt
$(DOCKER) build --cache-from "$(DOCKER_CACHE_FROM)" -t $(DOCKER_HOST)/$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG) .
## Tag and push a release (disabled; done via GitHub Actions now)
release:
@echo "Package '$(PACKAGE_NAME)' releases are managed via GitHub"
## Clean all generated files
distclean:
rm -rf $(BUILD_DIR) $(DIST_DIR)
rm -rf $(SENTINELS)/dist
## Create distribution files to upload to pypi
dist: $(SENTINELS)/dist
## Build project documentation HTML files
docs-html:
@cd docs && $(MAKE) html
.PHONY: test docker release dist distclean requirements docs-html init
requirements/main.txt: requirements/main.in
$(PIP_COMPILE) --no-emit-index-url -o requirements/main.txt requirements/main.in
requirements/dev.txt: requirements/dev.in requirements/main.txt
$(PIP_COMPILE) --no-emit-index-url -o requirements/dev.txt requirements/dev.in
$(DIST_DIR)/$(PACKAGE_NAME)-$(VERSION).tar.gz $(DIST_DIR)/$(PACKAGE_NAME)-$(VERSION)-py3-none-any.whl: $(SOURCE_FILES) README.md | $(SENTINELS)/dist-setup
$(PYTHON) -m build
$(SENTINELS):
mkdir $@
$(SENTINELS)/dist-setup: | $(SENTINELS)
$(PIP) install -U wheel twine
@touch $@
$(SENTINELS)/dist: $(SENTINELS)/dist-setup $(DIST_DIR)/$(PACKAGE_NAME)-$(VERSION).tar.gz $(DIST_DIR)/$(PACKAGE_NAME)-$(VERSION)-py3-none-any.whl | $(SENTINELS)
@touch $@
$(SENTINELS)/dev-setup: init requirements/main.txt requirements/dev.txt | $(SENTINELS)
$(PIP) install -U pip pip-tools pre-commit tox
$(PIP) install -r requirements/main.txt
$(PIP) install -e .
$(PIP) install -r requirements/dev.txt
@touch $@
# Help related variables and targets
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM := 20
## Show help
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)