@@ -24,8 +24,9 @@ import (
24
24
var releasesData []byte
25
25
26
26
const (
27
- uvVersion = "uv==0.2.33"
28
- requirementsTxt = "requirements.txt"
27
+ uvVersion = "uv==0.2.33"
28
+ requirementsTxt = "requirements.txt"
29
+ gptscriptRequirementsTxt = "requirements-gptscript.txt"
29
30
)
30
31
31
32
type Release struct {
@@ -47,10 +48,7 @@ func (r *Runtime) ID() string {
47
48
return "python" + r .Version
48
49
}
49
50
50
- func (r * Runtime ) Supports (tool types.Tool , cmd []string ) bool {
51
- if _ , hasRequirements := tool .MetaData [requirementsTxt ]; ! hasRequirements && ! tool .Source .IsGit () {
52
- return false
53
- }
51
+ func (r * Runtime ) Supports (_ types.Tool , cmd []string ) bool {
54
52
if runtimeEnv .Matches (cmd , r .ID ()) {
55
53
return true
56
54
}
@@ -152,11 +150,7 @@ func (r *Runtime) Setup(ctx context.Context, tool types.Tool, dataRoot, toolSour
152
150
}
153
151
}
154
152
155
- if err := r .runPip (ctx , tool , toolSource , binPath , append (env , newEnv ... )); err != nil {
156
- return nil , err
157
- }
158
-
159
- return newEnv , nil
153
+ return r .runPip (ctx , tool , toolSource , binPath , append (env , newEnv ... ))
160
154
}
161
155
162
156
func readRelease () (result []Release ) {
@@ -177,28 +171,52 @@ func (r *Runtime) getReleaseAndDigest() (string, string, error) {
177
171
return "" , "" , fmt .Errorf ("failed to find an python runtime for %s" , r .Version )
178
172
}
179
173
180
- func (r * Runtime ) runPip (ctx context.Context , tool types.Tool , toolSource , binDir string , env []string ) error {
174
+ func (r * Runtime ) GetHash (tool types.Tool ) (string , error ) {
175
+ if ! tool .Source .IsGit () && tool .WorkingDir != "" {
176
+ if _ , ok := tool .MetaData [requirementsTxt ]; ok {
177
+ return "" , nil
178
+ }
179
+ for _ , req := range []string {gptscriptRequirementsTxt , requirementsTxt } {
180
+ reqFile := filepath .Join (tool .WorkingDir , req )
181
+ if s , err := os .Stat (reqFile ); err == nil && ! s .IsDir () {
182
+ return hash .Digest (tool .WorkingDir + s .ModTime ().String ())[:7 ], nil
183
+ }
184
+ }
185
+ }
186
+
187
+ return "" , nil
188
+ }
189
+
190
+ func (r * Runtime ) runPip (ctx context.Context , tool types.Tool , toolSource , binDir string , env []string ) ([]string , error ) {
181
191
log .InfofCtx (ctx , "Running pip in %s" , toolSource )
182
192
if content , ok := tool .MetaData [requirementsTxt ]; ok {
183
193
reqFile := filepath .Join (toolSource , requirementsTxt )
184
194
if err := os .WriteFile (reqFile , []byte (content + "\n " ), 0644 ); err != nil {
185
- return err
195
+ return nil , err
186
196
}
187
197
cmd := debugcmd .New (ctx , uvBin (binDir ), "pip" , "install" , "-r" , reqFile )
188
198
cmd .Env = env
189
- return cmd .Run ()
199
+ return env , cmd .Run ()
190
200
}
191
201
192
- for _ , req := range []string {"requirements-gptscript.txt" , requirementsTxt } {
193
- reqFile := filepath .Join (toolSource , req )
202
+ reqPath := toolSource
203
+ if ! tool .Source .IsGit () {
204
+ if tool .WorkingDir == "" {
205
+ return env , nil
206
+ }
207
+ reqPath = tool .WorkingDir
208
+ }
209
+
210
+ for _ , req := range []string {gptscriptRequirementsTxt , requirementsTxt } {
211
+ reqFile := filepath .Join (reqPath , req )
194
212
if s , err := os .Stat (reqFile ); err == nil && ! s .IsDir () {
195
213
cmd := debugcmd .New (ctx , uvBin (binDir ), "pip" , "install" , "-r" , reqFile )
196
214
cmd .Env = env
197
- return cmd .Run ()
215
+ return env , cmd .Run ()
198
216
}
199
217
}
200
218
201
- return nil
219
+ return env , nil
202
220
}
203
221
204
222
func (r * Runtime ) setupUV (ctx context.Context , tmp string ) error {
0 commit comments