-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (54 loc) · 2.33 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
# 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
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 {} +
## 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"