@@ -24,8 +24,9 @@ import (
2424var releasesData []byte
2525
2626const (
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"
2930)
3031
3132type Release struct {
@@ -47,10 +48,7 @@ func (r *Runtime) ID() string {
4748 return "python" + r .Version
4849}
4950
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 {
5452 if runtimeEnv .Matches (cmd , r .ID ()) {
5553 return true
5654 }
@@ -177,6 +175,22 @@ func (r *Runtime) getReleaseAndDigest() (string, string, error) {
177175 return "" , "" , fmt .Errorf ("failed to find an python runtime for %s" , r .Version )
178176}
179177
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+
180194func (r * Runtime ) runPip (ctx context.Context , tool types.Tool , toolSource , binDir string , env []string ) error {
181195 log .InfofCtx (ctx , "Running pip in %s" , toolSource )
182196 if content , ok := tool .MetaData [requirementsTxt ]; ok {
@@ -189,8 +203,16 @@ func (r *Runtime) runPip(ctx context.Context, tool types.Tool, toolSource, binDi
189203 return cmd .Run ()
190204 }
191205
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 )
194216 if s , err := os .Stat (reqFile ); err == nil && ! s .IsDir () {
195217 cmd := debugcmd .New (ctx , uvBin (binDir ), "pip" , "install" , "-r" , reqFile )
196218 cmd .Env = env
0 commit comments