[Buildbot-devel] Create collection of build steps
Brian Warner
warner-buildbot at lothar.com
Fri Sep 29 07:25:11 UTC 2006
Mateusz Loskot <mateusz at loskot.net> writes:
>
> I'd like to create collection of common steps used by number of build
> factories. Here is how I'm trying to do it:
>
> commonSteps["cvs"] = s(step.CVS,
> name="cvs",
> cvsroot = myRoot,
> cvsmodule = myModule,
> mode="update")
>
> f1 = factory.BuildFactory
> f1.addStep(commonSteps["cvs"])
That old 's' function is creating tuples and dict-ifying the arguments in the
same way that f.addStep does, so you need to use one or the other. Using both
won't work.
f.addStep() is designed for use like this:
f.addStep(CVS, cvsroot=myRoot, mode="update")
internally, it creates a tuple of the step class (CVS in this case) and a
dictionary of all the keyword arguments (in this case, {'cvsroot': myRoot,
'mode': "update"}), and adds this to the factory. This is slightly easier
than creating that dictionary yourself, with something that would have to
look like:
f.steps.append((CVS, {"cvsroot": myRoot, "mode": "update"}))
Using the **kwarg->dict conversion lets the addStep() line look a lot like
the code that would be used to instantiate a CVS instance. (but not exactly
the same, of course, that would look more like the following:
CVS(cvsroot=myRoot, mode="update")).
The s() function is doing the same thing. Using both gives you a tuple of a
(class, args) tuple and an empty dictionary, which as you discovered breaks
in a weird way when later code attempts to use the class element to finally
create the Step.
I suppose we could change addStep() to recognize the (class,args) tuple
produced by s().. I've certainly had cases where it was convenient to use s()
to create a step description (generally a source-checkout step) and pass it
around. In those cases I've usually done something silly like:
def createAFactory(source):
f = factory.BuildFactory()
f.addStep(source[0], **source[1])
f.addStep(etc)
s1 = Darcs(...)
f1 = createAFactory(s1)
s2 = SVN(...)
f2 = createAFactory(s2)
If f.addStep were a little big magic, you could just do:
def createAFactory(source):
f = factory.BuildFactory()
f.addStep(source)
f.addStep(etc)
I dunno.. would other people find this useful?
cheers,
-Brian
More information about the devel
mailing list