KeyError: 'im_func'
This issue was originally created at: 2008-06-18 12:44:23.
This issue was reported by: philipsemanchuk.
philipsemanchuk said at 2008-06-18 12:44:23
Scons dies in an ugly way for me with the SConstruct file at the end. Us newbies are great for testing software because we aren't yet smart enough to know better. ;)
If I comment out the env.Command() the problem goes away.
FYI, I'm on OS X, my home dir is /Users/me, and I have some IDL files in ~/k/demo/idl.
Terminal:
scons: Reading SConscript files ...
KeyError: 'im_func':
File "/Users/me/k/demo/SConstruct", line 26:
env.Command(target=Glob(TYPELIB_DIR + "/*.xpt"), source=Glob(TYPELIB_DIR + "/*.idl"), action=env.XptBuilder)
File "/usr/local/lib/scons-0.98.5/SCons/Environment.py", line 1755:
bld = apply(SCons.Builder.Builder, (), bkw)
File "/usr/local/lib/scons-0.98.5/SCons/Builder.py", line 248:
kw['action'] = SCons.Action.Action(kw['action'])
File "/usr/local/lib/scons-0.98.5/SCons/Action.py", line 366:
return apply(_do_create_action, (act,)+args, kw)
File "/usr/local/lib/scons-0.98.5/SCons/Action.py", line 333:
return apply(action_type, (act,)+args, kw)
File "/usr/local/lib/scons-0.98.5/SCons/Action.py", line 783:
self.funccontents = _callable_contents(execfunction)
File "/usr/local/lib/scons-0.98.5/SCons/Action.py", line 160:
return _function_contents(obj.im_func)
File "/usr/local/lib/scons-0.98.5/SCons/Environment.py", line 233:
return self.__dict__[name]
SContrsuct:
# Note that ~ in pathnames is a shell concept. SCons != shell, so ~ is not expanded in
# pathnames used by SCons.
MOZILLA_BIN = "/Users/me/mozilla/dist/bin"
MOZILLA_IDL = "/Users/me/mozilla/dist/idl"
TYPELIB_DIR = "/Users/me/k/demo/idl"
env = Environment()
# Define a custom builder for IDL/XPT files. SCons actually knows about IDL files but
# it wants to compile them into Windows typelibs (.tlb).
XptBuilder = Builder(action = "%(MOZILLA_BIN)s/xpidl -m typelib -w -v -I%(MOZILLA_IDL)s -e $TARGET $SOURCE " % vars(),
suffix = ".xpt", src_suffix = ".idl")
env['BUILDERS']['XptBuilder'] = XptBuilder
#env.XptBuilder(TYPELIB_DIR + "/kreoIDemo.idl")
#env.XptBuilder(TYPELIB_DIR + "/foo.idl")
#env.XptBuilder("kreoIDemo.idl", srcdir = TYPELIB_DIR)
#env.XptBuilder("foo.idl", srcdir = TYPELIB_DIR)
#env.Command(target=Glob(TYPELIB_DIR + "/*.xpt"), source=Glob(TYPELIB_DIR + "/*.idl"), action=env.XptBuilder)
# ------------------------ Cleaners -------------------------------
env.Clean(Glob(TYPELIB_DIR + "/*.xpt"), Glob(TYPELIB_DIR + "/*.xpt"))
stevenknight said at 2008-06-22 11:46:59
Hi Philip--
What version of OS X--Leopard, Tiger or something else? And what version of Python? (I assume just whatever came installed with your version of Mac OS, right?)
Thanks,
philipsemanchuk said at 2008-06-22 11:59:15
I'm on OS X 10.5.3; my Python is:
Python 2.5.1 (r251:54863, Nov 17 2007, 21:19:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
This is not the system Python, but it's darn close. FYI, the system Python identifies itself this way:
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
stevenknight said at 2008-06-26 17:39:33
Set priority and target milestone per bug party.
Looks like this might be a difference in Python 2.5 (Mac only?) that needs to be accounted for.
stevenknight said at 2008-06-26 18:18:35
Assign to Benoit (not just QA contact).
belley said at 2008-06-26 19:33:39
Hi Steven,
I'll look at it when coming back from vacation. I'm leaving for 3 weeks (June 28th to July 20th). I won't have access to the Internet while in vacation.
Benoit
garyo said at 2008-08-20 04:25:29
Bug party triage: move to 1.0.1 from 1.0.x. Either a regression, trivial fix, or important.
pankrat said at 2008-08-22 09:39:32
Philip,
You're trying to assign a Builder instance to the 'action' argument of the Command builder. AFAICT, that fails because a Builder is not the same as an Action and provides a different interface. I think the Command invocation should look like that:
env.Command(..., action=XptBuilder.action)
Could you try that?
Apart from that, why are you using a Command if you already got a builder for the same action?
HTH, Ludwig
philipsemanchuk said at 2008-08-24 06:59:48
Your suggestion about the Command invocation made the error disappear, so thanks for that.
As to why I am using a Command when I have a builder for the same action, see my first comment about "not yet smart enough to know better". =) I was new to Scons and having trouble getting the concepts nailed down.
garyo said at 2008-09-01 13:37:32
Easiest place to catch this is probably in _do_create_action with a try/except. BUT, don't want to catch Ctrl-C exceptions or things like that. In any case we could catch KeyError to trap this specific error and say "Error: invalid action %s of type %s passed to builder."%(act, action_type)
gregnoel said at 2008-09-02 15:21:45
Move unfinished 1.0.1 issues to 1.1.
stevenknight said at 2008-10-17 05:59:04
Update target milestone to 1.2.
gregnoel said at 2008-12-04 17:41:09
1.2 is frozen; issues that didn't make it into 1.2 are moved to 1.3.
gregnoel said at 2010-01-20 03:40:33
Not completed in time for the 1.3 release; move to 2.1 p4.
garyo said at 2011-03-10 18:03:13
Benoit is no longer involved with the SCons project, reassigning his issues back to triage.
garyo said at 2012-09-01 10:01:49
Bumping all old issues targeted for past releases to 2.x.
My read of this is this was user error ("You're trying to assign a Builder instance to the 'action' argument of the Command builder." -> "Your suggestion about the Command invocation made the error disappear"). So I'm guessing it was left over to try to add some detection to maybe close the hole ("we could catch KeyError to trap this specific error and say 'Error: invalid action %s of type %s passed to builder."%(act, action_type)'). Is this worth keeping open?
@mwichmann sounds right.
Maybe check if the passed action is a child of ActionBase or a string, or a list of strings or action bases, or a function with the right signature?