Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (73 loc) · 2.2 KB
/
Copy pathMakefile
File metadata and controls
101 lines (73 loc) · 2.2 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
PROJECT_NAME=statsplotly
# Python env
PYTHON_SHELL_VERSION := $(shell python --version | cut -d " " -f 2)
POETRY_AVAILABLE := $(shell which poetry > /dev/null && echo 1 || echo 0)
# CI variables
CI_EXCLUDED_DIRS = __pycache__ dist docs
CI_DIRECTORIES=$(filter-out $(CI_EXCLUDED_DIRS), $(foreach dir, $(dir $(wildcard */)), $(dir:/=)))
# Project targets
confirm:
@echo "Are you sure? [y/N] " && read ans && [ $${ans:-N} = y ]
exists-%:
@which "$*" > /dev/null && echo 1 || echo 0
print-%: ; @echo $* = $($*)
init:
ifneq ($(POETRY_AVAILABLE), 1)
@echo "No Poetry executable found, cannot init project" && exit 1;
endif
@poetry check --no-ansi --quiet
@echo "✅ Poetry is installed"
@echo "💡 Using Python $(PYTHON_SHELL_VERSION)"
@poetry config virtualenvs.in-project true
@poetry config virtualenvs.create true
@poetry install
pre-commit
# CI targets
lint-%:
@echo lint-"$*"
@poetry run ruff check "$*"
@poetry run ruff format --check "$*"
@echo " ✅ All good"
lint: $(addprefix lint-, $(CI_DIRECTORIES))
fix-%:
@echo fix-"$*"
@poetry run ruff check --fix "$*"
@poetry run ruff format "$*"
@echo " ✅ All fixed"
fix: $(addprefix fix-, $(CI_DIRECTORIES)) ci
typecheck-%:
@echo typecheck-"$*"
@poetry run mypy "$*"
typecheck: $(addprefix typecheck-, $(CI_DIRECTORIES))
test:
@poetry run pytest -s --rootdir ./ --cache-clear tests
ci: lint typecheck test
coverage:
@poetry run coverage run -m pytest
@poetry run coverage report
# Pre-commit hooks
set-pre-commit:
@echo "Setting up pre-commit hooks..."
@poetry run pre-commit install
@poetry run pre-commit autoupdate
run-pre-commit:
@poetry run pre-commit run --all-files
# Documentation
update-doc:
@poetry run sphinx-apidoc --module-first --no-toc --force -o docs/source src/$(PROJECT_NAME)
build-doc:
@poetry run sphinx-build docs ./docs/_build/html/
# Cleaning
clean-python:
@echo "🧹 Cleaning Python bytecode..."
@poetry run pyclean . --quiet
clean-cache:
@echo "🧹 Cleaning cache..."
@find . -regex ".*_cache" -type d -print0|xargs -0 rm -r --
@poetry run pre-commit clean
clean-hooks:
@echo "🧹 Cleaning hooks..."
@rm -r ".git/hooks" ||:
# Global
clean: confirm clean-cache clean-python clean-hooks
@echo "✨ All clean"