Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
87 lines (71 loc) 路 2.86 KB
/
Copy pathMakefile
File metadata and controls
87 lines (71 loc) 路 2.86 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
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026, Unikraft GmbH. All rights reserved.
# Release channel to generate against (maps to a branch of the openapi repo).
CHANNEL ?= prod-staging
SPEC_BASE ?= https://raw.githubusercontent.com/unikraft-cloud/openapi/refs/heads/$(CHANNEL)
PLATFORM_SPEC ?= $(SPEC_BASE)/platform.json
CONTROLPLANE_SPEC ?= $(SPEC_BASE)/controlplane.json
# Both specs also live in the proto repository, which is where the changes land
# first. Generate against a local checkout of it with:
# make generate \
# PLATFORM_SPEC=../proto/gen/openapi/platform/openapi.yaml \
# CONTROLPLANE_SPEC=../proto/gen/openapi/controlplane/openapi.yaml
# The openapi-gen code generator, pinned so a regeneration is reproducible.
# Raise OPENAPI_GEN_VERSION to take a newer one.
GO ?= go
UV ?= uv
OPENAPI_GEN_VERSION ?= v0.0.0-20260915145300-fef7701a6874
OPENAPI_GEN ?= $(GO) run unikraft.com/x/tools/openapi-gen@$(OPENAPI_GEN_VERSION)
TEMPLATES ?= ./templates
OUTPUT ?= ./src/unikraft_cloud/api
.PHONY: all
all: generate test
# Each per-spec target clears its generated modules first, so a tag the spec
# drops leaves no stale client behind. The hand-written `__init__.py` files stay.
.PHONY: generate
generate: generate-platform generate-controlplane ## Regenerate the platform and control-plane plumbing from the OpenAPI specs.
$(MAKE) fmt
# Namespaced schema names (`Instances.Instance`) are not Python identifiers, so
# `--namespace-flatten strip` removes the namespace.
.PHONY: generate-platform
generate-platform: ## Regenerate the platform API plumbing.
rm -f $(OUTPUT)/platform/*_gen.py
$(OPENAPI_GEN) \
-i $(PLATFORM_SPEC) \
-o $(OUTPUT)/platform \
-t $(TEMPLATES) \
--namespace-flatten strip
.PHONY: generate-controlplane
generate-controlplane: ## Regenerate the control-plane API plumbing.
rm -f $(OUTPUT)/controlplane/*_gen.py
$(OPENAPI_GEN) \
-i $(CONTROLPLANE_SPEC) \
-o $(OUTPUT)/controlplane \
-t $(TEMPLATES) \
--namespace-flatten strip
# A plugin's client is generated by plugin-sdk from the plugin's own
# specification, and installed as a package of its own.
.PHONY: fmt
fmt: ## Sort the imports of the generated plumbing and format it.
$(UV) run ruff check --select I --fix $(OUTPUT)
$(UV) run ruff format $(OUTPUT)
.PHONY: typecheck
typecheck: ## Type-check the whole project.
$(UV) run mypy
.PHONY: lint
lint: ## Lint and format-check with Ruff.
$(UV) run ruff check .
$(UV) run ruff format --check .
.PHONY: test
test: ## Run the test suite.
$(UV) run pytest
.PHONY: build
build: ## Build the sdist and wheel.
$(UV) build
.PHONY: clean
clean: ## Remove build output.
rm -rf dist
.PHONY: help
help: ## Show this help.
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}'