Skip to content

Commit cf8a9dd

Browse files
ericvergnaudJCZuurmond
authored andcommitted
formatting
1 parent a8a6af3 commit cf8a9dd

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/databricks/labs/ucx/sequencing/sequencing.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,19 @@ def generate_steps(self) -> Iterable[MigrationStep]:
199199
for leaf_key in leaf_keys:
200200
del incoming_counts[leaf_key]
201201
sorted_steps.append(self._nodes[leaf_key].as_step(step_number, list(self._required_step_ids(leaf_key))))
202-
for dependency_key in self._outgoing[leaf_key]:
203-
# prevent re-instantiation of already deleted keys
204-
if dependency_key not in incoming_counts:
205-
continue
206-
# prevent negative count with cyclic dependencies
207-
if incoming_counts[dependency_key] > 0:
208-
incoming_counts[dependency_key] -= 1
202+
self._on_leaf_key_processed(leaf_key, incoming_counts)
209203
step_number += 1
210204
return sorted_steps
211205

206+
def _on_leaf_key_processed(self, leaf_key: tuple[str, str], incoming_counts: dict[tuple[str, str], int]):
207+
for dependency_key in self._outgoing[leaf_key]:
208+
# prevent re-instantiation of already deleted keys
209+
if dependency_key not in incoming_counts:
210+
continue
211+
# prevent negative count with cyclic dependencies
212+
if incoming_counts[dependency_key] > 0:
213+
incoming_counts[dependency_key] -= 1
214+
212215
def _required_step_ids(self, node_key: tuple[str, str]) -> Iterable[int]:
213216
for leaf_key in self._incoming[node_key]:
214217
yield self._nodes[leaf_key].node_id

tests/unit/sequencing/test_sequencing.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,27 @@ def test_sequencer_builds_steps_from_dependency_graph(ws, simple_dependency_reso
5555
job = jobs.Job(job_id=1234, settings=settings)
5656
ws.jobs.get.return_value = job
5757
ws_cache = create_autospec(WorkspaceCache)
58-
ws_cache.get_workspace_path.side_effect = lambda path: Path(path)
58+
ws_cache.get_workspace_path.side_effect = Path
5959
dependency = WorkflowTask(ws, task, job, ws_cache)
6060
container = dependency.load(mock_path_lookup)
6161
graph = DependencyGraph(dependency, None, simple_dependency_resolver, mock_path_lookup, CurrentSessionState())
6262
problems = container.build_dependency_graph(graph)
6363
assert not problems
6464
sequencer = MigrationSequencer(ws, mock_path_lookup, admin_locator(ws, "John Doe"))
6565
sequencer.register_workflow_task(task, job, graph)
66-
steps = list(sequencer.generate_steps())
67-
step0 = next((step for step in steps if step.object_type == "TASK"), None)
68-
assert step0
69-
step1 = next((step for step in steps if step.object_name == notebook_path.as_posix()), None)
70-
assert step1
71-
assert step1.step_number < step0.step_number
72-
step2 = next(
73-
(step for step in steps if step.object_name == "parent_that_magic_runs_child_that_uses_value_from_parent.py"),
74-
None,
75-
)
76-
assert step2
77-
assert step2.step_number < step1.step_number
78-
step3 = next((step for step in steps if step.object_name == "_child_that_uses_value_from_parent.py"), None)
79-
assert step3
80-
assert step3.step_number < step2.step_number
66+
all_steps = list(sequencer.generate_steps())
67+
# ensure steps have a consistent step_number: TASK > grand-parent > parent > child
68+
parent_name = "parent_that_magic_runs_child_that_uses_value_from_parent.py"
69+
steps = [
70+
next((step for step in all_steps if step.object_name == "_child_that_uses_value_from_parent.py"), None),
71+
next((step for step in all_steps if step.object_name == parent_name), None),
72+
next((step for step in all_steps if step.object_name == notebook_path.as_posix()), None),
73+
next((step for step in all_steps if step.object_type == "TASK"), None),
74+
]
75+
# ensure steps have a consistent step_number
76+
for i in range(0, len(steps) - 1):
77+
assert steps[i]
78+
assert steps[i].step_number < steps[i + 1].step_number
8179

8280

8381
class _DependencyGraph(DependencyGraph):

0 commit comments

Comments
 (0)