fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Simplified argument passed to a function?


From: Nick Sergeant
Subject: Re: [Fab-user] Simplified argument passed to a function?
Date: Sun, 16 Nov 2008 16:01:23 -0500

Wow, that's perfect, thanks!

Nick Sergeant
(315) 719-2047

On Nov 14, 2008, at 8:37 PM, Jeff Forcier wrote:

OK, I was right, args were not really supported -- what happens as of
the latest master, and probably in 0.0.9 too, is that args without an
equals sign gets turned into a kwarg with identical key and value, so
for example "fab mytask:foo" turns into "mytask(foo='foo')". Aside
from not conforming perfectly with typical Python *args/**kwargs
methods, it means that values like your example, which have spaces in
them, would break regardless.

I've just pushed a nicely sized changeset to my Github fork of Fabric
which fixes this; now "fab mytask:foo" turns into "mytask('foo')", and
all the other expected parses work too, so you can mix and match: "fab
mytask:a=b,c=d,e" turns into "mytask('e', a='b', c='d')". Order does
not matter, all non-equals-signed args become args, all equals-signed
ones become kwargs, and then the command is executed as
"command(*args, **kwargs)".

I ran our unit tests and they worked as advertised -- meaning that
since I didn't update them to work with the new arg-parsing algorithm,
they failed, so I fixed 'em. Gotta love testing :) I've also run some
simple fab tasks by hand and they appeared to work OK, so I'm not too
worried about serious breakage.

My fork is fully up to date with the main Fabric repo as of this
moment and I haven't made any other changes recently, so if you clone
it you'll get regular Fabric plus this one change.

http://github.com/bitprophet/fabric/commit/af401679451cc30818dfa655c74200f2fb7bd0bf
is the changeset.
http://github.com/bitprophet/fabric/tree/master is the main repo page.

-Jeff

On Fri, Nov 14, 2008 at 8:38 AM, Nick Sergeant <address@hidden> wrote:
Cool, thanks!
Nick Sergeant
www.nicksergeant.com
address@hidden
(315) 719-2047
On Nov 14, 2008, at 8:29 AM, Jeff Forcier wrote:

I'm pretty sure this is because the current argument parsing code only
does keyword args, but I'm also pretty sure there's no big reason why
it cannot be extended to support args too. I'll make sure we at least
have this as a todo item, after checking to make sure it's not already
in with some sort of alternate syntax than what you tried (or broken).

-Jeff

On Fri, Nov 14, 2008 at 8:16 AM, Nick Sergeant <address@hidden>
wrote:

Right now, my function is this:

def deploy(**kwargs):

...Some stuff...

I call the function like:

fab deploy:m='my subversion commit message'

However, it would be useful to simply call it like:

fab deploy:'my subversion committ message'

... if it is safe to assume I only need one argument (the commit message).

Yet, when I set the function up like this:

def deploy(m):

...Some stuff...

and call it like:

fab deploy:'my subversion commit message'

I get:

TypeError: deploy() got an unexpected keyword argument 'my subversion commit

message'

Thanks!

Nick Sergeant

www.nicksergeant.com

address@hidden

(315) 719-2047

_______________________________________________

Fab-user mailing list

address@hidden

http://lists.nongnu.org/mailman/listinfo/fab-user






reply via email to

[Prev in Thread] Current Thread [Next in Thread]