|
25 | 25 | by an opening %. cmds should be a vector of strings or nil/false for
|
26 | 26 | steps that don't need commands like method and template
|
27 | 27 | steps. Standard drake options can be appended inline as key value
|
28 |
| - pairs, e.g. :method-mode true. See method-step, cmd-step, template |
29 |
| - and template-step." |
30 |
| - [w-flow outputs inputs cmds & {:keys [template] |
31 |
| - :as options}] |
32 |
| - (let [vars (:vars w-flow) |
| 28 | + pairs, e.g. :method-mode true; or (preferred) you may pass a single |
| 29 | + option-map argument. Variables for the step can be given in |
| 30 | + the :vars key and will be substituted. See method-step, cmd-step, |
| 31 | + template and template-step." |
| 32 | + [w-flow outputs inputs cmds & options] |
| 33 | + (let [{:keys [template] :as options} (utils/varargs->map options) |
| 34 | + w-flow-vars (:vars w-flow) |
| 35 | + step-vars (utils/var-sub-map w-flow-vars (:vars options)) |
| 36 | + vars (merge w-flow-vars step-vars) |
| 37 | + options (dissoc options :vars) |
33 | 38 | base (parse/add-path-sep-suffix
|
34 | 39 | (get vars "BASE" parse/default-base))
|
35 | 40 |
|
36 | 41 | [intags infiles] (utils/split-tags-from-files inputs)
|
37 | 42 | intags (utils/remove-tag-symbol intags)
|
38 |
| - sub-infiles (map (partial utils/var-sub->str vars) infiles) |
| 43 | + sub-infiles (map (partial utils/var-sub vars) infiles) |
39 | 44 | infiles-with-base (map (partial parse/add-prefix base) sub-infiles)
|
40 | 45 |
|
41 | 46 | [outtags outfiles] (utils/split-tags-from-files outputs)
|
42 | 47 | outtags (utils/remove-tag-symbol outtags)
|
43 |
| - sub-outfiles (map (partial utils/var-sub->str vars) outfiles) |
| 48 | + sub-outfiles (map (partial utils/var-sub vars) outfiles) |
44 | 49 | outfiles-with-base (map (partial parse/add-prefix base) sub-outfiles)
|
45 | 50 |
|
46 | 51 | ;; this is used for target matching, just remove all
|
|
79 | 84 | and specify :method and :method-mode options. See step for outputs
|
80 | 85 | inputs and options."
|
81 | 86 | [w-flow outputs inputs method-name & options]
|
82 |
| - (apply step w-flow outputs inputs nil :method method-name options)) |
| 87 | + (step w-flow outputs inputs nil (-> (utils/varargs->map options) |
| 88 | + (assoc :method method-name)))) |
83 | 89 |
|
84 | 90 | (def cmd-step
|
85 | 91 | "Shortcut for adding a command step to the workflow, w-flow. See
|
|
90 | 96 | "Shortcut for adding a template to the workflow, w-flow. See step
|
91 | 97 | for outputs, inputs, cmds and options."
|
92 | 98 | [w-flow outputs inputs cmds & options]
|
93 |
| - (apply step w-flow outputs inputs cmds :template true options)) |
| 99 | + (step w-flow outputs inputs cmds (-> (utils/varargs->map options) |
| 100 | + (assoc :template true)))) |
94 | 101 |
|
95 | 102 | (defn template-step
|
96 | 103 | "Shortcut for adding a step that uses a template to the workflow,
|
97 | 104 | w-flow. See step for outputs, inputs, cmds and options"
|
98 | 105 | [w-flow outputs inputs & options]
|
99 |
| - (apply step w-flow outputs inputs nil options)) |
| 106 | + (step w-flow outputs inputs nil (utils/varargs->map options))) |
100 | 107 |
|
101 | 108 | (defn method
|
102 | 109 | "Add a method to the workflow, w-flow. method-name should be a
|
103 | 110 | string and cmds should be a vector of command strings. Options are
|
104 |
| - standard drake options as key value pairs, e.g. :my-option |
105 |
| - \"my-value\"" |
106 |
| - [w-flow method-name cmds & {:as options}] |
| 111 | + standard drake options as vararg key value pairs, e.g. :my-option |
| 112 | + \"my-value\", or (preferred) a single map. Variables for the method can be |
| 113 | + given in the :vars key and will be substituted." |
| 114 | + [w-flow method-name cmds & options] |
107 | 115 | (when ((:methods w-flow) method-name)
|
108 | 116 | (println (format "Warning: method redefinition ('%s')" method-name)))
|
109 |
| - (assoc-in w-flow [:methods method-name] {:opts (if (nil? options) |
110 |
| - {} |
111 |
| - options) |
112 |
| - :vars (:vars w-flow) |
113 |
| - :cmds (mapv utils/var-place cmds)})) |
| 117 | + (let [options (utils/varargs->map options) |
| 118 | + w-flow-vars (:vars w-flow) |
| 119 | + step-vars (utils/var-sub-map w-flow-vars (:vars options)) |
| 120 | + vars (merge w-flow-vars step-vars)] |
| 121 | + (assoc-in w-flow [:methods method-name] {:opts (dissoc options :vars) |
| 122 | + :vars vars |
| 123 | + :cmds (mapv utils/var-place cmds)}))) |
114 | 124 |
|
115 | 125 | (defn add-methods
|
116 | 126 | "Adds all the methods in methods-hash to workflow, w-flow.
|
|
129 | 139 | should be strings"
|
130 | 140 | [w-flow var-name var-value]
|
131 | 141 | (let [vars (:vars w-flow)
|
132 |
| - sub-var-name (utils/var-sub->str vars var-name) |
133 |
| - sub-var-value (utils/var-sub->str vars var-value)] |
| 142 | + sub-var-name (utils/var-sub vars var-name) |
| 143 | + sub-var-value (utils/var-sub vars var-value)] |
134 | 144 | (assoc-in w-flow [:vars sub-var-name] sub-var-value)))
|
135 | 145 |
|
136 | 146 | (defn base
|
|
140 | 150 |
|
141 | 151 | (defn run-workflow
|
142 | 152 | "Run the workflow in w-flow. Optionally specify targetv as a
|
143 |
| - key value pair, e.g. :targetv [\"=...\"]\", otherwise the default |
144 |
| - targetv is [\"=...\"]\". Other run options to run-workflow can also |
145 |
| - be specified as key value pairs. Set :repl-feedback to :quiet, |
146 |
| - :default or :verbose to adjust the repl feedback level." |
| 153 | + key value pair, e.g. :targetv [\"outA.txt\" \"outB.txt\" \"outC.txt]\", |
| 154 | + otherwise the default targetv is core/DEFAULT-TARGETV. |
| 155 | + Other run options to run-workflow can also be specified as key value pairs. |
| 156 | + Set :repl-feedback to :quiet, :default or :verbose to adjust the repl feedback |
| 157 | + level." |
147 | 158 | [w-flow & {:keys [targetv repl-feedback]
|
148 |
| - :or {targetv ["=..."] |
| 159 | + :or {targetv d-core/DEFAULT-TARGETV |
149 | 160 | repl-feedback :default}
|
150 | 161 | :as run-options}]
|
151 |
| - (let [opts (merge d-core/DEFAULT-OPTIONS |
| 162 | + (let [opts (merge d-opts/DEFAULT-OPTIONS |
152 | 163 | {:auto true}
|
153 | 164 | run-options)
|
154 | 165 | opts-with-eb (if (not= repl-feedback :quiet)
|
|
162 | 173 | (info "Clojure version:" *clojure-version*)
|
163 | 174 | (info "Options:" opts-with-eb)
|
164 | 175 |
|
165 |
| - (plug/load-plugin-deps (*options* :plugins)) |
| 176 | + (plug/load-plugin-deps (:plugins *options*)) |
166 | 177 | (fs/with-cwd fs/*cwd*
|
167 | 178 | (-> w-flow
|
168 | 179 | (utils/compile-parse-tree)
|
|
0 commit comments