-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
116 lines (79 loc) · 3.43 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 common development tasks.
#
# Copyright (c) 2015-2022 Wibowo Arindrarto <[email protected]>
# SPDX-License-Identifier: BSD-3-Clause
#
# This file is part of crimson <https://github.com/bow/crimson>.
# Application name.
APP_NAME := crimson
all: help
.PHONY: build
build: ## Build wheel and source dist.
poetry build
.PHONY: clean
clean: ## Remove build and test artifacts, including built Docker images.
rm -rf build/ dist/ wheels/ \
.coverage .coverage.xml .junit.xml .tox/ .cache/ .mypy_cache/ .pytest_cache/ \
&& (docker rmi ghcr.io/bow/$(APP_NAME) 2> /dev/null || true)
.PHONY: clean-pyenv
clean-pyenv: ## Remove the created pyenv virtualenv.
pyenv virtualenv-delete -f $(VENV_NAME) && rm -f .python-version
.PHONY: dev
dev: ## Configure a local development setup.
@if command -v nix-env > /dev/null && command -v direnv > /dev/null; then \
printf "Configuring a local dev environment and setting up git pre-commit hooks...\n" >&2 \
&& direnv allow . > /dev/null \
&& DIRENV_LOG_FORMAT="" direnv exec $(CURDIR) pre-commit install \
&& printf "Done.\n" >&2; \
elif command -v nix-env > /dev/null; then \
printf "Error: direnv seems to be unconfigured or missing\n" >&2 && exit 1; \
elif command -v direnv > /dev/null; then \
printf "Error: nix seems to be unconfigured or missing\n" >&2 && exit 1; \
else \
printf "Error: both direnv and nix seem to be unconfigured and/or missing" >&2 && exit 1; \
fi
.PHONY: dev-reset
dev-reset: ## Resets the local development environment.
rm -rf .venv .direnv && direnv reload
.PHONY: fmt
fmt: ## Apply Black.
black -t py312 .
.PHONY: help
help: ## Show this help.
$(eval PADLEN=$(shell grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| cut -d':' -f1 \
| awk '{cur = length($$0); lengths[cur] = lengths[cur] $$0 ORS; max=(cur > max ? cur : max)} END {printf "%s", max}' \
|| (true && echo 0)))
@(grep --version > /dev/null 2>&1 || (>&2 "error: GNU grep not installed"; exit 1)) \
&& printf "\033[36m◉ %s dev console\033[0m\n" "$(APP_NAME)" >&2 \
&& grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m» \033[33m%-*s\033[0m \033[36m· \033[0m%s\n", $(PADLEN), $$1, $$2}' \
| sort
.PHONY: img
img: ## Build a docker image and load it into a running daemon.
nix build .#dockerArchiveStreamer && ./result | docker image load
.PHONY: lint
lint: lint-types lint-style lint-metrics ## Run the linter suite.
.PHONY: lint-types
lint-types: ## Lint the type hints.
mypy crimson tests
.PHONY: lint-style
lint-style: ## Lint style conventions.
flake8 --statistics crimson tests && black -t py312 --check .
.PHONY: lint-metrics
lint-metrics: ## Lint other metrics.
python -m radon cc --total-average --show-closures --show-complexity --min C crimson
.PHONY: scan-sec
scan-sec: scan-sec-ast scan-sec-deps ## Perform all security analyses.
.PHONY: scan-sec-ast
scan-sec-ast: ## Perform static security analysis on the AST.
bandit -r crimson
.PHONY: scan-sec-deps
scan-sec-deps: ## Scan dependencies for reported vulnerabilities.
poetry export --without-hashes -f requirements.txt -o /dev/stdout | safety check --full-report --stdin
.PHONY: test
test: ## Run the test suite.
py.test --junitxml=.junit.xml --cov=crimson --cov-report=term-missing --cov-report=xml:.coverage.xml crimson tests
.PHONY: tox
tox: ## Run the test suite and all linters under all supported Python versions.
tox --parallel auto