Debian Codegraph @

doc/presentation.rst

raw
1 .. include:: <s5defs.txt>
2
3 ======================================================================
4 doit: bringing the power of build tools to execute any kind of task
5 ======================================================================
6
7
8 "Anything worth repeating is worth automating"
9
10
11 :Author: Eduardo Schettino
12
13
14 build tools
15 ============
16
17 Tools that manage repetitive tasks and their dependencies
18
19
20 * 1977: Make
21 * C & other compiled languages
22
23
24
25 Make - how it works
26 ===================
27
28 * rules
29
30
31 target: dependencies ...
32 commands
33 ...
34
35 * simple (and fragile) dependency checking (timestamps)
36
37
38 Make - how does it look?
39 ========================
40
41 .. class:: tiny
42 .. sourcecode:: make
43
44 helloworld: helloworld.o
45 cc -o $@ $<
46
47 helloworld.o: helloworld.c
48 cc -c -o $@ $<
49
50 .PHONY: clean
51 clean:
52 rm -f helloworld helloworld.o
53
54 Make - problems
55 ===============
56
57 * Make is not a programming language (how can I do a loop?)
58 * compact syntax (but hard to understand and remember)
59 * hard to debug
60
61
62 other build tools
63 ==================
64
65 * CMake
66 * java/XML: ant, maven
67 * Rake
68 * SCons
69
70
71 dynamic languages
72 =================
73
74 * who needs a build tool?
75 * unit-test
76
77 *web development*
78
79 * heavy use of database
80 * tests on browsers are slow
81 * need environment setup (start servers, reset DB...)
82
83
84 doit - design
85 =============
86
87 * nice language => python
88 * get out of your way
89 * we-don't-need-no-stinking-API (learned from pytest)
90 * dependencies by task not on file/targets (unique feature)
91
92 doit - do what?
93 ================
94
95
96 it's up to you!
97
98 doit is a tool to help you execute **your** tasks in a efficient way.
99
100
101 doit - how it works
102 ===================
103
104 * actions => what the task does
105
106 * python (portable)
107 * shell commands (fast, easy to use other programs)
108
109 * targets => what this task creates
110
111 * dependencies => what this task uses as input
112
113
114 doit - how does it look? (1)
115 ============================
116
117 .. class:: tiny
118 .. sourcecode:: python
119
120 DEFAULT_TASKS = ['edit']
121
122 # map source file to dependencies
123 SOURCE = {
124 'main': ["defs.h"],
125 'kbd': ["defs.h command.h"],
126 'command': ["defs.h command.h"],
127 'display': ["defs.h buffer.h"],
128 'insert': ["defs.h buffer.h"],
129 'files': ["defs.h buffer.h command.h"],
130 }
131
132 OBJECTS = ["%s.o" module for module in SOURCE.iterkeys()]
133
134
135 doit - how does it look? (2)
136 ============================
137
138 .. class:: tiny
139 .. sourcecode:: python
140
141 def task_edit():
142 return {'actions': ['cc -o edit %s' % " ".join(OBJECTS)],
143 'dependencies': OBJECTS,
144 'targets': ['edit']
145 }
146
147 def task_object():
148 for module, dep in SOURCE.iteritems():
149 dependencies = dep + ['%s.c' % module]
150 yield {'name': module,
151 'actions': ["cc -c %s.c" % module]
152 'targets': ["%s.o" % module],
153 'dependencies': dependencies,
154 }
155
156
157 doit - how does it look? (3)
158 ============================
159
160 .. class:: tiny
161 .. sourcecode:: python
162
163 import os
164 def task_clean():
165 for f in ['edit'] + OBJECTS:
166 yield {'name': f,
167 'actions': [(os.remove, f)],
168 'dependencies': [f]}
169
170
171
172 doit - no targets
173 =================
174
175 .. class:: tiny
176 .. sourcecode:: python
177
178 import glob;
179
180 pyFiles = glob.glob('*.py')
181
182 def task_checker():
183 for f in pyFiles:
184 yield {'actions': ["pychecker %s"% f],
185 'name':f,
186 'dependencies':(f,)}
187
188
189 doit - run once
190 ===============
191
192 .. class:: tiny
193 .. sourcecode:: python
194
195 URL = "http://svn.dojotoolkit.org/src/util/trunk/shrinksafe/shrinksafe.jar"
196 shrinksafe = "shrinksafe.jar"
197
198 jsFile = "file1.js"
199 compFile = "compressed1.js"
200
201 def task_shrink():
202 return {'actions': ['java -jar %s %s > %s'% (shrinksafe, jsFile, compFile)],
203 'dependencies': [shrinksafe]
204 }
205
206 def task_get_shrinksafe():
207 return {'actions': ["wget %s"% URL],
208 'targets': [shrinksafe],
209 'dependencies': [True]
210 }
211
212
213 doit - groups
214 =============
215
216 .. class:: tiny
217 .. sourcecode:: python
218
219 def task_foo():
220 return {'actions': ["echo foo"]}
221
222 def task_bar():
223 return {'actions': ["echo bar"]}
224
225 def task_mygroup():
226 return {'actions': None,
227 'dependencies': [':foo', ':bar']}
228
229
230 doit - environment setup (1)
231 ============================
232
233 .. class:: tiny
234 .. sourcecode:: python
235
236 ### task setup env. good for functional tests!
237
238 class SetupSample(object):
239 def __init__(self, server):
240 self.server = server
241
242 def setup(self):
243 # start server
244 pass
245
246 def cleanup(self):
247 # stop server
248 pass
249
250
251 doit - environment setup (2)
252 ============================
253
254 .. class:: tiny
255 .. sourcecode:: python
256
257 setupX = SetupSample('x')
258 setupY = SetupSample('y')
259
260 def task_withenvX():
261 for fin in ('a','b','c'):
262 yield {'name': fin,
263 'actions':['echo x'],
264 'setup': setupX}
265
266 def task_withenvY():
267 return {'actions': ['echo x'],
268 'setup': setupY}
269
270
271 doit - cmd line
272 ===============
273
274 * run
275 * list
276 * forget
277
278
279 doit - future
280 =============
281
282 * community > 1
283 * support clean task
284 * command line parameters
285 * specific support for common tasks (C compilation)
286 * dependency scanners
287 * speed improvements
288
289
290 thanks
291 ===========
292
293 Questions?
294
295
296 doit website: http://python-doit.sourceforge.net
297
298
299 references:
300 http://software-carpentry.org/
301 http://www.gnu.org/software/make/
302
303 presentation written in ReST/rst2s5 + pygments