Skip to content

Commit

Permalink
Refactor: Rename SetPathCustom -> SetOutFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
samuell committed Jul 19, 2018
1 parent 0bfc69a commit f78ac4a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions docs/writing_workflows.md
Expand Up @@ -103,10 +103,10 @@ would write like this:

```go
// Configure output file path formatters for the processes created above
hello.SetPathCustom("out", func(t *sp.Task) string {
hello.SetOutFunc("out", func(t *sp.Task) string {
return "hello.txt"
})
world.SetPathCustom("out", func(t *sp.Task) string {
world.SetOutFunc("out", func(t *sp.Task) string {
return strings.Replace(t.InPath("in"), ".txt", "_world.txt", -1)
})
```
Expand All @@ -127,7 +127,7 @@ functions in a loop, that uses a shared variable, like this:
```go
for _, val := range []string{"foo", "bar"} {
proc := scipipe.NewProc(val + "_proc", "cat {p:val} > {o:out}")
proc.SetPathCustom("out", func(t *sp.Task) string {
proc.SetOutFunc("out", func(t *sp.Task) string {
return val + ".txt"
})
}
Expand All @@ -145,7 +145,7 @@ generally recommended:
for _, val := range []string{"foo", "bar"} {
proc := scipipe.NewProc(val + "_proc", "cat {p:val} > {o:out}")
val := val // <- Here we create a new copy of the variable
proc.SetPathCustom("out", func(t *sp.Task) string {
proc.SetOutFunc("out", func(t *sp.Task) string {
return val + ".txt"
})
}
Expand All @@ -156,7 +156,7 @@ generally recommended:
```go
for _, val := range []string{"foo", "bar"} {
proc := scipipe.NewProc(val + "_proc", "cat {p:val} > {o:out}")
proc.SetPathCustom("out", func(t *sp.Task) string {
proc.SetOutFunc("out", func(t *sp.Task) string {
return t.Param("val") + ".txt" // Access param via the task (`t`)
})
}
Expand Down
4 changes: 2 additions & 2 deletions port_test.go
Expand Up @@ -168,10 +168,10 @@ func TestConnectBackwards(t *testing.T) {
wf := NewWorkflow("TestConnectBackwards", 16)

p1 := wf.NewProc("p1", "echo foo > {o:foo}")
p1.SetPathCustom("foo", func(t *Task) string { return "foo.txt" })
p1.SetOutFunc("foo", func(t *Task) string { return "foo.txt" })

p2 := wf.NewProc("p2", "sed 's/foo/bar/g' {i:foo} > {o:bar}")
p2.SetPathCustom("bar", func(t *Task) string { return t.InPath("foo") + ".bar.txt" })
p2.SetOutFunc("bar", func(t *Task) string { return t.InPath("foo") + ".bar.txt" })

p1.Out("foo").To(p2.In("foo"))

Expand Down
6 changes: 3 additions & 3 deletions process.go
Expand Up @@ -214,7 +214,7 @@ func (p *Process) SetOut(outPortName string, pathPattern string) {
if _, ok := p.outPorts[outPortName]; !ok {
p.InitOutPort(p, outPortName)
}
p.SetPathCustom(outPortName, func(t *Task) string {
p.SetOutFunc(outPortName, func(t *Task) string {
path := pathPattern // Avoiding reusing the same variable in multiple instances of this func

r := getShellCommandPlaceHolderRegex()
Expand Down Expand Up @@ -269,9 +269,9 @@ func (p *Process) SetOut(outPortName string, pathPattern string) {
})
}

// SetPathCustom takes a function which produces a file path based on data
// SetOutFunc takes a function which produces a file path based on data
// available in *Task, such as concrete file paths and parameter values,
func (p *Process) SetPathCustom(outPortName string, pathFmtFunc func(task *Task) (path string)) {
func (p *Process) SetOutFunc(outPortName string, pathFmtFunc func(task *Task) (path string)) {
p.PathFormatters[outPortName] = pathFmtFunc
}

Expand Down
8 changes: 4 additions & 4 deletions workflow_test.go
Expand Up @@ -148,7 +148,7 @@ func getWorkflowForTestRunToProc(wfName string) *Workflow {
bar.SetOut("out", "/tmp/bar.txt")

mrg := wf.NewProc("mrg", "cat {i:in1} {i:in2} > {o:mgd}")
mrg.SetPathCustom("mgd", func(tk *Task) string {
mrg.SetOutFunc("mgd", func(tk *Task) string {
return tk.InPath("in1") + "." + filepath.Base(tk.InPath("in2"))
})
mrg.In("in1").From(foo.Out("out"))
Expand All @@ -167,7 +167,7 @@ func TestBasicRun(t *testing.T) {

p1 := wf.NewProc("p1", "echo foo > {o:foo}")
assertIsType(t, p1.Out("foo"), NewOutPort("foo"))
p1.SetPathCustom("foo", func(t *Task) string { return "foo.txt" })
p1.SetOutFunc("foo", func(t *Task) string { return "foo.txt" })

p2 := wf.NewProc("p2", "sed 's/foo/bar/g' {i:foo} > {o:bar}")
assertIsType(t, p2.In("foo"), NewInPort("foo"))
Expand Down Expand Up @@ -260,7 +260,7 @@ func TestDontOverWriteExistingOutputs(t *testing.T) {
// Run again with different output
wf2 := NewWorkflow("TestDontOverWriteExistingOutputsWf2", 16)
tsk = wf2.NewProc("tsk", "echo hej > {o:hej2}")
tsk.SetPathCustom("hej2", func(task *Task) string { return f })
tsk.SetOutFunc("hej2", func(task *Task) string { return f })
prt = wf2.NewProc("prt", "cat {i:in1} > {o:done}")
prt.SetOut("done", "{i:in1}.done.txt")
prt.In("in1").From(tsk.Out("hej2"))
Expand Down Expand Up @@ -467,7 +467,7 @@ func TestReceiveBothIPsAndParams(t *testing.T) {
for _, str := range strs {
add := wf.NewProc("add_"+str, `echo {i:infile} {p:param} > {o:out}`)
str := str
add.SetPathCustom("out", func(t *Task) string {
add.SetOutFunc("out", func(t *Task) string {
return t.InPath("infile") + "." + str + ".txt"
})
add.InParam("param").From(params.Out())
Expand Down

0 comments on commit f78ac4a

Please sign in to comment.