Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alex Pearce
Moore
Commits
e4106ffd
Commit
e4106ffd
authored
Jul 30, 2019
by
Niklas Stefan Nolte
🔥
Committed by
Rosen Matev
Jul 30, 2019
Browse files
Fix hash dependence on dict order
parent
0a813276
Changes
1
Hide whitespace changes
Inline
Side-by-side
PyConf/python/PyConf/components.py
View file @
e4106ffd
...
...
@@ -26,6 +26,7 @@ except ImportError:
from
cgi
import
escape
as
html_escape
import
inspect
import
re
import
json
from
GaudiKernel.ConfigurableMeta
import
ConfigurableMeta
...
...
@@ -51,14 +52,12 @@ _UNIQUE_PREFIXES = defaultdict(lambda: 0)
def
_hash_dict
(
d
):
return
hash
(
','
.
join
([
str
(
k
)
+
'='
+
str
(
v
)
for
k
,
v
in
d
.
items
()]))
def
_hash_list
(
l
):
return
hash
(
','
.
join
((
str
(
i
)
for
i
in
l
)))
"""hash a dict with string keys"""
return
hash
(
json
.
dumps
(
d
,
sort_keys
=
True
))
def
_get_args
(
func
):
"""get the argument keys of a function"""
return
inspect
.
getargspec
(
func
).
args
...
...
@@ -363,12 +362,13 @@ class Algorithm(object):
# location this forms part of the algorithm's defined behaviour
# So, record when any output location is forced
if
isinstance
(
outputs
,
dict
):
forced_locations
=
[
str
(
output
)
for
output
in
outputs
.
values
()
forced_locations
=
{
key
:
str
(
output
)
for
key
,
output
in
outputs
.
items
()
if
isinstance
(
output
,
force_location
)
]
}
else
:
forced_locations
=
[]
forced_locations
=
dict
()
#TOOLS ##############
_tools
=
_pop_tools
(
kwargs
)
...
...
@@ -448,18 +448,17 @@ class Algorithm(object):
@
staticmethod
def
_calc_id
(
typename
,
props
,
inputs
,
tools
,
forced_outputs
=
None
):
if
forced_outputs
is
None
:
forced_outputs
=
[]
forced_outputs
=
dict
()
props_hash
=
_hash_dict
(
props
)
# TODO include the transformed input somehow
inputs_hash
=
_hash_dict
(
{
key
:
_datahandle_ids
(
handles
)
for
key
,
handles
in
inputs
.
items
()})
tools_hash
=
_hash_dict
({
key
:
tool
.
id
for
key
,
tool
in
tools
.
items
()})
outputs_hash
=
_hash_list
(
forced_outputs
)
to_be_hashed
=
[
typename
,
props_hash
,
inputs_hash
,
tools_hash
,
outputs_hash
]
return
_hash_list
(
to_be_hashed
)
outputs_hash
=
_hash_dict
(
forced_outputs
)
to_be_hashed
=
(
typename
,
props_hash
,
inputs_hash
,
tools_hash
,
outputs_hash
)
return
hash
(
to_be_hashed
)
# end of __init__
...
...
@@ -773,8 +772,8 @@ class Tool(object):
{
key
:
_datahandle_ids
(
handles
)
for
key
,
handles
in
inputs
.
items
()})
tools_hash
=
_hash_dict
({
key
:
tool
.
id
for
key
,
tool
in
tools
.
items
()})
to_be_hashed
=
[
typename
,
props_hash
,
inputs_hash
,
tools_hash
]
return
_
hash
_list
(
to_be_hashed
)
to_be_hashed
=
(
typename
,
props_hash
,
inputs_hash
,
tools_hash
)
return
hash
(
to_be_hashed
)
@
property
def
inputs
(
self
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment