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,