forked from paketo-buildpacks/pipenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipenv_install_process.go
47 lines (37 loc) · 1.23 KB
/
pipenv_install_process.go
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
package pipenv
import (
"bytes"
"fmt"
"os"
"github.com/paketo-buildpacks/packit/v2/pexec"
)
//go:generate faux --interface Executable --output fakes/executable.go
// Executable defines the interface for invoking an executable.
type Executable interface {
Execute(pexec.Execution) error
}
type PipenvInstallProcess struct {
executable Executable
}
// NewPipenvInstallProcess creates a PipenvInstallProcess instance.
func NewPipenvInstallProcess(executable Executable) PipenvInstallProcess {
return PipenvInstallProcess{
executable: executable,
}
}
// Execute installs the provided version of pipenv from the internet into the
// layer path designated by targetLayerPath
func (p PipenvInstallProcess) Execute(version, targetLayerPath string) error {
buffer := bytes.NewBuffer(nil)
err := p.executable.Execute(pexec.Execution{
Args: []string{"install", fmt.Sprintf("pipenv==%s", version), "--user"},
// Set the PYTHONUSERBASE to ensure that pip is installed to the newly created target layer.
Env: append(os.Environ(), fmt.Sprintf("PYTHONUSERBASE=%s", targetLayerPath)),
Stdout: buffer,
Stderr: buffer,
})
if err != nil {
return fmt.Errorf("failed to configure pipenv:\n%s\nerror: %w", buffer.String(), err)
}
return nil
}