Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def splitter_validation(self):
""" validating if the splitter is correct (after all states are connected)"""
for spl in self.splitter_rpn_compact:
if not (
spl in [".", "*"]
or spl.startswith("_")
or spl.split(".")[0] == self.name
):
raise hlpst.PydraStateError(
"can't include {} in the splitter, consider using _{}".format(
spl, spl.split(".")[0]
)
if st_combiner:
# keys and groups from previous states
# after taking into account combiner from current state
(
keys_f_st,
group_for_inputs_f_st,
groups_stack_f_st,
combiner_all_st,
) = hlpst.splits_groups(
st.splitter_rpn_final,
combiner=st_combiner,
inner_inputs=st.inner_inputs,
)
self.keys_final += keys_f_st # st.keys_final
if not hasattr(st, "group_for_inputs_final"):
raise hlpst.PydraStateError("previous state has to run first")
group_for_inputs = group_for_inputs_f_st
groups_stack = groups_stack_f_st
self.left_combiner_all += combiner_all_st
else:
# if no element from st.splitter is in the current combiner,
# using st attributes without changes
if st.keys_final:
self.keys_final += st.keys_final
group_for_inputs = st.group_for_inputs_final
groups_stack = st.groups_stack_final
group_for_inputs = {k: v + last_gr for k, v in group_for_inputs.items()}
self.group_for_inputs_final.update(group_for_inputs)
nmb_gr = 0
for i, groups in enumerate(groups_stack):
el,
".",
other_states,
output_splitter=output_splitter,
state_fields=state_fields,
)
elif type(el) is list:
_iterate_list(
el,
"*",
other_states,
output_splitter=output_splitter,
state_fields=state_fields,
)
else:
raise PydraStateError("splitter has to be a string, a tuple or a list")
if i > 0:
output_splitter.append(current_sign)
def combiner_validation(self):
""" validating if the combiner is correct (after all states are connected)"""
if self.combiner:
if not self.splitter:
raise hlpst.PydraStateError(
"splitter has to be set before setting combiner"
)
if set(self._combiner) - set(self.splitter_rpn):
raise hlpst.PydraStateError("all combiners have to be in the splitter")
raise PydraStateError(
"can't ask for splitter from {}, other nodes that are connected: {}".format(
node_nm, other_states.keys()
)
)
elif state_fields:
splitter_mod = add_name_splitter(
splitter=other_states[node_nm][0].splitter_final, name=node_nm
)
el = (splitter_mod, el[1])
if other_states[node_nm][0].other_states:
other_states.update(other_states[node_nm][0].other_states)
if type(el[1]) is str and el[1].startswith("_"):
node_nm = el[1][1:]
if node_nm not in other_states and state_fields:
raise PydraStateError(
"can't ask for splitter from {}, other nodes that are connected: {}".format(
node_nm, other_states.keys()
)
)
elif state_fields:
splitter_mod = add_name_splitter(
splitter=other_states[node_nm][0].splitter_final, name=node_nm
)
el = (el[0], splitter_mod)
if other_states[node_nm][0].other_states:
other_states.update(other_states[node_nm][0].other_states)
_iterate_list(
el,
".",
other_states,
output_splitter=output_splitter,
""" splits_groups function if splitter is a singleton"""
if op_single in inner_inputs:
# TODO: have to be changed if differ length
# TODO: i think I don't want to add here from left part
# keys = inner_inputs[op_single].keys_final + [op_single]
keys = [op_single]
groups[op_single], groups_stack = 0, [[], [0]]
else:
keys = [op_single]
groups[op_single], groups_stack = 0, [[0]]
if combiner:
if combiner == [op_single]:
return [], {}, [], combiner
else:
# TODO: probably not needed, should be already check by st.combiner_validation
raise PydraStateError(
"all fields from the combiner have to be in splitter_rpn: {}, but combiner: {} is set".format(
[op_single], combiner
)
)
else:
return keys, groups, groups_stack, []
def combiner_validation(self):
""" validating if the combiner is correct (after all states are connected)"""
if self.combiner:
if not self.splitter:
raise hlpst.PydraStateError(
"splitter has to be set before setting combiner"
)
if set(self._combiner) - set(self.splitter_rpn):
raise hlpst.PydraStateError("all combiners have to be in the splitter")
combiner_all = list(set(combiner_all))
combiner_all.sort()
# groups that were removed (so not trying to remove twice)
grs_removed = []
groups_stack_final = deepcopy(groups_stack)
for comb in combiner:
grs = groups[comb]
for gr in ensure_list(grs):
if gr in groups_stack_final[-1]:
grs_removed.append(gr)
groups_stack_final[-1].remove(gr)
elif gr in grs_removed:
pass
else:
raise PydraStateError(
"input {} not ready to combine, you have to combine {} "
"first".format(comb, groups_stack[-1])
)
groups_final = {inp: gr for (inp, gr) in groups.items() if inp not in combiner_all}
gr_final = list(set(groups_final.values()))
map_gr_nr = {nr: i for (i, nr) in enumerate(sorted(gr_final))}
groups_final = {inp: map_gr_nr[gr] for (inp, gr) in groups_final.items()}
for i, groups_l in enumerate(groups_stack_final):
groups_stack_final[i] = [map_gr_nr[gr] for gr in groups_l]
keys_final = [key for key in keys if key not in combiner_all]
# TODO: not sure if I have to calculate and return keys, groups, groups_stack
return keys_final, groups_final, groups_stack_final, combiner_all