#!make # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2026 Bryan Joshua Pedini PYTHON ?= python3 VENV ?= .venv-publish PKG := proxmox_power_button DIST := netbox-proxmox-power-button PY := $(VENV)/bin/python TWINE := $(VENV)/bin/twine # Version lives in two places on purpose (importing the package to read it # would drag in `netbox`, absent in a build env). `make bump` writes both, # `make version` proves they agree. PYPROJECT_VERSION = $(shell $(PYTHON) -c "import tomllib,pathlib;print(tomllib.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])") CONFIG_VERSION = $(shell $(PYTHON) -c "import re,pathlib;print(re.search(r'version = \"([^\"]+)\"',pathlib.Path('$(PKG)/__init__.py').read_text()).group(1))") .PHONY: default help venv clean version bump build check testpypi publish tag default: help help: @echo "make venv - create $(VENV) with build+twine (PEP 668-safe)" @echo "make version - show the version and verify both copies agree" @echo "make bump V=x.y.z - set the version in pyproject.toml and $(PKG)/__init__.py" @echo "make build - clean, then build the sdist and the wheel" @echo "make check - build, then verify the artifacts (contents + twine check)" @echo "make testpypi - build, check, upload to TestPyPI" @echo "make publish - build, check, upload to PyPI (asks to confirm)" @echo "make tag - git tag " @echo "make clean - remove dist/, build/, *.egg-info, __pycache__" @echo "" @echo "Uploads authenticate with username __token__ and a pypi-... API token." @echo "Put it in ~/.pypirc or export TWINE_USERNAME/TWINE_PASSWORD." venv: @test -x $(TWINE) || ( \ $(PYTHON) -m venv $(VENV) && \ $(VENV)/bin/pip --quiet install --upgrade pip build twine \ ) @echo "tooling ready: $(VENV)" clean: rm -rf dist build *.egg-info find . -path ./$(VENV) -prune -o -name __pycache__ -type d -prune -exec rm -rf {} + version: @echo "pyproject.toml : $(PYPROJECT_VERSION)" @echo "$(PKG)/__init__.py : $(CONFIG_VERSION)" @test "$(PYPROJECT_VERSION)" = "$(CONFIG_VERSION)" || \ ( echo "ERROR: versions disagree — run 'make bump V='"; exit 1 ) bump: @test -n "$(V)" || ( echo "usage: make bump V=1.2.3"; exit 1 ) sed -i 's/^version = ".*"/version = "$(V)"/' pyproject.toml sed -i 's/^\( *\)version = ".*"/\1version = "$(V)"/' $(PKG)/__init__.py @$(MAKE) --no-print-directory version build: venv version clean $(PY) -m build # The wheel must carry the button template (templates/ has no __init__.py, so a # misconfigured package-data silently ships a wheel that raises # TemplateDoesNotExist on every VM page) and every migration. check: build @echo "--- wheel contents ---" @$(PY) -m zipfile -l dist/*.whl | awk 'NR>1 {print $$1}' @echo "--- sdist contents ---" @tar tzf dist/*.tar.gz @echo "--- assertions ---" @$(PY) -m zipfile -l dist/*.whl | grep -q 'templates/$(PKG)/vm_power_buttons.html' \ && echo "OK wheel ships the button template" \ || ( echo "FAIL wheel is missing the button template"; exit 1 ) @$(PY) -m zipfile -l dist/*.whl | grep -q '$(PKG)/migrations/0001_initial.py' \ && echo "OK wheel ships the migration" \ || ( echo "FAIL wheel is missing the migration"; exit 1 ) @$(PY) -m zipfile -l dist/*.whl | grep -q 'dist-info/licenses/LICENSE' \ && echo "OK wheel ships the licence" \ || ( echo "FAIL wheel is missing the licence"; exit 1 ) @$(TWINE) check dist/* testpypi: build check $(TWINE) upload --repository testpypi dist/* # A version number is burned permanently on upload — never reusable, even after # a delete. Hence the confirmation. publish: build check @echo "About to upload $(DIST) $(PYPROJECT_VERSION) to the real PyPI." @read -p "This cannot be undone. Type the version to confirm: " v; \ test "$$v" = "$(PYPROJECT_VERSION)" || ( echo "aborted"; exit 1 ) $(TWINE) upload dist/* tag: git tag $(PYPROJECT_VERSION) @echo "tagged $(PYPROJECT_VERSION) — push with: git push --tags"