Skip to content

Commit

Permalink
Fixed issue with dedent
Browse files Browse the repository at this point in the history
  • Loading branch information
romain-intel committed Dec 20, 2024
1 parent 49383ea commit 1c890d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions metaflow/graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import inspect
import ast
import re
import textwrap


from .util import to_pod
Expand Down Expand Up @@ -177,7 +176,9 @@ def _create_nodes(self, flow):
if callable(func) and hasattr(func, "is_step"):
source_file = inspect.getsourcefile(func)
source_lines, lineno = inspect.getsourcelines(func)
source_code = textwrap.dedent("".join(source_lines))
# This also works for code (strips out leading whitspace based on
# first line)
source_code = deindent_docstring("".join(source_lines))
function_ast = ast.parse(source_code).body[0]
node = DAGNode(
function_ast, func.decorators, func.__doc__, source_file, lineno
Expand All @@ -198,6 +199,10 @@ def _postprocess(self):

def _traverse_graph(self):
def traverse(node, seen, split_parents):
try:
self.sorted_nodes.remove(node.name)
except ValueError:
pass
self.sorted_nodes.append(node.name)
if node.type in ("split", "foreach"):
node.split_parents = split_parents
Expand Down

0 comments on commit 1c890d5

Please sign in to comment.