From 52641f4cc33f8c71a52b3ca44aef6f67b5575a48 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 19 Jan 2024 14:26:31 -0800 Subject: [PATCH] Fix off-by-one padding issue. --- metricflow/dag/dag_to_text.py | 70 ++++++++++------------------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/metricflow/dag/dag_to_text.py b/metricflow/dag/dag_to_text.py index 340c1199d6..d380a36cbd 100644 --- a/metricflow/dag/dag_to_text.py +++ b/metricflow/dag/dag_to_text.py @@ -75,17 +75,9 @@ def _max_width_tracker(self) -> MaxWidthTracker: # noqa: D return self._thread_local_data.max_width_tracker def _displayed_property_on_one_line(self, displayed_property: DisplayedProperty) -> str: - return jinja2.Template( - textwrap.dedent( - """\ - - """ - ), - undefined=jinja2.StrictUndefined, - ).render( - key=displayed_property.key, - value=mf_pformat(displayed_property.value, max_line_length=self._max_width_tracker.current_max_width), - ) + key = displayed_property.key + value = mf_pformat(displayed_property.value, max_line_length=self._max_width_tracker.current_max_width) + return f"" def _format_to_text(self, node: DagNode, inner_contents: Optional[str]) -> str: """Convert the given node to the text representation. @@ -117,50 +109,28 @@ def _format_to_text(self, node: DagNode, inner_contents: Optional[str]) -> str: max_value_str_length = max([len(x) for x in value_str_split]) # Print the key on multiple lines. - node_fields.append( - jinja2.Template( - textwrap.dedent( - """\ - - """ - ), - undefined=jinja2.StrictUndefined, - ).render( - key=displayed_property.key, - padding=" " - * ( - (len("")) - - len("") - ), - ) + key = displayed_property.key + # Add padding so that all fields of this object have that align. + key_padding = " " * ( + (len("")) + - len("") ) + node_fields.append(f"") + # Print the lines for the value in an indented section. for value_str in value_str_split: - node_fields.append( - jinja2.Template( - textwrap.dedent( - """\ - - """ - ), - undefined=jinja2.StrictUndefined, - ).render( - indent_prefix=self._value_indent_prefix, - value=value_str, - padding=" " - * ( - (len("")) - - len("") - ), - ) + value_padding = " " * ( + (len("")) + - len("") ) + node_fields.append(f"") return jinja2.Template( textwrap.dedent(