summaryrefslogtreecommitdiff
path: root/runner/python/runner.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
committerewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
commit45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch)
tree852ebc3a0112c94dc9726d0b27ab057bf6383660 /runner/python/runner.go
i have to commit at some point!
Diffstat (limited to 'runner/python/runner.go')
-rw-r--r--runner/python/runner.go86
1 files changed, 86 insertions, 0 deletions
diff --git a/runner/python/runner.go b/runner/python/runner.go
new file mode 100644
index 0000000..b06d8ab
--- /dev/null
+++ b/runner/python/runner.go
@@ -0,0 +1,86 @@
+package python
+
+import (
+ "errors"
+ "io/fs"
+ "os/exec"
+ "path/filepath"
+ "pik/identity"
+ "pik/model"
+ "pik/runner"
+)
+
+type python struct {
+ Venvs map[string]string
+ Uv string
+ System string
+}
+
+func (p python) Init() error {
+ uv, err := exec.LookPath("uv")
+ if err != nil && !errors.Is(err, exec.ErrNotFound) {
+ return err
+ }
+ p.Uv = uv
+ sys, err := exec.LookPath("python3")
+ if err == nil {
+ p.System = sys
+ }
+ return err
+}
+
+func (p python) Hydrate(target model.Target) (model.HydratedTarget, error) {
+ //TODO implement me
+ panic("implement me")
+}
+
+func (p python) Wants(fs fs.FS, file string, entry fs.DirEntry) (bool, error) {
+ return !entry.IsDir() && filepath.Ext(entry.Name()) == ".py", nil
+}
+
+func (p python) VenvFor(src *model.Source) string {
+ venvPath := p.Venvs[src.Path]
+ if venvPath != "" {
+ return venvPath
+ }
+ return ""
+}
+
+func (p python) PyFor(src *model.Source) []string {
+ if p.Uv != "" {
+ return []string{p.Uv, "run", "--"}
+ }
+ if venv := p.VenvFor(src); venv != "" {
+ return []string{filepath.Join(src.Path, venv, "bin", "python")}
+ }
+ return nil
+}
+
+func (p python) CreateProjTarget(name string, cmd string) model.Target {
+ return &ProjTarget{
+ BaseTarget: runner.BaseTarget{
+ Identity: identity.New(name),
+ },
+ Cmd: cmd,
+ }
+}
+
+func (p python) CreateTarget(fs fs.FS, source string, file string, entry fs.DirEntry) (model.Target, error) {
+ _, filename := filepath.Split(file)
+ return &FileTarget{
+ BaseTarget: runner.BaseTarget{
+ Identity: identity.New(filename),
+ MyTags: model.TagsFromFilename(filename),
+ },
+ File: file,
+ }, nil
+}
+
+var VenvPaths = []string{
+ ".venv",
+ "venv",
+}
+
+var Python = &python{
+ Venvs: map[string]string{},
+}