Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setup Python action #789

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ jobs:
with:
go-version: 1.21.0

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Set go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
Expand Down
1 change: 1 addition & 0 deletions python/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestFreeze(t *testing.T) {
t.Skip("Skipping test until fixing Python installation on GitHub Windows environment")

// remove this once equivalent tests for windows have been set up
// or this test has been fixed for windows
Expand Down
7 changes: 6 additions & 1 deletion python/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func DetectExecutable(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
pyExec = trimmedS(out)
pyExec = getFirstMatch(string(out))
return pyExec, nil
}

Expand All @@ -92,6 +92,11 @@ func execAndPassErr(ctx context.Context, name string, args ...string) ([]byte, e
return out, nicerErr(err)
}

func getFirstMatch(out string) string {
res := strings.Split(out, "\n")
return strings.Trim(res[0], "\n\r")
}

func nicerErr(err error) error {
if err == nil {
return nil
Expand Down
5 changes: 5 additions & 0 deletions python/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func TestDetectVirtualEnvFalse(t *testing.T) {
assert.Equal(t, "", venvDir)
}

func TestGetFirstMatch(t *testing.T) {
matches := "C:\\hostedtoolcache\\windows\\Python\\3.9.13\\x64\\python3.exe\r\nC:\\ProgramData\\Chocolatey\\bin\\python3.exe"
assert.Equal(t, getFirstMatch(matches), "C:\\hostedtoolcache\\windows\\Python\\3.9.13\\x64\\python3.exe")
}

func TestMakeDetectableVenv(t *testing.T) {
var temp string
defer testTempdir(t, &temp)()
Expand Down