Skip to content

Commit

Permalink
Set default width if fail to get terminal size (#2558)
Browse files Browse the repository at this point in the history
* Set default width if fail to get terminal size

Signed-off-by: Kevin Su <[email protected]>

* lint

Signed-off-by: Kevin Su <[email protected]>

* test

Signed-off-by: Kevin Su <[email protected]>

---------

Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
  • Loading branch information
pingsutw authored and fiedlerNr9 committed Jul 25, 2024
1 parent 0513445 commit 743ef90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flytekit/core/type_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ def to_python_value(self, ctx: FlyteContext, lv: Literal, expected_python_type:
res_tag = trans.name
found_res = True
except Exception as e:
logger.debug(f"Failed to convert from {lv} to {v}", e)
logger.debug(f"Failed to convert from {lv} to {v} with error: {e}")

if is_ambiguous:
raise TypeError(
Expand Down
8 changes: 7 additions & 1 deletion flytekit/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,19 @@ def upgrade_to_rich_logging(log_level: typing.Optional[int] = logging.WARNING):

import flytekit

try:
width = os.get_terminal_size().columns
except Exception as e:
logger.debug(f"Failed to get terminal size: {e}")
width = 80

handler = RichHandler(
tracebacks_suppress=[click, flytekit],
rich_tracebacks=True,
omit_repeated_times=False,
show_path=False,
log_time_format="%H:%M:%S.%f",
console=Console(width=os.get_terminal_size().columns),
console=Console(width=width),
)

formatter = logging.Formatter(fmt="%(filename)s:%(lineno)d - %(message)s")
Expand Down
11 changes: 11 additions & 0 deletions tests/flytekit/loggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
from subprocess import run


def test_error(tmp_path):
EXAMPLE = "import flytekit"

script_path = tmp_path / "script.py"
script_path.write_text(EXAMPLE)
out = run([sys.executable, script_path], text=True, capture_output=True)
assert out.stderr == ""

0 comments on commit 743ef90

Please sign in to comment.