Discussion:
[Scons-users] SCons.Util.Flatten does not support Python3's dictionary view objects
Mike Haboustak
2018-10-17 14:21:04 UTC
Permalink
I've been testing SCons with Python3 and have run into some trouble
using the Depends builder. My dependency sources are the values of a
dictionary and I'm passing the result of dict.values() to Depends.

resources = {
'icon': 'resources/icon.png',
'splash': 'resources/splash.png',
}
env.Depends(myprog, resources.values())

When run under Python3, SCons fails to build with the following traceback:
AttributeError: 'dict_values' object has no attribute 'get_state':
File "/usr/local/lib/scons/SCons/Script/Main.py", line 1361:
_exec_main(parser, values)
File "/usr/local/lib/scons/SCons/Script/Main.py", line 1324:
_main(parser)
File "/usr/local/lib/scons/SCons/Script/Main.py", line 1103:
nodes = _build_targets(fs, options, targets, target_top)
File "/usr/local/lib/scons/SCons/Script/Main.py", line 1298:
jobs.run(postfunc = jobs_postfunc)
File "/usr/local/lib/scons/SCons/Job.py", line 111:
self.job.start()
File "/usr/local/lib/scons/SCons/Job.py", line 193:
task = self.taskmaster.next_task()
File "/usr/local/lib/scons/SCons/Taskmaster.py", line 960:
node = self._find_next_ready_node()
File "/usr/local/lib/scons/SCons/Taskmaster.py", line 851:
childstate = child.get_state()


In python 3, dict.values() returns a dictionary view object:
https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects

The problem starts with a lack of support for these dictionary views
in SCons.Util.Flatten:
items = {"a":1, "b":2, "c":3}
args = SCons.Util.Flatten(items.values())
print(args)

result: [dict_values([2, 1, 3])]

Thanks,
Mike Haboustak
Bill Deegan
2018-10-17 14:36:37 UTC
Permalink
I'd suggest you change to sort the values before adding to depends?
The order of dependencies changing can cause a rebuild.

I've reproduced the issue.

Please file an issue on github.
Likely we'll get a fix fairly soon.

in the interim.
env.Depends(myprog, list(resources.values()))

might work to get you going?
Post by Mike Haboustak
I've been testing SCons with Python3 and have run into some trouble
using the Depends builder. My dependency sources are the values of a
dictionary and I'm passing the result of dict.values() to Depends.
resources = {
'icon': 'resources/icon.png',
'splash': 'resources/splash.png',
}
env.Depends(myprog, resources.values())
_exec_main(parser, values)
_main(parser)
nodes = _build_targets(fs, options, targets, target_top)
jobs.run(postfunc = jobs_postfunc)
self.job.start()
task = self.taskmaster.next_task()
node = self._find_next_ready_node()
childstate = child.get_state()
https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects
The problem starts with a lack of support for these dictionary views
items = {"a":1, "b":2, "c":3}
args = SCons.Util.Flatten(items.values())
print(args)
result: [dict_values([2, 1, 3])]
Thanks,
Mike Haboustak
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Mike Haboustak
2018-10-17 14:39:49 UTC
Permalink
Bill,

Thanks for the quick reply and the tip about preserving dependency order.

I'll create the GitHub issue. Converting the view via list() does work.
Post by Bill Deegan
I'd suggest you change to sort the values before adding to depends?
The order of dependencies changing can cause a rebuild.
I've reproduced the issue.
Please file an issue on github.
Likely we'll get a fix fairly soon.
in the interim.
env.Depends(myprog, list(resources.values()))
might work to get you going?
Post by Mike Haboustak
I've been testing SCons with Python3 and have run into some trouble
using the Depends builder. My dependency sources are the values of a
dictionary and I'm passing the result of dict.values() to Depends.
resources = {
'icon': 'resources/icon.png',
'splash': 'resources/splash.png',
}
env.Depends(myprog, resources.values())
_exec_main(parser, values)
_main(parser)
nodes = _build_targets(fs, options, targets, target_top)
jobs.run(postfunc = jobs_postfunc)
self.job.start()
task = self.taskmaster.next_task()
node = self._find_next_ready_node()
childstate = child.get_state()
https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects
The problem starts with a lack of support for these dictionary views
items = {"a":1, "b":2, "c":3}
args = SCons.Util.Flatten(items.values())
print(args)
result: [dict_values([2, 1, 3])]
Thanks,
Mike Haboustak
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Bill Deegan
2018-10-17 15:15:01 UTC
Permalink
I fixed it, pull request, and merged..

Take a look at the pull request. If you pull the sequencetypes change from
here
https://github.com/bdbaddog/scons/blob/fc51dd74d89ec1a4b5704b52d34fe4ef1c6e1982/src/engine/SCons/Util.py#L373

You should be able to move forward.
Post by Mike Haboustak
Bill,
Thanks for the quick reply and the tip about preserving dependency order.
I'll create the GitHub issue. Converting the view via list() does work.
Post by Bill Deegan
I'd suggest you change to sort the values before adding to depends?
The order of dependencies changing can cause a rebuild.
I've reproduced the issue.
Please file an issue on github.
Likely we'll get a fix fairly soon.
in the interim.
env.Depends(myprog, list(resources.values()))
might work to get you going?
Post by Mike Haboustak
I've been testing SCons with Python3 and have run into some trouble
using the Depends builder. My dependency sources are the values of a
dictionary and I'm passing the result of dict.values() to Depends.
resources = {
'icon': 'resources/icon.png',
'splash': 'resources/splash.png',
}
env.Depends(myprog, resources.values())
When run under Python3, SCons fails to build with the following
_exec_main(parser, values)
_main(parser)
nodes = _build_targets(fs, options, targets, target_top)
jobs.run(postfunc = jobs_postfunc)
self.job.start()
task = self.taskmaster.next_task()
node = self._find_next_ready_node()
childstate = child.get_state()
https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects
The problem starts with a lack of support for these dictionary views
items = {"a":1, "b":2, "c":3}
args = SCons.Util.Flatten(items.values())
print(args)
result: [dict_values([2, 1, 3])]
Thanks,
Mike Haboustak
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Loading...