-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (91 loc) · 3.6 KB
/
Makefile
File metadata and controls
133 lines (91 loc) · 3.6 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
SHELL = /bin/bash
.DEFAULT_GOAL := help
CURRENT_DIR := $(shell pwd)
# Test reports configuration
TEST_REPORT_DIR ?= $(CURRENT_DIR)/tests/report
TEST_REPORT_FILE ?= nose2-junit.xml
# general targets timestamps
TIMESTAMPS = .timestamps
REQUIREMENTS := $(TIMESTAMPS) $(PIP_FILE) $(PIP_FILE_LOCK)
# Find all python files that are not inside a hidden directory (directory starting with .)
PYTHON_FILES := $(shell find ./* -type d \( -path ./build -o -path ./dist \) -prune -false -o -type f -name "*.py" -print)
# PIPENV files
PIP_FILE = Pipfile
PIP_FILE_LOCK = Pipfile.lock
# default configuration
ENV_FILE ?= .env.local
# Commands
PIPENV_RUN := pipenv run
PYTHON := $(PIPENV_RUN) python3
PIP := $(PIPENV_RUN) pip3
YAPF := $(PIPENV_RUN) yapf
ISORT := $(PIPENV_RUN) isort
NOSE := $(PIPENV_RUN) nose2
PYLINT := $(PIPENV_RUN) pylint
PACKAGE_VERSION = $(shell awk '/^Version:/ {print $$2}' gatilegrid.egg-info/PKG-INFO)
# Build targets. Calling setup is all that is needed for the local files to be installed as needed.
.PHONY: setup
setup: $(REQUIREMENTS) ## Create the python virtual environment with developper tools
pipenv install --dev
# linting target, calls upon yapf to make sure your code is easier to read and respects some conventions.
.PHONY: format
format: $(REQUIREMENTS) ## Format the python source code
$(YAPF) -p -i --style .style.yapf $(PYTHON_FILES)
$(ISORT) $(PYTHON_FILES)
.PHONY: ci-check-format
ci-check-format: format ## Check if formatting python source code is required
@if [[ -n `git status --porcelain` ]]; then \
>&2 echo "ERROR: the following files are not formatted correctly:"; \
>&2 git status --porcelain; \
exit 1; \
fi
.PHONY: lint
lint: $(REQUIREMENTS) ## Lint the python source code
$(PYLINT) $(PYTHON_FILES)
.PHONY: format-lint
format-lint: format lint ## Format and lint the python source code
# Test target
.PHONY: test
test: $(DEV_REQUIREMENTS_TIMESTAMP) ## Run the tests
mkdir -p $(TEST_REPORT_DIR)
$(NOSE) -v -c tests/unittest.cfg --junit-xml-path $(TEST_REPORT_DIR)/$(TEST_REPORT_FILE) -s tests/
# Packaging target
.PHONY: package
package: $(DEV_REQUIREMENTS_TIMESTAMP) ## Create package
$(PYTHON) -m build
.PHONY: publish
publish: publish-check package ## Tag and publish package to PyPI
@echo "Upload package version=$(PACKAGE_VERSION)"
$(PYTHON) -m twine upload dist/*
# Clean targets
.PHONY: clean-venv
clean-venv: ## Clean python venv
pipenv --rm
.PHONY: clean
clean: clean-venv ## Clean generated files
@# clean python cache files
find . -name __pycache__ -type d -print0 | xargs -I {} -0 rm -rf "{}"
rm -rf $(TEST_REPORT_DIR)
rm -rf $(TIMESTAMPS)
rm -rf dist
rm -rf build
rm -rf *.egg-info
rm -f .coverage
.PHONY: clean-all
clean-all: clean ## Clean everything
# Actual builds targets with dependencies
$(TIMESTAMPS):
mkdir -p $(TIMESTAMPS)
$(VENV_TIMESTAMP):
test -d $(VENV) || $(SYSTEM_PYTHON) -m venv $(VENV) && $(PIP) install --upgrade pip setuptools
@touch $(VENV_TIMESTAMP)
$(DEV_REQUIREMENTS_TIMESTAMP): $(VENV_TIMESTAMP) $(DEV_REQUIREMENTS)
$(PIP) install -r $(DEV_REQUIREMENTS)
@touch $(DEV_REQUIREMENTS_TIMESTAMP)
publish-check: ## Check if publish is allowed
@if [ -n "`git status --porcelain`" ]; then echo "ERROR: Repo is dirty !" >&2; exit 1; fi
.PHONY: help
help: ## Display this help
# automatically generate the help page based on the documentation after each make target
# from https://gist.github.com/prwhite/8168133
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)