[Scons-users] How to make a builder that takes a list of parameters

Bijan Chokoufe Nejad bijan.chokoufe at gmail.com
Thu Jun 11 09:54:52 EDT 2015


Hi Dirk,

OK, I give you the minimal example:

```
#!/usr/bin/env python
import os
env = Environment(ENV = os.environ)

def generate_plot(source, target, env, for_signature, descriptions=None):
  if descriptions is not None:
    sources = ' '.join([str(s) + ':' + d for (s,d) in zip(source,
descriptions)])
  else:
    sources = ' '.join([str(s) for s in source])
  return 'plot -o %s %s' % (target[0], sources)

build_plot = Builder(generator = generate_plot)

env.Append(BUILDERS = {'Plot' : build_plot})

descriptions = ["AAA", "BBB"]
sources = ["one.dat", "two.dat"]

env.Plot(target = "test", source = sources, descriptions = descriptions)
```

When I touch "one.dat" and "two.dat", I only get:

plot -o test one.dat two.dat

instead of

plot -o test one.dat:AAA two.dat:BBB

So the supplied `descriptions` are just ignored. When I make
descriptions non_optional in generate_plot, I get

```
TypeError: generate_plot() takes exactly 5 arguments (4 given):
  File "/home/bijancn/test/sconslist/SConstruct", line 19:
    env.Plot(target = "test", source = sources, descriptions = descriptions)
  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 578:
    key = self.action.batch_key(env or self.env, tlist, slist)
  File "/usr/lib/scons/SCons/Action.py", line 893:
    return self._generate(target, source, env, 1).batch_key(env, target,
source)
  File "/usr/lib/scons/SCons/Action.py", line 876:
    for_signature=for_signature)
```

Version is
```
python --version
Python 2.7.6
scons --version
SCons by Steven Knight et al.:
	script: v2.3.0, 2013/03/03 09:48:35, by garyo on reepicheep
	engine: v2.3.0, 2013/03/03 09:48:35, by garyo on reepicheep
	engine path: ['/usr/lib/scons/SCons']
```
and
```
python --version
Python 2.7.9
scons --version
SCons by Steven Knight et al.:
        script: v2.0.1.r5134, 2010/08/16 23:02:40, by bdeegan on cooldog
        engine: v2.0.1.r5134, 2010/08/16 23:02:40, by bdeegan on cooldog
```

I hope its clear what I want. I have no idea if it should work this way.
Best regards,

Bijan

On 06/11/2015 03:36 PM, Dirk Bächle wrote:
> Hi Bijan,
> 
> On 11.06.2015 15:29, Bijan Chokoufe Nejad wrote:
>> Hi all,
>>
>> I have a list of files and a list of descriptions that should be
>> compiled together to a plot. So I need something like
>>
>> cmd file1:desc1 file2:desc2 ...
>>
>> In an old post, I saw someone using optional arguments for the generator
>> like this
>>
>> def generate_plot(source, target, env, for_signature,
>>         descriptions=None):
>>    target_dir = target[0].dir
>>    if descriptions is not None:
>>      sources = ' '.join([str(s) + ':' + d for (s,d) in
>>         zip(source, descriptions)])
>>    else:
>>      sources = ' '.join([str(s) for s in source])
>>    return plot_cmd + '-o %s %s' % (target_dir, sources)
>>
>> build_plot = Builder(generator = generate_plot)
>>
>> But with scons 2.0.1 this doesn't seem to work?!
> 
> what exactly did you try to make it work? Which versions of SCons and
> Python were you using? And what is the exact error message that you got?
> 
> Best regards,
> 
> Dirk
> 
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users


More information about the Scons-users mailing list