Skip to content

Commit

Permalink
fix handling binary path and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertobruin committed Nov 13, 2024
1 parent c8d1539 commit 4777fd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/python/uv.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (u *UvChecker) EnsureUvInstalled(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
return "", nil
return uvBinaryPath, nil
}

cmd := exec.Command(uvBinaryPath, "version", "--output-format", "json")
output, err := cmd.CombinedOutput()
if err != nil {
return "", fmt.Errorf("failed to check uv version: %w\nOutput: %s\n\nPlease install uv v%s yourself: https://docs.astral.sh/uv/getting-started/installation/", err, output, UvVersion)
return "", fmt.Errorf("failed to check uv version: %w -- Output: %s", err, output)
}

var uvVersion struct {
Expand Down Expand Up @@ -109,7 +109,7 @@ func (u *UvChecker) installUvCommand(ctx context.Context, dest string) error {
if runtime.GOOS == "windows" {
commandInstance = exec.Command(Shell, ShellSubcommandFlag, fmt.Sprintf("winget install --accept-package-agreements --accept-source-agreements --silent --id=astral-sh.uv --version %s --location %s -e", UvVersion, dest)) //nolint:gosec
} else {
commandInstance = exec.Command(Shell, ShellSubcommandFlag, fmt.Sprintf(" set -o pipefail; UV_INSTALL_DIR=\"%s\" curl -LsSf https://astral.sh/uv/%s/install.sh | sh", dest, UvVersion)) //nolint:gosec
commandInstance = exec.Command(Shell, ShellSubcommandFlag, fmt.Sprintf(" set -o pipefail; curl -LsSf https://astral.sh/uv/%s/install.sh | UV_INSTALL_DIR=\"%s\" NO_MODIFY_PATH=1 sh", UvVersion, dest)) //nolint:gosec
}

err := u.cmd.RunAnyCommand(ctx, commandInstance)
Expand Down
10 changes: 5 additions & 5 deletions pkg/python/uv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type mockUvInstaller struct {
mock.Mock
}

func (m *mockUvInstaller) EnsureUvInstalled(ctx context.Context) error {
func (m *mockUvInstaller) EnsureUvInstalled(ctx context.Context) (string, error) {
called := m.Called(ctx)
return called.Error(0)
return called.String(0), called.Error(1)
}

func Test_uvPythonRunner_Run(t *testing.T) {
Expand Down Expand Up @@ -46,7 +46,7 @@ func Test_uvPythonRunner_Run(t *testing.T) {
}).Return(assert.AnError)

inst := new(mockUvInstaller)
inst.On("EnsureUvInstalled", mock.Anything).Return(nil)
inst.On("EnsureUvInstalled", mock.Anything).Return("~/.bruin/uv", nil)

return &fields{
cmd: cmd,
Expand All @@ -73,7 +73,7 @@ func Test_uvPythonRunner_Run(t *testing.T) {
}).Return(assert.AnError)

inst := new(mockUvInstaller)
inst.On("EnsureUvInstalled", mock.Anything).Return(nil)
inst.On("EnsureUvInstalled", mock.Anything).Return("~/.bruin/uv", nil)

return &fields{
cmd: cmd,
Expand All @@ -100,7 +100,7 @@ func Test_uvPythonRunner_Run(t *testing.T) {
}).Return(assert.AnError)

inst := new(mockUvInstaller)
inst.On("EnsureUvInstalled", mock.Anything).Return(nil)
inst.On("EnsureUvInstalled", mock.Anything).Return("~/.bruin/uv", nil)

return &fields{
cmd: cmd,
Expand Down

0 comments on commit 4777fd5

Please sign in to comment.