summaryrefslogtreecommitdiff
path: root/runner/python
diff options
context:
space:
mode:
Diffstat (limited to 'runner/python')
-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
4 files changed, 31 insertions, 10 deletions
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
}