diff options
Diffstat (limited to 'runner/python/file.go')
| -rw-r--r-- | runner/python/file.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/runner/python/file.go b/runner/python/file.go new file mode 100644 index 0000000..f8b6c2e --- /dev/null +++ b/runner/python/file.go @@ -0,0 +1,51 @@ +package python + +import ( + "os/exec" + "path/filepath" + "pik/model" + "pik/runner" +) + +type File struct { + runner.BaseTarget + File string +} + +type HydratedFileTarget struct { + runner.BaseHydration[*File] +} + +func (h *HydratedFileTarget) Icon() string { + return "\uE606" +} + +func (p *File) Create(s *model.Source) *exec.Cmd { + var cmd []string + if Python.Uv != "" { + cmd = []string{Python.Uv, "run", "--", p.File} + } else if venv := Python.VenvFor(s); venv != "" { + cmd = []string{filepath.Join(s.Path, venv, "bin", "python3"), p.File} + } else { + sysPath, err := exec.LookPath("python3") + if err != nil { + return nil + } + cmd = []string{sysPath, p.File} + } + return exec.Command(cmd[0], cmd[1:]...) +} + +func (p *File) Sub() []string { + return nil +} + +func (p *File) Label() string { + return p.Full +} + +func (p *File) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &HydratedFileTarget{ + BaseHydration: runner.Hydrated(p), + }, nil +} |
