-
Notifications
You must be signed in to change notification settings - Fork 6
/
makefile
167 lines (133 loc) · 4.17 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# See 'make help' for a list of useful targets
# ==================================================
# Constants
# ===================================================
PYTHON := python3
PIP := $(PYTHON) -m pip
BROWSER := firefox
DIR = .
DOCKER = sudo docker
DOCKER_IMG_NAME = btac
PRECOMMIT = pre-commit
MYPY = mypy
PYTEST = pytest
QUICK_TEST = $(PYTEST) -k "not test_9_API"
# set to ON/OFF to toggle ANSI escape sequences
COLOR = ON
# Uncomment to show commands
# VERBOSE = TRUE
# padding for help on targets
# should be > than the longest target
HELP_PADDING = 15
# ==================================================
# Make code and variable setting
# ==================================================
ifeq ($(COLOR),ON)
color_yellow = \033[93;1m
color_orange = \033[33m
color_red = \033[31m
color_green = \033[32m
color_blue = \033[34;1m
color_reset = \033[0m
endif
define print
@echo "$(color_yellow)$(1)$(color_reset)"
endef
# =================================================
# Default target
# =================================================
default: mypy
.PHONY: default
# =================================================
# Special Targets
# =================================================
# No display of executed commands.
$(VERBOSE).SILENT:
.PHONY: help
help: ## Show this help
@echo "$(color_yellow)make:$(color_reset) list of useful targets :"
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(color_blue)%-$(HELP_PADDING)s$(color_reset) %s\n", $$1, $$2}'
.PHONY: precommit
precommit: ## run precommit
$(call print,Running precommit)
$(PRECOMMIT) run
.PHONY: precommit-all
precommit-all: ## run precommit on all files
$(call print,Running precommit on all files)
$(PRECOMMIT) run --all-files
.PHONY: test
quick-test: ## Run local tests (perform no API queries)
$(call print,Running pytest (skip API query test))
$(QUICK_TEST)
.PHONY: test
test: ## Run all tests
$(call print,Running pytest on all test)
$(PYTEST) --cov
.PHONY: coverage
coverage: ## build html coverage and open in browser
$(call print,Building coverage report)
coverage html
$(BROWSER) htmlcov/index.html
.PHONY: mypy
mypy: ## Typecheck all files
$(call print,Running mypy)
$(MYPY) --strict ./bibtexautocomplete/ ./tests
.PHONY: format
format: ## Format files with black and isort
$(call print,Running ruff format)
ruff format
$(call print,Running ruff check and fix)
ruff check --fix
.PHONY: format-check
check: ## Check that all files are formatted and lint
$(call print,Running ruff format)
ruff format --check
$(call print,Running ruff check)
ruff check
# =================================================
# Installation
# =================================================
.PHONY: setup
setup: ## Install dependencies
$(call print,Upgrading pip)
$(PIP) install --upgrade pip
$(call print,Installing package and dependencies)
$(PIP) install $(DIR)
.PHONY: setup-dev
setup-dev: ## Install development dependencies
$(call print,Upgrading pip)
$(PIP) install --upgrade pip
$(call print,Installing package and development dependencies)
$(PIP) install -e $(DIR)[dev]
$(call print,Setting up pre-commit)
$(PRECOMMIT) install
.PHONY: clean
clean: ## Remove package
$(call print,Removing package)
rm -rf build bibtexautocomplete.egg-info
.PHONY: clean-all
clean-all: ## Remove package and venv
$(call print,Removing package and dependencies and virtual environment)
rm -rf build bibtexautocomplete.egg-info htmlcov
rm -rf venv
.PHONY: deploy
deploy: ## Build and deploys the package
$(call print,Removing previous dist)
rm -rf dist/* bibtexautocomplete.egg-info build
$(call print,Building package)
$(PYTHON) -m build
$(call print,Deploying package)
twine upload dist/*
# =================================================
# Docker
# =================================================
.PHONY: docker-build
docker-build: ## Build the docker image
$(call print,Building docker image)
$(DOCKER) build -t $(DOCKER_IMG_NAME) .
.PHONY: docker-run
docker-run: ## Run the docker image (requires building first)
$(call print,Running docker image)
$(DOCKER) run --rm -it $(DOCKER_IMG_NAME)
.PHONY: docker
docker: docker-build docker-run ## Build and run the docker image