Python: Scons: TypeError: __init__() takes exactly 4 arguments (2 given):

676 Views Asked by At

I'm using SCons as a software construction tool. I want to untar a 3rd party software. I'm using UnTarBuilder to do it and the code is same as the one given here

This is a piece of my SConstruct file:

def tarContentsEmitter(target, source, env):
    import tarfile
    sourceTar = tarfile.open(source[0].name,'r')
    tarContents = sourceTar.getmembers()
    tarFileContents = filter(lambda tarEntry: tarEntry.isfile(), tarContents)
    newTargets = map(tarInfoToNode, tarFileContents)
    sourceTar.close()
    return (newTargets, source)

def tarInfoToNode(tarInfoObject):
    return File(tarInfoObject.name)

def UnTar(target, source, env):
    # Code to build "target" from "source" here
    import tarfile
    sourceTar = tarfile.open(source[0].name,'r')
    sourceTar.extractall()
    sourceTar.close()
    return None

def UnTarString(target, source, env):
    """ Information string for UnTar """
    return 'Extracting %s' % os.path.basename
    (str (source[0]))

unTarBuilder = Builder(action=SCons.Action.Action(UnTar, UnTarString),
                src_suffix='.tar.bz2',
                emitter=tarContentsEmitter)

env.Append(BUILDERS = {'UnTar' : unTarBuilder})
env.UnTar(source='curl-7.37.0')

I'm getting the following error:

scons: Reading SConscript files ...
TypeError: __init__() takes exactly 4 arguments (2 given):
  File "/home/nikhil/mnt/work/trunk/SConstruct", line 100:
    env.UnTar(source='curl-7.37.0.tar.bz2')
  File "/usr/lib/scons/SCons/Environment.py", line 259:
    return MethodWrapper.__call__(self, target, source, *args, **kw)
  File "/usr/lib/scons/SCons/Environment.py", line 223:
    return self.method(*nargs, **kwargs)
  File "/usr/lib/scons/SCons/Builder.py", line 632:
    return self._execute(env, target, source, OverrideWarner(kw), ekw)
  File "/usr/lib/scons/SCons/Builder.py", line 553:
    tlist, slist = self._create_nodes(env, target, source)
  File "/usr/lib/scons/SCons/Builder.py", line 517:
    target, source = self.emitter(target=tlist, source=slist, env=env)
  File "/home/nikhil/mnt/work/trunk/SConstruct", line 75:
    newTargets = map(tarInfoToNode, tarFileContents)
  File "/home/nikhil/mnt/work/trunk/SConstruct", line 80:
    return File(tarInfoObject.name)

I know that UnTar expects target and env but I'm not sure if I missed something else because they would've corrected in the link mentioned above since this is pretty trivial (I'm not a python guy)

1

There are 1 best solutions below

0
On BEST ANSWER

UnTar takes 3 arguments and you are passing only 1 (source), you have to pass also "target" and "env". The error says:

TypeError: __init__() takes exactly 4 arguments (2 given):

__init__() is called automatically when you create an instance of a class, so in your case as soon you call UnTar() you get that error.

Anyway your code is incomplete, where does "env" come from?