Skip to content

Commit 713b0bd

Browse files
author
Aaron Crow
committed
Merge branch 'release/v0.1.6'
2 parents 5b57add + e58a217 commit 713b0bd

File tree

17 files changed

+899
-20
lines changed

17 files changed

+899
-20
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.6
2+
3+
* Add [a Clojure frontend](https://github.com/Factual/drake/wiki/A-Clojure-Frontend-to-Drake) (thanks morrifeldman)
4+
* bugfix: [#129](https://github.com/Factual/drake/issues/129) (thanks calfzhou)
5+
16
## 0.1.5
27

38
* bugfix: [#98](https://github.com/Factual/drake/issues/98) --help now doesn't run workflow (thanks marshallshen)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ We've not tested it on other operating systems.
2626

2727
You can build Drake from source, which is the preferred way to run the most
2828
up-to-date version, or you can
29-
[download a prebuilt uberjar](https://docs.google.com/uc?export=download&confirm=0H_c&id=0B2xtKcFEL6wwc28ybDFQUWZBR3c)
29+
[download a prebuilt uberjar](https://docs.google.com/uc?export=download&confirm=nT8F&id=0B2xtKcFEL6wwWnRzVzRZcGFFaWc)
30+
3031
,which may not be the most recent version of Drake.
3132

3233
Following are instructions for building from source. Drake is a Clojure project, so you will need to have [leiningen](https://github.com/technomancy/leiningen).

demos/clj-frontend/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/target
2+
/classes
3+
/checkouts
4+
pom.xml
5+
pom.xml.asc
6+
*.jar
7+
*.class
8+
/.lein-*
9+
/.nrepl-port

demos/clj-frontend/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# clj-frontend
2+
3+
A demonstration leiningen project showing how to use drake.clj-frontend.
4+
5+
## Usage
6+
7+
Run `lein repl` from within the root directory of this project to start a
8+
repl and interact with the workflows found in the `clj.frontend.demo`
9+
namespace in `/src/clj_frontend/demo.clj`.
10+
11+
For example, try these commands at the repl.
12+
13+
```clojure
14+
(run-workflow minimal-workflow :preview true)
15+
16+
(run-workflow minimal-workflow)
17+
18+
(run-workflow advanced-workflow :preview true)
19+
20+
(run-workflow advanced-workflow)
21+
22+
(run-workflow reduce-workflow :preview true)
23+
```
24+
25+
## License
26+
27+
Copyright © 2014
28+
29+
Distributed under the Eclipse Public License either version 1.0.

demos/clj-frontend/project.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(defproject clj-frontend "0.1.0-SNAPSHOT"
2+
:description "Demo project for drake.clj-frontend"
3+
:url "http://example.com/FIXME"
4+
:license {:name "Eclipse Public License"
5+
:url "http://www.eclipse.org/legal/epl-v10.html"}
6+
:dependencies [[org.clojure/clojure "1.5.1"]
7+
[factual/drake "0.1.5"]]
8+
:repl-options {:init-ns clj-frontend.demo})
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
(ns clj-frontend.demo
2+
(:use drake.clj-frontend))
3+
4+
;; minimal workflow example
5+
6+
;; Define a workflow called minimal-workflow.
7+
(def minimal-workflow
8+
(->
9+
(new-workflow) ;Create a new workflow
10+
(cmd-step ;Add a command step with the
11+
;following arguments
12+
["out"] ;Array of outputs
13+
[] ;Array of inputs
14+
["echo \"We are writing to a file here\" > $OUTPUT"] ;Array of commands
15+
)))
16+
17+
;; To see what will happen without running the workflow uncomment the
18+
;; following line or run it at in the repl:
19+
20+
;; (run-workflow minimal-workflow :preview true)
21+
22+
;; Use the following line to actually run the workflow
23+
24+
;; (run-workflow minimal-workflow)
25+
26+
27+
;; A more advanced example
28+
29+
(def advanced-workflow
30+
(->
31+
(new-workflow)
32+
(cmd-step
33+
["out1"
34+
"out2"]
35+
[]
36+
["echo \"This is the first output.\" > $OUTPUT0"
37+
"echo \"This is the second output.\" > $OUTPUT1"] ;multiple commands
38+
:timecheck false) ;options are key value pairs
39+
(method
40+
"test_method"
41+
["echo \"Here we are using a method.\" > $OUTPUT"])
42+
(method-step
43+
["out_method"] ;outputs
44+
[] ;inputs
45+
"test_method") ;method name
46+
(set-var "test_var" "TEST_VAR_VALUE") ;var name, var value
47+
(set-var "output_three" "out3")
48+
(cmd-step
49+
["$[output_three]"] ;inputs and outputs can have
50+
;$[XXX] substitution
51+
["out1" "%a_tag"] ;tags are allowed in inputs
52+
;and outputs
53+
;; $[XXX] substitution is allowed in commands.
54+
["echo \"This is the third output.\" > $OUTPUT"
55+
"echo \"test_var is set to $test_var - $[test_var].\" >> $OUTPUT"
56+
"echo \"The file $INPUT contains:\" | cat - $INPUT >> $[OUTPUT]"])))
57+
58+
;; (run-workflow advanced-workflow :preview true)
59+
;; (run-workflow advanced-workflow)
60+
61+
;; Example with reduce
62+
63+
;; Let's say you want to take several raw data sources from the
64+
;; internet and for each source you want to create a directory,
65+
;; download some data into it, and do several processing steps on the
66+
;; data. We will express this as a map called dir->url-map between the
67+
;; directory names we want to create and the raw data sources we want
68+
;; to process.
69+
70+
(def dir->url-map
71+
"Hash map of:
72+
Directory Names => URLs"
73+
{"Dir1" "http://url1"
74+
"Dir2" "http://url2"
75+
"Dir3" "http://url3"})
76+
77+
;; Now we need a function that takes an existing workflow and adds new
78+
;; steps to it for each directory => url pair from our data-map.
79+
80+
81+
(defn download-and-process
82+
"I take an existing workflow and download and process the data at
83+
url into the directory dir"
84+
[w-flow [dir url]] ;note the argument
85+
;destructuring
86+
(-> w-flow
87+
(base "") ;make sure we are in top
88+
;directory
89+
(cmd-step
90+
[dir]
91+
[]
92+
["mkdir -p $OUTPUT"])
93+
(base dir) ;move into dir for our
94+
;subsequent commands
95+
(cmd-step
96+
["raw_data"]
97+
[]
98+
["wget -O $OUTPUT " url] ;get the data
99+
:timecheck false)
100+
(cmd-step
101+
["sorted_data"]
102+
["raw_data"]
103+
["sort -o $OUTPUT"]) ;sort the data
104+
;; more steps can be added here
105+
))
106+
107+
;; Finally we can use `reduce` with `download-and-process` to add
108+
;; several workflow steps for each dir => url pair in dir->url-map.
109+
110+
(def reduce-workflow
111+
(reduce
112+
download-and-process
113+
(new-workflow)
114+
dir->url-map))
115+
116+
;; (run-workflow reduce-workflow :preview true)
117+
118+
;; this is a fake workflow in that the interet data doesn't exist so
119+
;; we can't acutally run it

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
[clojopts/clojopts "0.3.2"]
1212
[fs "1.3.2"]
1313
[factual/jlk-time "0.1"]
14+
[clj-time "0.6.0"]
1415
[digest "1.4.0"]
1516
[com.google.guava/guava "14.0.1"]
1617
[cheshire "5.2.0"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Regression testing for Drake: variable string substitution inside a command substitution
3+
# Relevant URLs:
4+
# https://github.com/Factual/drake/issues/129
5+
6+
source $(dirname $0)/regtest_utils.sh
7+
8+
cleanup() {
9+
rm -f test_variable.out
10+
}
11+
12+
echo "----------------------------"
13+
echo "TESTS: variable substitution"
14+
echo "----------------------------"
15+
16+
cleanup
17+
run_d regtest_command_substitution_variable.d -a
18+
check "`cat test_variable.out`" '-world-/-world-/-$[VAR]-/-6-'
19+
20+
# All tests passed
21+
echo "ALL PASSED"
22+
23+
# Clean up again
24+
cleanup
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
VAR="world"
2+
TEXT1=$(echo -$[VAR]-)
3+
TEXT2=$(echo -"$[VAR]"-)
4+
TEXT3=$(echo -'$[VAR]'-)
5+
TEXT4=$(echo -"$(echo $[VAR] | wc -c)"-)
6+
7+
test_variable.out <-
8+
echo $TEXT1/$TEXT2/$TEXT3/$TEXT4 > $OUTPUT

resources/regtest/run-all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ if ($(dirname $0)/regtest_fs.sh &&
33
$(dirname $0)/regtest_stdout.sh &&
44
$(dirname $0)/regtest_interpreters.sh &&
55
$(dirname $0)/regtest_inline_shell.sh &&
6+
$(dirname $0)/regtest_command_substitution.sh &&
67
$(dirname $0)/regtest_async.sh &&
78
$(dirname $0)/regtest_splitvars.sh &&
89
$(dirname $0)/regtest_inputs_outputs.sh &&

0 commit comments

Comments
 (0)