Skip to content

Commit b6f0c69

Browse files
committed
fix build env and run env
1 parent 55107c4 commit b6f0c69

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

cmd/internal/create/templates/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import (
77
func main() {
88
Initialize()
99
defer Finalize()
10+
println("Hello, World!")
1011
}

cmd/internal/install/python.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ print(f'{version}\n{is_freethreaded}')
200200
// Template for the pkg-config files
201201
embedTemplate := `prefix=${pcfiledir}/../..
202202
exec_prefix=${prefix}
203-
libdir=${exec_prefix}/lib
203+
libdir=${exec_prefix}
204204
includedir=${prefix}/include
205205
206206
Name: Python
@@ -214,7 +214,7 @@ Cflags: -I${includedir}
214214

215215
normalTemplate := `prefix=${pcfiledir}/../..
216216
exec_prefix=${prefix}
217-
libdir=${exec_prefix}/lib
217+
libdir=${exec_prefix}
218218
includedir=${prefix}/include
219219
220220
Name: Python

cmd/internal/rungo/run.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ func RunCommand(command string, args []string) error {
119119
cmd.Env = append(goEnv, os.Environ()...)
120120
cmd.Stdout = os.Stdout
121121
cmd.Stderr = os.Stderr
122-
if command == "run" {
123-
cmd.Stdin = os.Stdin
124-
}
122+
cmd.Stdin = os.Stdin
125123

126124
// Execute the command
127125
if err := cmd.Run(); err != nil {

internal/env/env.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ func GetPythonRoot(projectPath string) string {
3737

3838
// GetPythonBinDir returns the Python binary directory path relative to project path
3939
func GetPythonBinDir(projectPath string) string {
40+
if runtime.GOOS == "windows" {
41+
return filepath.Join(GetPythonRoot(projectPath))
42+
}
4043
return filepath.Join(GetPythonRoot(projectPath), "bin")
4144
}
4245

@@ -93,6 +96,7 @@ func SetBuildEnv(projectPath string) {
9396
}
9497
path := os.Getenv("PATH")
9598
path = GetGoBinDir(absPath) + pathSeparator() + path
99+
path = GetPythonBinDir(absPath) + pathSeparator() + path
96100
if runtime.GOOS == "windows" {
97101
path = GetMingwRoot(absPath) + pathSeparator() + path
98102
path = GetTinyPkgConfigDir(absPath) + pathSeparator() + path
@@ -101,6 +105,8 @@ func SetBuildEnv(projectPath string) {
101105
os.Setenv("GOPATH", GetGoPath(absPath))
102106
os.Setenv("GOROOT", GetGoRoot(absPath))
103107
os.Setenv("GOCACHE", GetGoCacheDir(absPath))
108+
os.Setenv("PKG_CONFIG_PATH", GetPythonPkgConfigDir(absPath))
109+
os.Setenv("CGO_ENABLED", "1")
104110
}
105111

106112
func pathSeparator() string {
@@ -110,13 +116,13 @@ func pathSeparator() string {
110116
return ":"
111117
}
112118

113-
// WriteEnvFile writes environment variables to .python/env.txt
119+
// WriteEnvFile writes environment variables to .deps/env.txt
114120
func WriteEnvFile(projectPath, pythonHome, pythonPath string) error {
115121
// Prepare environment variables
116122
envVars := []string{
117-
fmt.Sprintf("PKG_CONFIG_PATH=%s", filepath.Join(pythonHome, "lib", "pkgconfig")),
118123
fmt.Sprintf("PYTHONPATH=%s", strings.TrimSpace(pythonPath)),
119124
fmt.Sprintf("PYTHONHOME=%s", pythonHome),
125+
fmt.Sprintf("PATH=%s", GetPythonBinDir(projectPath)),
120126
}
121127

122128
// Write to env.txt

internal/env/env_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package env
33
import (
44
"fmt"
55
"os"
6-
"path/filepath"
76
"reflect"
87
"runtime"
98
"strings"
@@ -106,7 +105,7 @@ func TestWriteEnvFile(t *testing.T) {
106105
// Verify the content contains expected environment variables
107106
envContent := string(content)
108107
expectedVars := []string{
109-
fmt.Sprintf("PKG_CONFIG_PATH=%s", filepath.Join(pythonDir, "lib", "pkgconfig")),
108+
fmt.Sprintf("PATH=%s", GetPythonBinDir(projectDir)),
110109
fmt.Sprintf("PYTHONPATH=/mock/path1%s/mock/path2", pathSep),
111110
fmt.Sprintf("PYTHONHOME=%s", pythonDir),
112111
}

0 commit comments

Comments
 (0)