-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (117 loc) · 5.26 KB
/
Makefile
File metadata and controls
139 lines (117 loc) · 5.26 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
.PHONY: all build-package push-package clean-package build-alias push-alias clean-alias build-docker push-docker clean-docker test lint format typecheck clean help
DOCKER_IMAGE := oaklight/weilink
VERSION := $(shell grep '__version__' src/weilink/__init__.py | head -1 | cut -d'"' -f2)
# Optional variables
V ?= $(VERSION)
PYPI_MIRROR ?=
REGISTRY_MIRROR ?=
all: lint format typecheck test
# ──────────────────────────────────────────────
# Package
# ──────────────────────────────────────────────
build-package:
python -m build
push-package:
twine upload dist/*
clean-package:
rm -rf dist/ build/ src/*.egg-info
# ──────────────────────────────────────────────
# Alias package (pyilink)
# ──────────────────────────────────────────────
build-alias:
@echo "Building pyilink alias package $(V)..."
@sed 's/version = "0.0.0"/version = "$(V)"/' pyilink/pyproject.toml > pyilink/pyproject.toml.tmp
@sed -i 's/weilink==0.0.0/weilink==$(V)/' pyilink/pyproject.toml.tmp
@mv pyilink/pyproject.toml.tmp pyilink/pyproject.toml.build
@cd pyilink && cp pyproject.toml pyproject.toml.bak && mv pyproject.toml.build pyproject.toml && python -m build --no-isolation && mv pyproject.toml.bak pyproject.toml
@echo "pyilink $(V) built successfully."
push-alias:
twine upload pyilink/dist/*
clean-alias:
rm -rf pyilink/dist/ pyilink/build/ pyilink/*.egg-info
# ──────────────────────────────────────────────
# Docker
# ──────────────────────────────────────────────
build-docker:
@echo "Building Docker image $(DOCKER_IMAGE):$(V)..."
@BUILD_ARGS=""; \
if [ -n "$(REGISTRY_MIRROR)" ]; then \
echo "Using registry mirror: $(REGISTRY_MIRROR)"; \
BUILD_ARGS="$$BUILD_ARGS --build-arg REGISTRY_MIRROR=$(REGISTRY_MIRROR)"; \
fi; \
LOCAL_WHEEL=""; \
if [ -d "dist" ] && [ -n "$$(ls -A dist/*.whl 2>/dev/null)" ]; then \
LOCAL_WHEEL=$$(ls dist/*.whl | head -n 1 | xargs basename); \
echo "Found local wheel: $$LOCAL_WHEEL"; \
BUILD_ARGS="$$BUILD_ARGS --build-arg LOCAL_WHEEL=$$LOCAL_WHEEL"; \
elif [ -n "$(V)" ]; then \
echo "Using version: $(V)"; \
BUILD_ARGS="$$BUILD_ARGS --build-arg PACKAGE_VERSION=$(V)"; \
else \
echo "No local wheel or version specified, will install latest from PyPI"; \
fi; \
if [ -n "$(PYPI_MIRROR)" ]; then \
echo "Using PyPI mirror: $(PYPI_MIRROR)"; \
BUILD_ARGS="$$BUILD_ARGS --build-arg PYPI_MIRROR=$(PYPI_MIRROR)"; \
fi; \
cd docker && docker build -f Dockerfile $$BUILD_ARGS -t $(DOCKER_IMAGE):$(V) -t $(DOCKER_IMAGE):latest ..
@echo "Docker image built successfully."
push-docker:
@echo "Pushing Docker images $(DOCKER_IMAGE):$(V) and $(DOCKER_IMAGE):latest..."
docker push $(DOCKER_IMAGE):$(V)
docker push $(DOCKER_IMAGE):latest
@echo "Docker images pushed successfully."
clean-docker:
@echo "Cleaning Docker images..."
docker rmi $(DOCKER_IMAGE):latest 2>/dev/null || true
docker rmi $(DOCKER_IMAGE):$(V) 2>/dev/null || true
# ──────────────────────────────────────────────
# Development
# ──────────────────────────────────────────────
test:
pytest tests/ -v
lint:
ruff check src/ tests/ --fix
format:
ruff format src/ tests/
typecheck:
ty check
clean: clean-package
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
rm -rf .pytest_cache .coverage htmlcov
help:
@echo "Available targets:"
@echo ""
@echo "Package:"
@echo " build-package - Build Python package"
@echo " push-package - Upload to PyPI"
@echo " clean-package - Remove build artifacts"
@echo ""
@echo "Alias (pyilink):"
@echo " build-alias - Build pyilink alias package"
@echo " push-alias - Upload pyilink to PyPI"
@echo " clean-alias - Remove pyilink build artifacts"
@echo ""
@echo "Docker:"
@echo " build-docker - Build Docker image (local x64)"
@echo " push-docker - Push Docker image to registry"
@echo " clean-docker - Clean Docker images"
@echo ""
@echo "Development:"
@echo " test - Run tests"
@echo " lint - Run ruff linter with auto-fix"
@echo " format - Format code with ruff"
@echo " typecheck - Run ty type checker"
@echo " clean - Clean all generated files"
@echo ""
@echo "Usage examples:"
@echo " make build-docker"
@echo " make build-docker V=0.3.0"
@echo " make build-docker PYPI_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple"
@echo " make build-docker REGISTRY_MIRROR=docker.1ms.run"
@echo ""
@echo "Variables:"
@echo " V=<version> - Specify version (default: auto-detected from __init__.py)"
@echo " PYPI_MIRROR=<url> - PyPI mirror URL"
@echo " REGISTRY_MIRROR=<host> - Docker registry mirror"