Skip to content

Commit 8cdab13

Browse files
committed
soft_dependencies : correct standard codepath affected by my prior changes + an incorrect error check
1 parent 181868d commit 8cdab13

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

src/dependencies/soft_dependencies.jl

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -216,30 +216,38 @@ function soft_dependencies_multiscale(soft_dep_graphs_roots::DependencyGraph{Dic
216216
# If the node has soft dependencies at other scales, add it as child of the other scale (and add its parent too):
217217
if length(soft_deps_multiscale) > 0
218218
for org in keys(soft_deps_multiscale)
219-
# org = "Leaf"
220219
for (parent_soft_dep, soft_dep_vars) in soft_deps_multiscale[org]
221-
master_node = ()
222-
223-
#if the node has a soft dependency on a node that is a nested hard dependency, have it point to the master node of that hard dependency instead of the internal node
224-
225-
# This check is meant in case the organ at the inspected scale is part of a hard dependency, and therefore already absent from the roots
226-
227-
roots_at_given_scale = soft_dep_graphs_roots.roots[org][:soft_dep_graph]
228-
if !(parent_soft_dep in keys(roots_at_given_scale))
229-
for (hd_key, hd) in hard_dep_dict
230-
master_node = hd
231-
if parent_soft_dep == hd_key
232-
while !isa(master_node, SoftDependencyNode)
220+
221+
# if the node has a soft dependency on a node that is a nested hard dependency,
222+
# have it point to the master node of that hard dependency instead of the internal node
223+
# This check is meant in case the organ at the inspected scale is part of a hard dependency,
224+
# and therefore already absent from the roots
225+
226+
roots_at_given_scale = soft_dep_graphs_roots.roots[org][:soft_dep_graph]
227+
if !(parent_soft_dep in keys(roots_at_given_scale))
228+
master_node = ()
229+
for (hd_key, hd) in hard_dep_dict
230+
if parent_soft_dep == hd_key
231+
master_node = hd
232+
depth = 0
233+
# A cleaner way of preventing cycles or infinite loops would be more desirable
234+
while !isa(master_node, SoftDependencyNode) && depth < 50
233235
master_node.parent === nothing && error("Finalised hard dependency has no parent")
234236
master_node = master_node.parent
237+
depth += 1
235238
end
239+
236240
break
237241
end
238242
end
239-
end
240243

241-
# NOTE : this may need to be propagated within internal hard dependencies' ancestors of this model... ?
242-
parent_node = soft_dep_graphs_roots.roots[master_node.scale][:soft_dep_graph][master_node.process]
244+
master_node == () && error("Parent is not located in hard deps, nor in roots, which should be the case when initalizing soft dependencies")
245+
246+
# NOTE : this may need to be propagated within internal hard dependencies' ancestors of this model... ?
247+
parent_node = soft_dep_graphs_roots.roots[master_node.scale][:soft_dep_graph][master_node.process]
248+
else
249+
parent_node = soft_dep_graphs_roots.roots[org][:soft_dep_graph][parent_soft_dep]
250+
end
243251

244252
# preventing a cyclic dependency: if the parent also has a dependency on the current node:
245253
if parent_node.parent !== nothing && any([i == p for p in parent_node.parent])

0 commit comments

Comments
 (0)