From 08dfefb28ddbc6e370743abf9c75275e2e3dcbdc Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 19 Apr 2026 00:03:36 +0900 Subject: [PATCH] internal/rosa/python: pip helper Binary pip releases are not considered acceptable, this more generic helper is required for building from source. Signed-off-by: Ophestra --- internal/rosa/python.go | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/rosa/python.go b/internal/rosa/python.go index 4da4074d..e9a2a25a 100644 --- a/internal/rosa/python.go +++ b/internal/rosa/python.go @@ -81,6 +81,52 @@ func init() { } } +// PipHelper is the [Python] pip packaging helper. +type PipHelper struct { + // Whether to omit --no-build-isolation. + BuildIsolation bool +} + +var _ Helper = new(PipHelper) + +// extra returns python. +func (*PipHelper) extra(int) P { return P{Python} } + +// wantsChmod returns true. +func (*PipHelper) wantsChmod() bool { return true } + +// wantsWrite is equivalent to wantsChmod. +func (attr *PipHelper) wantsWrite() bool { return attr.wantsChmod() } + +// scriptEarly is a noop. +func (*PipHelper) scriptEarly() string { return "" } + +// createDir returns false. +func (*PipHelper) createDir() bool { return false } + +// wantsDir requests a new directory in TMPDIR. +func (*PipHelper) wantsDir() string { return `"$(mktemp -d)"` } + +// script generates the pip3 install command. +func (attr *PipHelper) script(name string) string { + if attr == nil { + attr = new(PipHelper) + } + + var extra string + if !attr.BuildIsolation { + extra += ` + --no-build-isolation \` + } + + return ` +pip3 install \ + --no-index \ + --prefix=/system \ + --root=/work \` + extra + ` + '/usr/src/` + name + `'` +} + // newViaPip installs a pip wheel from a url. func (t Toolchain) newViaPip( name, version, url, checksum string,