# Packaging Makefile for workspace-runner.
# `make publish` builds sdists+wheels and uploads to PyPI via twine.
#
# Tooling (build + twine) is installed into an isolated .build-venv/, created
# on demand -- so targets are self-sufficient and never touch system python.

PYTHON ?= python3
VENV := .build-venv
VPY := $(VENV)/bin/python

.PHONY: help build check testpublish publish clean distclean

help:
	@echo "targets:"
	@echo "  make build       build sdist and wheel into dist/"
	@echo "  make check       twine check the built artifacts"
	@echo "  make testpublish upload to TestPyPI (dry run before the real thing)"
	@echo "  make publish     build, check, then upload to PyPI"
	@echo "  make clean       remove build artifacts"
	@echo "  make distclean   also remove the isolated build venv"

# Provision the isolated tool venv; the stamp file marks it ready.
$(VENV)/.stamp:
	$(PYTHON) -m venv $(VENV)
	$(VPY) -m pip install --quiet --upgrade pip build twine
	touch $@

# Clean dist first so it never carries a stale version into the upload.
build: $(VENV)/.stamp clean
	$(VPY) -m build

check: build
	$(VPY) -m twine check dist/*

# TestPyPI: validate the whole publish path without burning a real version.
testpublish: check
	$(VPY) -m twine upload --repository testpypi dist/*

publish: check
	$(VPY) -m twine upload dist/*

clean:
	rm -rf dist build src/*.egg-info

distclean: clean
	rm -rf $(VENV)
