Skip to content

Commit

Permalink
fix build env and run env
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Nov 22, 2024
1 parent a1c9ae0 commit 019595d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ func SetBuildEnv(projectPath string) {
os.Setenv("GOPATH", GetGoPath(absPath))
os.Setenv("GOROOT", GetGoRoot(absPath))
os.Setenv("GOCACHE", GetGoCacheDir(absPath))
os.Setenv("PKG_CONFIG_PATH", GetPythonPkgConfigDir(absPath))
os.Setenv("CGO_ENABLED", "1")
}

func pathSeparator() string {
Expand All @@ -114,13 +116,13 @@ func pathSeparator() string {
return ":"
}

// WriteEnvFile writes environment variables to .python/env.txt
// WriteEnvFile writes environment variables to .deps/env.txt
func WriteEnvFile(projectPath, pythonHome, pythonPath string) error {
// Prepare environment variables
envVars := []string{
fmt.Sprintf("PKG_CONFIG_PATH=%s", filepath.Join(pythonHome, "lib", "pkgconfig")),
fmt.Sprintf("PYTHONPATH=%s", strings.TrimSpace(pythonPath)),
fmt.Sprintf("PYTHONHOME=%s", pythonHome),
fmt.Sprintf("PATH=%s", GetPythonBinDir(projectPath)),
}

// Write to env.txt
Expand Down
3 changes: 1 addition & 2 deletions internal/env/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package env
import (
"fmt"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
Expand Down Expand Up @@ -106,7 +105,7 @@ func TestWriteEnvFile(t *testing.T) {
// Verify the content contains expected environment variables
envContent := string(content)
expectedVars := []string{
fmt.Sprintf("PKG_CONFIG_PATH=%s", filepath.Join(pythonDir, "lib", "pkgconfig")),
fmt.Sprintf("PATH=%s", GetPythonBinDir(projectDir)),
fmt.Sprintf("PYTHONPATH=/mock/path1%s/mock/path2", pathSep),
fmt.Sprintf("PYTHONHOME=%s", pythonDir),
}
Expand Down

0 comments on commit 019595d

Please sign in to comment.