diff options
| author | ewy <ewy0@protonmail.com> | 2026-04-14 16:37:17 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-04-14 16:37:17 +0200 |
| commit | 45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch) | |
| tree | 852ebc3a0112c94dc9726d0b27ab057bf6383660 /runner/python/filetarget.go | |
i have to commit at some point!
Diffstat (limited to 'runner/python/filetarget.go')
| -rw-r--r-- | runner/python/filetarget.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/runner/python/filetarget.go b/runner/python/filetarget.go new file mode 100644 index 0000000..6793f4b --- /dev/null +++ b/runner/python/filetarget.go @@ -0,0 +1,51 @@ +package python + +import ( + "os/exec" + "path/filepath" + "pik/model" + "pik/runner" +) + +type FileTarget struct { + runner.BaseTarget + File string +} + +type HydratedFileTarget struct { + runner.BaseHydration[*FileTarget] +} + +func (h *HydratedFileTarget) Icon() string { + return "\uE606" +} + +func (p *FileTarget) 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 *FileTarget) Sub() []string { + return nil +} + +func (p *FileTarget) Label() string { + return p.Full +} + +func (p *FileTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &HydratedFileTarget{ + BaseHydration: runner.Hydrated(p), + }, nil +} |
