From f6963b1c451afcb2f0d0104f38178235e52f8b63 Mon Sep 17 00:00:00 2001 From: ewy Date: Tue, 14 Apr 2026 20:13:13 +0200 Subject: remove all name repetition --- runner/python/file.go | 51 +++++++++++++++++++++++++++++++++++++++++++++ runner/python/filetarget.go | 51 --------------------------------------------- runner/python/indexer.go | 4 ++-- runner/python/proj.go | 49 +++++++++++++++++++++++++++++++++++++++++++ runner/python/projtarget.go | 49 ------------------------------------------- runner/python/runner.go | 4 ++-- 6 files changed, 104 insertions(+), 104 deletions(-) create mode 100644 runner/python/file.go delete mode 100644 runner/python/filetarget.go create mode 100644 runner/python/proj.go delete mode 100644 runner/python/projtarget.go (limited to 'runner/python') 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 +} diff --git a/runner/python/filetarget.go b/runner/python/filetarget.go deleted file mode 100644 index 6793f4b..0000000 --- a/runner/python/filetarget.go +++ /dev/null @@ -1,51 +0,0 @@ -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 -} diff --git a/runner/python/indexer.go b/runner/python/indexer.go index d0dd4e3..3a61f7e 100644 --- a/runner/python/indexer.go +++ b/runner/python/indexer.go @@ -8,7 +8,7 @@ import ( "pik/model" ) -type Pyproj struct { +type pyproj struct { Project struct { Scripts map[string]string } @@ -29,7 +29,7 @@ func (p python) Index(path string, f fs.FS, runners []model.Runner) ([]model.Tar return nil, err } - pp := &Pyproj{} + pp := &pyproj{} err = toml.Unmarshal(content, pp) if err != nil { diff --git a/runner/python/proj.go b/runner/python/proj.go new file mode 100644 index 0000000..9a711bd --- /dev/null +++ b/runner/python/proj.go @@ -0,0 +1,49 @@ +package python + +import ( + "os/exec" + "path/filepath" + "pik/model" + "pik/runner" +) + +type Project struct { + runner.BaseTarget + Cmd string +} + +type Hydrated struct { + runner.BaseHydration[*Project] +} + +func (h *Hydrated) Icon() string { + return "\uE606" +} + +func (h *Hydrated) Description() string { + return h.BaseTarget.Cmd +} + +func (p *Project) Create(s *model.Source) *exec.Cmd { + var cmd []string + if Python.Uv != "" { + cmd = []string{Python.Uv, "run", "--", p.Cmd} + } else if venv := Python.VenvFor(s); venv != "" { + cmd = []string{filepath.Join(s.Path, venv, "bin", "python"), p.Cmd} + } + return exec.Command(cmd[0], cmd[1:]...) +} + +func (p *Project) Sub() []string { + return nil +} + +func (p *Project) Label() string { + return p.Cmd +} + +func (p *Project) Hydrate(src *model.Source) (model.HydratedTarget, error) { + return &Hydrated{ + BaseHydration: runner.Hydrated(p), + }, nil +} diff --git a/runner/python/projtarget.go b/runner/python/projtarget.go deleted file mode 100644 index c7422b4..0000000 --- a/runner/python/projtarget.go +++ /dev/null @@ -1,49 +0,0 @@ -package python - -import ( - "os/exec" - "path/filepath" - "pik/model" - "pik/runner" -) - -type ProjTarget struct { - runner.BaseTarget - Cmd string -} - -type HydratedProjTarget struct { - runner.BaseHydration[*ProjTarget] -} - -func (h *HydratedProjTarget) Icon() string { - return "\uE606" -} - -func (h *HydratedProjTarget) Description() string { - return h.BaseTarget.Cmd -} - -func (p *ProjTarget) Create(s *model.Source) *exec.Cmd { - var cmd []string - if Python.Uv != "" { - cmd = []string{Python.Uv, "run", "--", p.Cmd} - } else if venv := Python.VenvFor(s); venv != "" { - cmd = []string{filepath.Join(s.Path, venv, "bin", "python"), p.Cmd} - } - return exec.Command(cmd[0], cmd[1:]...) -} - -func (p *ProjTarget) Sub() []string { - return nil -} - -func (p *ProjTarget) Label() string { - return p.Cmd -} - -func (p *ProjTarget) Hydrate(src *model.Source) (model.HydratedTarget, error) { - return &HydratedProjTarget{ - BaseHydration: runner.Hydrated(p), - }, nil -} diff --git a/runner/python/runner.go b/runner/python/runner.go index b06d8ab..2293336 100644 --- a/runner/python/runner.go +++ b/runner/python/runner.go @@ -57,7 +57,7 @@ func (p python) PyFor(src *model.Source) []string { } func (p python) CreateProjTarget(name string, cmd string) model.Target { - return &ProjTarget{ + return &Project{ BaseTarget: runner.BaseTarget{ Identity: identity.New(name), }, @@ -67,7 +67,7 @@ func (p python) CreateProjTarget(name string, cmd string) model.Target { func (p python) CreateTarget(fs fs.FS, source string, file string, entry fs.DirEntry) (model.Target, error) { _, filename := filepath.Split(file) - return &FileTarget{ + return &File{ BaseTarget: runner.BaseTarget{ Identity: identity.New(filename), MyTags: model.TagsFromFilename(filename), -- cgit v1.3