-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
88 lines (74 loc) · 2.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
SHELL := sh
.ONESHELL:
.SHELLFLAGS := -eu -c
.DELETE_ON_ERROR:
SOURCES_PATH := src
TESTS_PATH := tests
# load environment config from .env if able
-include .env
ifndef UV_VERSION
UV_VERSION := 0.5.14
endif
.PHONY: uv_check venv sync update format lint test release
# Check installed UV version and install if needed
uv_check:
@echo 'Checking uv version...'
# Install if not present
@if ! command -v uv > /dev/null; then \
echo '...installing uv...'; \
curl -LsSf https://github.com/astral-sh/uv/releases/download/$(UV_VERSION)/uv-installer.sh | sh; \
if [ $$? -ne 0 ]; then \
echo "...installing uv failed!"; \
exit 1; \
fi; \
fi
# Check version and update if needed
@if command -v uv > /dev/null; then \
CURRENT_VERSION=$$(uv --version | head -n1 | cut -d" " -f2); \
if [ "$$(printf "%s\n%s" "$(UV_VERSION)" "$$CURRENT_VERSION" | sort -V | head -n1)" != "$(UV_VERSION)" ]; then \
echo '...updating uv...'; \
curl -LsSf https://github.com/astral-sh/uv/releases/download/$(UV_VERSION)/uv-installer.sh | sh; \
if [ $$? -ne 0 ]; then \
echo "...updating uv failed!"; \
exit 1; \
fi; \
else \
echo '...uv version is up-to-date!'; \
fi; \
fi
# Setup virtual environment for local development.
venv: uv_check
@echo '# Preparing development environment...'
@echo '...cloning .env...'
@cp -n ./config/.env.example ./.env || :
@echo '...preparing git hooks...'
@cp -n ./config/pre-push ./.git/hooks/pre-push || :
@echo '...preparing venv...'
@uv sync --all-groups --all-extras --frozen --reinstall
@echo '...development environment ready! Activate venv using `. ./.venv/bin/activate`.'
# Sync environment with uv based on constraints
sync: uv_check
@echo '# Synchronizing dependencies...'
@uv sync --all-groups --all-extras --frozen
@echo '...finished!'
# Update and lock dependencies from pyproject.toml
update:
@echo '# Updating dependencies...'
@uv sync --all-groups --all-extras --upgrade
@echo '...finished!'
# Run formatter.
format:
@ruff check --quiet --fix $(SOURCES_PATH) $(TESTS_PATH)
@ruff format --quiet $(SOURCES_PATH) $(TESTS_PATH)
# Run linters and code checks.
lint:
@bandit -r $(SOURCES_PATH)
@ruff check $(SOURCES_PATH) $(TESTS_PATH)
@pyright --project ./
# Run tests suite.
test:
@python -B -m pytest -v --cov=$(SOURCES_PATH) --rootdir=$(TESTS_PATH)
release: lint test
@echo '# Preparing release...'
@python -m build && python -m twine upload --skip-existing dist/*
@echo '...finished!'