Skip to content

Commit 50bd91c

Browse files
authored
Merge pull request #252 from roots/upgrade-pip-on-init
Upgrade pip during init
2 parents 80e3a4d + 67f4e7c commit 50bd91c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

cmd/init.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"bytes"
55
"flag"
66
"fmt"
7-
"os/exec"
87
"strings"
98

109
"github.com/mitchellh/cli"
10+
"github.com/roots/trellis-cli/command"
1111
"github.com/roots/trellis-cli/trellis"
1212
)
1313

@@ -116,17 +116,33 @@ func (c *InitCommand) Run(args []string) int {
116116
}
117117

118118
spinner := NewSpinner(
119+
SpinnerCfg{
120+
Message: "Ensure pip is up to date",
121+
FailMessage: "Error upgrading pip",
122+
},
123+
)
124+
spinner.Start()
125+
pipUpgradeOutput, err := command.Cmd("python3", []string{"-m", "pip", "install", "--upgrade", "pip"}).CombinedOutput()
126+
127+
if err != nil {
128+
spinner.StopFail()
129+
c.UI.Error(string(pipUpgradeOutput))
130+
return 1
131+
}
132+
spinner.Stop()
133+
134+
spinner = NewSpinner(
119135
SpinnerCfg{
120136
Message: "Installing dependencies (this can take a minute...)",
121137
FailMessage: "Error installing dependencies",
122-
StopMessage: "Installing dependencies",
138+
StopMessage: "Dependencies installed",
123139
},
124140
)
125141
spinner.Start()
126-
pipCmd := exec.Command("pip", "install", "-r", "requirements.txt")
142+
pipCmd := command.Cmd("pip", []string{"install", "-r", "requirements.txt"})
127143
errorOutput := &bytes.Buffer{}
128144
pipCmd.Stderr = errorOutput
129-
err := pipCmd.Run()
145+
err = pipCmd.Run()
130146

131147
if err != nil {
132148
spinner.StopFail()

0 commit comments

Comments
 (0)