Verified Commit cd4ae20f authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Initial commit of wheel baker

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+2 −0
Original line number Diff line number Diff line
*.pyc
*.whl
+0 −0

Empty file added.

+44 −0
Original line number Diff line number Diff line
import sys, os
import click
from subprocess import run, CalledProcessError
from importlib import resources
from pathlib import Path
from collections.abc import Sequence

# TODO: Lookup and add the rest
PLATFORMS = [
	"linux/386",
	"linux/amd64",
	"linux/arm64",
	"linux/ppc64le",
	"linux/s390x",
]
PLATFORM_OPTS = ["all", *PLATFORMS]


@click.command
@click.option("--output", type=click.Path(file_okay=False), default="dist")
@click.option("--platform", "platforms", type=click.Choice(PLATFORM_OPTS), multiple=True)
@click.argument("packages", nargs=-1, required=True)
def cli(output: str, platforms: Sequence[str], packages: Sequence[str]) -> None:
	config_resource = resources.files(__package__) / "bake.hcl"

	if "all" in platforms:
		platforms = PLATFORMS

	cmd: list[str|Path] = [
		"docker", "buildx", "bake", "build-pkg",
		*(f"--set=*.platform={platform}" for platform in platforms),
	]

	with resources.as_file(config_resource) as config:
		cmd += ["--file", config]
		env = os.environ.copy()
		env.update(PACKAGES=" ".join(packages), OUTPUT=output)
		try:
			run(cmd, env=env, check=True)
		except CalledProcessError as exc:
			raise click.Abort from exc


cli()

build_wheel/bake.hcl

0 → 100644
+29 −0
Original line number Diff line number Diff line
variable "PACKAGES" {
	default = "$PACKAGES"
}

variable "OUTPUT" {
	default = "dist"
}

target "build-pkg" {
	name = "build-pkg-py${replace(python_tag, ".", "")}"
	matrix = {
		python_tag = ["3.10", "3.11", "3.12"]
	}
	dockerfile-inline = <<-EOF
		ARG python_tag=latest
		FROM docker.io/python:$python_tag
		WORKDIR /pkg
		ARG packages
		RUN pip wheel $packages

		FROM scratch
		COPY --from=0 /pkg/ /
	EOF
	args = {
		python_tag = python_tag
		packages = PACKAGES
	}
	output = ["type=local,dest=${OUTPUT}"]
}