-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (69 loc) · 2.93 KB
/
Makefile
File metadata and controls
91 lines (69 loc) · 2.93 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
# Makefile for Python Module Template
.PHONY: help install clean test lint format build
# Shell colors
GREEN := \033[0;32m
RESET := \033[0m
# ====================================================================================
# HELP
# ====================================================================================
help:
@echo "Available commands:"
@echo " ${GREEN}install${RESET} -> Creates venv and installs development dependencies."
@echo " ${GREEN}test${RESET} -> Runs tests with pytest."
@echo " ${GREEN}lint${RESET} -> Checks code style and errors with ruff."
@echo " ${GREEN}format${RESET} -> Formats code with ruff and black."
@echo " ${GREEN}build${RESET} -> Builds the package (wheel and sdist) using 'build'."
@echo " ${GREEN}publish-test${RESET} -> Publishes the package to TestPyPI."
@echo " ${GREEN}publish${RESET} -> Publishes the package to PyPI."
@echo " ${GREEN}clean${RESET} -> Removes all build artifacts and caches."
# ====================================================================================
# ENVIRONMENT AND DEPENDENCY MANAGEMENT
# ====================================================================================
# OS check for venv activation
ifeq ($(OS),Windows_NT)
VENV_ACTIVATE = .\.venv\Scripts\activate
else
VENV_ACTIVATE = source .venv/bin/activate
endif
.venv/touchfile:
python -m venv .venv
touch .venv/touchfile
install: .venv/touchfile
@echo "Installing development dependencies and the package in editable mode..."
@$(VENV_ACTIVATE) && pip install --upgrade pip && pip install -e .[dev]
@echo "Setting up pre-commit hooks..."
@$(VENV_ACTIVATE) && pre-commit install
# ====================================================================================
# CODE QUALITY AND TESTING
# ====================================================================================
test:
@echo "Running tests with pytest..."
@$(VENV_ACTIVATE) && pytest
lint:
@echo "Checking code with ruff..."
ruff check .
format:
@echo "Formatting code with ruff and black..."
ruff format .
black .
# ====================================================================================
# BUILD AND PUBLISH
# ====================================================================================
build:
@echo "Building package with 'build'..."
python -m build
publish-test: build
@echo "Publishing to TestPyPI..."
twine upload --repository testpypi dist/*
publish: build
@echo "Publishing to PyPI..."
twine upload dist/*
# ====================================================================================
# CLEANUP
# ====================================================================================
clean:
@echo "Cleaning up artifacts..."
rm -rf build dist *.egg-info .pytest_cache .mypy_cache .coverage __pycache__ .venv
find . -type d -name "__pycache__" -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
@echo "Cleanup complete."