-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (96 loc) · 3.59 KB
/
Makefile
File metadata and controls
122 lines (96 loc) · 3.59 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
# Set this to ~use it everywhere in the project setup
PYTHON_VERSION ?= 3.8.10
# the directories containing the library modules this repo builds
LIBRARY_DIRS = mylibrary
# build artifacts organized in this Makefile
BUILD_DIR ?= build
# PyTest options
PYTEST_HTML_OPTIONS = --html=$(BUILD_DIR)/report.html --self-contained-html
PYTEST_TAP_OPTIONS = --tap-combined --tap-outdir $(BUILD_DIR)
PYTEST_COVERAGE_OPTIONS = --cov=$(LIBRARY_DIRS)
PYTEST_OPTIONS ?= $(PYTEST_HTML_OPTIONS) $(PYTEST_TAP_OPTIONS) $(PYTEST_COVERAGE_OPTIONS)
# MyPy typechecking options
MYPY_OPTS ?= --python-version $(basename $(PYTHON_VERSION)) --show-column-numbers --pretty --html-report $(BUILD_DIR)/mypy
# Python installation artifacts
PYTHON_VERSION_FILE=.python-version
ifeq ($(shell which pyenv),)
# pyenv isn't installed, guess the eventual path FWIW
PYENV_VERSION_DIR ?= $(HOME)/.pyenv/versions/$(PYTHON_VERSION)
else
# pyenv is installed
PYENV_VERSION_DIR ?= $(shell pyenv root)/versions/$(PYTHON_VERSION)
endif
PIP ?= pip3
POETRY_OPTS ?=
POETRY ?= poetry $(POETRY_OPTS)
RUN_PYPKG_BIN = $(POETRY) run
COLOR_ORANGE = \033[33m
COLOR_RESET = \033[0m
##@ Utility
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: version-python
version-python: ## Echos the version of Python in use
@echo $(PYTHON_VERSION)
##@ Testing
.PHONY: test
test: ## Runs tests
$(RUN_PYPKG_BIN) pytest \
$(PYTEST_OPTIONS) \
tests/*.py
##@ Building and Publishing
.PHONY: build
build: ## Runs a build
$(POETRY) build
.PHONY: publish
publish: ## Publish a build to the configured repo
$(POETRY) publish $(POETRY_PUBLISH_OPTIONS_SET_BY_CI_ENV)
.PHONY: deps-py-update
deps-py-update: pyproject.toml ## Update Poetry deps, e.g. after adding a new one manually
$(POETRY) update
##@ Setup
# dynamic-ish detection of Python installation directory with pyenv
$(PYENV_VERSION_DIR):
pyenv install --skip-existing $(PYTHON_VERSION)
$(PYTHON_VERSION_FILE): $(PYENV_VERSION_DIR)
pyenv local $(PYTHON_VERSION)
.PHONY: deps
deps: deps-brew deps-py ## Installs all dependencies
.PHONY: deps-brew
deps-brew: Brewfile ## Installs development dependencies from Homebrew
brew bundle --file=Brewfile
@echo "$(COLOR_ORANGE)Ensure that pyenv is setup in your shell.$(COLOR_RESET)"
@echo "$(COLOR_ORANGE)It should have something like 'eval \$$(pyenv init -)'$(COLOR_RESET)"
.PHONY: deps-py
deps-py: $(PYTHON_VERSION_FILE) ## Installs Python development and runtime dependencies
$(PIP) install --upgrade \
--index-url $(PYPI_PROXY) \
pip
$(PIP) install --upgrade \
--index-url $(PYPI_PROXY) \
poetry
$(POETRY) install
##@ Code Quality
.PHONY: check
check: check-py ## Runs linters and other important tools
.PHONY: check-py
check-py: check-py-flake8 check-py-black check-py-mypy ## Checks only Python files
.PHONY: check-py-flake8
check-py-flake8: ## Runs flake8 linter
$(RUN_PYPKG_BIN) flake8 .
.PHONY: check-py-black
check-py-black: ## Runs black in check mode (no changes)
$(RUN_PYPKG_BIN) black --check --line-length 118 --fast .
.PHONY: check-py-mypy
check-py-mypy: ## Runs mypy
$(RUN_PYPKG_BIN) mypy $(MYPY_OPTS) $(LIBRARY_DIRS)
.PHONY: format-py
format-py: ## Runs black, makes changes where necessary
$(RUN_PYPKG_BIN) black .
.PHONY: format-autopep8
format-autopep8:
$(RUN_PYPKG_BIN) autopep8 --in-place --recursive .
.PHONY: format-isort
format-isort:
$(RUN_PYPKG_BIN) isort --recursive .