summaryrefslogtreecommitdiff
path: root/runner
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-29 01:30:12 +0200
committerewy <ewy0@protonmail.com>2026-04-29 01:30:12 +0200
commit2b28ee919614d5ddaceda26ce488a0ca4c851cb3 (patch)
treedf9a9af3f6b37165c9522eefea8456aa1baea9d5 /runner
parent19f68366eb4a2c01f801b29585fd0a36bdf47488 (diff)
simplify the contracts
Diffstat (limited to 'runner')
-rw-r--r--runner/base.go51
-rw-r--r--runner/gnumake/make.go9
-rw-r--r--runner/gnumake/target.go12
-rw-r--r--runner/just/just.go9
-rw-r--r--runner/just/target.go8
-rw-r--r--runner/python/file.go22
-rw-r--r--runner/python/indexer.go4
-rw-r--r--runner/python/proj.go12
-rw-r--r--runner/python/runner.go3
-rw-r--r--runner/shell/hydrated.go4
-rw-r--r--runner/shell/target.go4
11 files changed, 74 insertions, 64 deletions
diff --git a/runner/base.go b/runner/base.go
index 3f405a5..c9825ae 100644
--- a/runner/base.go
+++ b/runner/base.go
@@ -1,7 +1,6 @@
package runner
import (
- "os/exec"
"pik/identity"
"pik/model"
)
@@ -35,58 +34,22 @@ func (b *BaseTarget) Invocation(src *model.Source) []string {
func Hydrated[T model.Target](in T) BaseHydration[T] {
return BaseHydration[T]{
- BaseTarget: in,
+ Self: in,
}
}
type BaseHydration[T model.Target] struct {
- BaseTarget T
+ Self T
}
-func (b BaseHydration[T]) Matches(input string) bool {
- return b.BaseTarget.Matches(input)
-}
-
-func (b BaseHydration[T]) Create(s *model.Source) *exec.Cmd {
- return b.BaseTarget.Create(s)
-}
-
-func (b BaseHydration[T]) Sub() []string {
- return b.BaseTarget.Sub()
-}
-
-func (b BaseHydration[T]) Label() string {
- return b.BaseTarget.Label()
-}
-
-func (b BaseHydration[T]) Hydrate(src *model.Source) (model.HydratedTarget, error) {
- return b, nil
-}
-
-func (b BaseHydration[T]) Invocation(src *model.Source) []string {
- return b.BaseTarget.Invocation(src)
-}
-
-func (b BaseHydration[T]) Visible() bool {
- return b.BaseTarget.Visible()
-}
-
-func (b BaseHydration[T]) Tags() model.Tags {
- return b.BaseTarget.Tags()
-}
-
-func (b BaseHydration[T]) ShortestId() string {
- return b.BaseTarget.ShortestId()
-}
-
-func (b BaseHydration[T]) Icon() string {
- return " "
+func (b *BaseHydration[T]) Icon() string {
+ return ""
}
-func (b BaseHydration[T]) Description() string {
+func (b *BaseHydration[T]) Description() string {
return ""
}
-func (b BaseHydration[T]) Target() model.Target {
- return b.BaseTarget
+func (b *BaseHydration[T]) Target() model.Target {
+ return b.Self
}
diff --git a/runner/gnumake/make.go b/runner/gnumake/make.go
index 96e7efb..e04f927 100644
--- a/runner/gnumake/make.go
+++ b/runner/gnumake/make.go
@@ -4,6 +4,7 @@ import (
"errors"
"io/fs"
"os/exec"
+ "path/filepath"
"pik/identity"
"pik/model"
"pik/runner"
@@ -13,10 +14,13 @@ import (
)
type gnumake struct {
- path string
+ path string
+ files map[string]string
}
-var Indexer = &gnumake{}
+var Indexer = &gnumake{
+ files: make(map[string]string),
+}
var Makefiles = []string{
"Makefile",
@@ -32,6 +36,7 @@ func (m *gnumake) Index(path string, f fs.FS, _ []model.Runner) ([]model.Target,
makefile := ""
for _, e := range entries {
if !e.IsDir() && slices.Contains(Makefiles, strings.ToLower(e.Name())) {
+ m.files[path] = filepath.Join(path, e.Name())
content, err := fs.ReadFile(f, e.Name())
if err != nil {
return nil, err
diff --git a/runner/gnumake/target.go b/runner/gnumake/target.go
index 2f909bb..bde09f8 100644
--- a/runner/gnumake/target.go
+++ b/runner/gnumake/target.go
@@ -12,6 +12,10 @@ type Target struct {
Description string
}
+func (j *Target) File(src *model.Source) string {
+ return Indexer.files[src.Path]
+}
+
func (j *Target) Create(s *model.Source) *exec.Cmd {
return exec.Command(Indexer.path, j.Identity.Full)
}
@@ -38,10 +42,10 @@ type Hydrated struct {
runner.BaseHydration[*Target]
}
-func (h *Hydrated) Icon() string {
- return "\uE673"
+func (h *Hydrated) Description(src *model.HydratedSource) string {
+ return h.Self.Description
}
-func (h *Hydrated) Description() string {
- return h.BaseTarget.Description
+func (h *Hydrated) Icon() string {
+ return "\uE673"
}
diff --git a/runner/just/just.go b/runner/just/just.go
index 7d6bb92..377553e 100644
--- a/runner/just/just.go
+++ b/runner/just/just.go
@@ -4,6 +4,7 @@ import (
"errors"
"io/fs"
"os/exec"
+ "path/filepath"
"pik/identity"
"pik/model"
"pik/runner"
@@ -11,10 +12,13 @@ import (
)
type just struct {
- path string
+ path string
+ files map[string]string
}
-var Indexer = &just{}
+var Indexer = &just{
+ files: make(map[string]string),
+}
func (j *just) Index(path string, f fs.FS, runners []model.Runner) ([]model.Target, error) {
@@ -25,6 +29,7 @@ func (j *just) Index(path string, f fs.FS, runners []model.Runner) ([]model.Targ
hasJustfile := false
for _, e := range entries {
if !e.IsDir() && strings.ToLower(e.Name()) == "justfile" {
+ j.files[path] = filepath.Join(path, e.Name())
hasJustfile = true
break
}
diff --git a/runner/just/target.go b/runner/just/target.go
index ca33b6b..9319e73 100644
--- a/runner/just/target.go
+++ b/runner/just/target.go
@@ -11,6 +11,10 @@ type Target struct {
Category string
}
+func (j Target) File(src *model.Source) string {
+ return Indexer.files[src.Path]
+}
+
func (j Target) Create(s *model.Source) *exec.Cmd {
return exec.Command(Indexer.path, j.Identity.Full)
}
@@ -36,6 +40,10 @@ type Hydrated struct {
runner.BaseHydration[*Target]
}
+func (h *Hydrated) Description(src *model.HydratedSource) string {
+ return ""
+}
+
func (h *Hydrated) Icon() string {
return "\uF039"
}
diff --git a/runner/python/file.go b/runner/python/file.go
index f8b6c2e..4734b0a 100644
--- a/runner/python/file.go
+++ b/runner/python/file.go
@@ -3,19 +3,33 @@ package python
import (
"os/exec"
"path/filepath"
+ "pik/describe"
"pik/model"
"pik/runner"
+ "pik/spool"
)
type File struct {
runner.BaseTarget
- File string
+ Path string
+}
+
+func (p *File) File(src *model.Source) string {
+ return p.Path
}
type HydratedFileTarget struct {
runner.BaseHydration[*File]
}
+func (h *HydratedFileTarget) Description(src *model.HydratedSource) string {
+ desc, err := describe.Describe(h.Target(), h.Self.Path)
+ if err != nil {
+ spool.Warn("%v\n", err)
+ }
+ return desc
+}
+
func (h *HydratedFileTarget) Icon() string {
return "\uE606"
}
@@ -23,15 +37,15 @@ func (h *HydratedFileTarget) Icon() string {
func (p *File) Create(s *model.Source) *exec.Cmd {
var cmd []string
if Python.Uv != "" {
- cmd = []string{Python.Uv, "run", "--", p.File}
+ cmd = []string{Python.Uv, "run", "--", p.Path}
} else if venv := Python.VenvFor(s); venv != "" {
- cmd = []string{filepath.Join(s.Path, venv, "bin", "python3"), p.File}
+ cmd = []string{filepath.Join(s.Path, venv, "bin", "python3"), p.Path}
} else {
sysPath, err := exec.LookPath("python3")
if err != nil {
return nil
}
- cmd = []string{sysPath, p.File}
+ cmd = []string{sysPath, p.Path}
}
return exec.Command(cmd[0], cmd[1:]...)
}
diff --git a/runner/python/indexer.go b/runner/python/indexer.go
index 3a61f7e..98502ca 100644
--- a/runner/python/indexer.go
+++ b/runner/python/indexer.go
@@ -14,7 +14,7 @@ type pyproj struct {
}
}
-func (p python) Index(path string, f fs.FS, runners []model.Runner) ([]model.Target, error) {
+func (p *python) Index(path string, f fs.FS, runners []model.Runner) ([]model.Target, error) {
for _, pt := range VenvPaths {
if stat, err := fs.Stat(f, filepath.Join(pt)); err == nil {
if stat.IsDir() {
@@ -29,6 +29,8 @@ func (p python) Index(path string, f fs.FS, runners []model.Runner) ([]model.Tar
return nil, err
}
+ p.files[path] = filepath.Join(path, "pyproject.toml")
+
pp := &pyproj{}
err = toml.Unmarshal(content, pp)
diff --git a/runner/python/proj.go b/runner/python/proj.go
index 9a711bd..1230b1c 100644
--- a/runner/python/proj.go
+++ b/runner/python/proj.go
@@ -12,16 +12,20 @@ type Project struct {
Cmd string
}
+func (p *Project) File(src *model.Source) string {
+ return Python.files[src.Path]
+}
+
type Hydrated struct {
runner.BaseHydration[*Project]
}
-func (h *Hydrated) Icon() string {
- return "\uE606"
+func (h *Hydrated) Description(src *model.HydratedSource) string {
+ return h.Self.Cmd
}
-func (h *Hydrated) Description() string {
- return h.BaseTarget.Cmd
+func (h *Hydrated) Icon() string {
+ return "\uE606"
}
func (p *Project) Create(s *model.Source) *exec.Cmd {
diff --git a/runner/python/runner.go b/runner/python/runner.go
index 2293336..73192e6 100644
--- a/runner/python/runner.go
+++ b/runner/python/runner.go
@@ -14,6 +14,7 @@ type python struct {
Venvs map[string]string
Uv string
System string
+ files map[string]string
}
func (p python) Init() error {
@@ -72,7 +73,7 @@ func (p python) CreateTarget(fs fs.FS, source string, file string, entry fs.DirE
Identity: identity.New(filename),
MyTags: model.TagsFromFilename(filename),
},
- File: file,
+ Path: file,
}, nil
}
diff --git a/runner/shell/hydrated.go b/runner/shell/hydrated.go
index 1ecce51..dcd28be 100644
--- a/runner/shell/hydrated.go
+++ b/runner/shell/hydrated.go
@@ -16,8 +16,8 @@ func (h *Hydrated) Icon() string {
return "\uF489"
}
-func (h *Hydrated) Description() string {
- desc, err := describe.Describe(h.BaseTarget, h.BaseTarget.Script)
+func (h *Hydrated) Description(src *model.HydratedSource) string {
+ desc, err := describe.Describe(h.Target(), h.Target().File(src.Source))
if err != nil {
spool.Warn("%v\n", err)
return ""
diff --git a/runner/shell/target.go b/runner/shell/target.go
index 8422cf0..189bcb7 100644
--- a/runner/shell/target.go
+++ b/runner/shell/target.go
@@ -12,6 +12,10 @@ type Target struct {
Script string
}
+func (s *Target) File(src *model.Source) string {
+ return s.Script
+}
+
func (s *Target) String() string {
return s.Label()
}