-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (74 loc) · 2.63 KB
/
Copy pathMakefile
File metadata and controls
89 lines (74 loc) · 2.63 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
# Project Variables
PACKAGE ?= prdoc # import/console script name
IMAGE_NAME ?= $(PACKAGE) # docker image repo/name
IMAGE_TAG ?= $(shell poetry version -s 2>/dev/null || echo latest)
REGISTRY ?= ghcr.io/your-org # e.g., ghcr.io/your-user-or-org
PYTHON ?= python3
POETRY ?= poetry
# Helpers
define log
@printf "\033[1;36m%s\033[0m\n" "$(1)"
endef
# Setup / Quality
.PHONY: install
install: ## Create venv & install all deps (incl. dev)
$(call log,"Installing with Poetry...")
$(POETRY) install
.PHONY: fmt
fmt: ## Format code (ruff+black if configured in pyproject)
$(call log,"Formatting code...")
$(POETRY) run ruff format
$(POETRY) run ruff check --fix
.PHONY: lint
lint: ## Lint only
$(call log,"Linting...")
$(POETRY) run ruff check
.PHONY: test
test: ## Run tests with coverage (if configured)
$(call log,"Running tests...")
$(POETRY) run pytest -q
# Build & Publish (PyPI)
dist: ## Build wheels/sdist into ./dist
$(call log,"Building package artifacts...")
$(POETRY) build
.PHONY: publish
publish: ## Publish to PyPI (needs POETRY_PYPI_TOKEN_PYPI env var)
$(call log,"Publishing to PyPI...")
$(POETRY) publish --username __token__ --password "$$POETRY_PYPI_TOKEN_PYPI"
# Example:
# export POETRY_PYPI_TOKEN_PYPI=pfp_xxx...
# make publish
# Version
.PHONY: version
version: ## Show version from pyproject
@$(POETRY) version
# Docker
.PHONY: docker-build
docker-build: ## Build Docker image (prod deps only by default)
$(call log,"Building Docker image $(IMAGE_NAME):$(IMAGE_TAG)...")
docker build \
--build-arg WITH_DEV_DEPS=false \
-t $(IMAGE_NAME):$(IMAGE_TAG) .
.PHONY: docker-build-dev
docker-build-dev: ## Build Docker image with dev deps
$(call log,"Building Docker image (dev) $(IMAGE_NAME):$(IMAGE_TAG)...")
docker build \
--build-arg WITH_DEV_DEPS=true \
-t $(IMAGE_NAME):$(IMAGE_TAG)-dev .
.PHONY: docker-run
docker-run: ## Run the CLI inside the container (override CMD/args as needed)
$(call log,"Running $(IMAGE_NAME):$(IMAGE_TAG)...")
docker run --rm -it \
$(IMAGE_NAME):$(IMAGE_TAG) --help
.PHONY: docker-tag
docker-tag: ## Tag image for registry
$(call log,"Tagging image for registry...")
docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: docker-push
docker-push: docker-tag ## Push image to registry
$(call log,"Pushing image to $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)...")
docker push $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
# Help
.PHONY: help
help: ## Show this help
@awk 'BEGIN {FS = ":.*##"; print "Available targets:\n"} /^[a-zA-Z0-9_.-]+:.*?##/ {printf " \033[1m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)