@@ -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 }
@@ -152,11 +150,7 @@ func (r *Runtime) Setup(ctx context.Context, tool types.Tool, dataRoot, toolSour
152150 }
153151 }
154152
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 ... ))
160154}
161155
162156func readRelease () (result []Release ) {
@@ -177,28 +171,52 @@ func (r *Runtime) getReleaseAndDigest() (string, string, error) {
177171 return "" , "" , fmt .Errorf ("failed to find an python runtime for %s" , r .Version )
178172}
179173
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 (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 ) {
181191 log .InfofCtx (ctx , "Running pip in %s" , toolSource )
182192 if content , ok := tool .MetaData [requirementsTxt ]; ok {
183193 reqFile := filepath .Join (toolSource , requirementsTxt )
184194 if err := os .WriteFile (reqFile , []byte (content + "\n " ), 0644 ); err != nil {
185- return err
195+ return nil , err
186196 }
187197 cmd := debugcmd .New (ctx , uvBin (binDir ), "pip" , "install" , "-r" , reqFile )
188198 cmd .Env = env
189- return cmd .Run ()
199+ return env , cmd .Run ()
190200 }
191201
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 )
194212 if s , err := os .Stat (reqFile ); err == nil && ! s .IsDir () {
195213 cmd := debugcmd .New (ctx , uvBin (binDir ), "pip" , "install" , "-r" , reqFile )
196214 cmd .Env = env
197- return cmd .Run ()
215+ return env , cmd .Run ()
198216 }
199217 }
200218
201- return nil
219+ return env , nil
202220}
203221
204222func (r * Runtime ) setupUV (ctx context.Context , tmp string ) error {
0 commit comments