-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (66 loc) · 2.92 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
# Variables
PACKAGE_NAME = ducopy
PYTHON = python3
VENV = venv311
PYPI_REPO = pypi # Use 'testpypi' for testing
# Commands
.PHONY: all install dev-install lint test build publish clean help increment-version append-license
all: help
## Create a virtual environment and install dependencies
install:
$(PYTHON) -m venv $(VENV)
$(VENV)/bin/pip install -e .
## Install development dependencies
dev-install:
$(PYTHON) -m venv $(VENV)
$(VENV)/bin/pip install -e .[dev]
## Run linting with ruff and formatting with black
lint:
$(VENV)/bin/ruff src/ tests/
$(VENV)/bin/black src/ tests/
## Run tests with pytest
test:
$(VENV)/bin/pytest
## Build the package for PyPI
build:
rm -rf dist/
$(VENV)/bin/python -m build
## Publish the package to PyPI (use PYPI_REPO variable to switch between pypi and testpypi)
## If AUTO_INCREMENT_VERSION is set, increment version before publishing
publish: $(if $(AUTO_INCREMENT_VERSION),increment-version) build
$(VENV)/bin/python -m twine upload -r $(PYPI_REPO) dist/*
## Increment version number in pyproject.toml
increment-version:
@echo "Incrementing version number in pyproject.toml..."
@current_version=$$(grep -oP 'version = "\K[0-9]+' pyproject.toml); \
new_version=$$((current_version + 1)); \
sed -i "s/version = \"$$current_version\"/version = \"$$new_version\"/" pyproject.toml
@echo "Version updated to $$new_version in pyproject.toml."
## Clean build artifacts
clean:
rm -rf dist/ build/ *.egg-info
find . -type d -name "__pycache__" -exec rm -rf {} +
## Append a commented-out license to Python files in the src directory if not already present
append-license:
@echo "Appending license to *.py files under src/ if not already present..."
@find src -name "*.py" | while read pyfile; do \
if ! grep -q "Copyright" "$$pyfile"; then \
sed 's/^/# /' LICENSE > "$$pyfile.new"; \
cat "$$pyfile" >> "$$pyfile.new"; \
mv "$$pyfile.new" "$$pyfile"; \
echo "License prepended (commented) to: $$pyfile"; \
fi; \
done
## Display available commands
help:
@echo "Commonly used make commands:"
@echo " make install - Set up virtual environment and install the package"
@echo " make dev-install - Set up environment with development dependencies"
@echo " make lint - Run ruff and black for linting and formatting"
@echo " make test - Run tests with pytest"
@echo " make build - Build the package for distribution"
@echo " make publish - Publish the package to PyPI (or TestPyPI if PYPI_REPO is set to testpypi)"
@echo " - Use AUTO_INCREMENT_VERSION=1 make publish to increment version before publishing"
@echo " make increment-version - Manually increment the version number in pyproject.toml"
@echo " make clean - Clean build artifacts"
@echo " make append-license - Prepend LICENSE to all *.py files that don't already contain the license"