@@ -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
}
@@ -177,6 +175,22 @@ func (r *Runtime) getReleaseAndDigest() (string, string, error) {
177
175
return "" , "" , fmt .Errorf ("failed to find an python runtime for %s" , r .Version )
178
176
}
179
177
178
+ func (r * Runtime ) GetHash (tool types.Tool ) (string , error ) {
179
+ if ! tool .Source .IsGit () && tool .WorkingDir != "" {
180
+ if _ , ok := tool .MetaData [requirementsTxt ]; ok {
181
+ return "" , nil
182
+ }
183
+ for _ , req := range []string {gptscriptRequirementsTxt , requirementsTxt } {
184
+ reqFile := filepath .Join (tool .WorkingDir , req )
185
+ if s , err := os .Stat (reqFile ); err == nil && ! s .IsDir () {
186
+ return hash .Digest (tool .WorkingDir + s .ModTime ().String ())[:7 ], nil
187
+ }
188
+ }
189
+ }
190
+
191
+ return "" , nil
192
+ }
193
+
180
194
func (r * Runtime ) runPip (ctx context.Context , tool types.Tool , toolSource , binDir string , env []string ) error {
181
195
log .InfofCtx (ctx , "Running pip in %s" , toolSource )
182
196
if content , ok := tool .MetaData [requirementsTxt ]; ok {
@@ -189,8 +203,16 @@ func (r *Runtime) runPip(ctx context.Context, tool types.Tool, toolSource, binDi
189
203
return cmd .Run ()
190
204
}
191
205
192
- for _ , req := range []string {"requirements-gptscript.txt" , requirementsTxt } {
193
- reqFile := filepath .Join (toolSource , req )
206
+ reqPath := toolSource
207
+ if ! tool .Source .IsGit () {
208
+ if tool .WorkingDir == "" {
209
+ return nil
210
+ }
211
+ reqPath = tool .WorkingDir
212
+ }
213
+
214
+ for _ , req := range []string {gptscriptRequirementsTxt , requirementsTxt } {
215
+ reqFile := filepath .Join (reqPath , req )
194
216
if s , err := os .Stat (reqFile ); err == nil && ! s .IsDir () {
195
217
cmd := debugcmd .New (ctx , uvBin (binDir ), "pip" , "install" , "-r" , reqFile )
196
218
cmd .Env = env
0 commit comments