From 4fd68060e4174ed9024f8895a8a792ffd930fbf4 Mon Sep 17 00:00:00 2001 From: Konstantin Dobler Date: Mon, 11 Sep 2023 19:06:41 +0200 Subject: [PATCH] Escape printed strings by default --- src/print_on_steroids/print.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/print_on_steroids/print.py b/src/print_on_steroids/print.py index 3fce633..fe474c5 100644 --- a/src/print_on_steroids/print.py +++ b/src/print_on_steroids/print.py @@ -120,7 +120,7 @@ def print_on_steroids( print_origin: bool = False, sep: str = " ", end: str = "\n", - escape: bool = False, + escape: bool = True, stack_offset: int = 1, ): if rank0_only and rank != 0: @@ -161,7 +161,7 @@ def namespace_print_on_steroids( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=True, ): if rank0_only and rank != 0: return @@ -183,6 +183,7 @@ def __init__( package_name: str = None, rank: int = None, print_rank0_only=False, + escape=True, ): if mode == "from_env": assert package_name is not None @@ -192,6 +193,7 @@ def __init__( self.rank = rank self.print_rank0_only = print_rank0_only self.verbosity = verbosity + self.escape = escape def log( self, @@ -201,7 +203,7 @@ def log( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, stack_offset=2, print_time=True, print_level=True, @@ -215,6 +217,8 @@ def log( rank = self.rank if rank0_only is None: rank0_only = self.print_rank0_only + if self.escape is None: + self.escape = escape if self.mode == "dev": print_on_steroids( @@ -243,7 +247,7 @@ def print( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, print_time=False, print_level=False, print_origin=False, @@ -269,7 +273,7 @@ def debug( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, print_time=True, print_level=False, print_origin=True, @@ -295,7 +299,7 @@ def info( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, print_time=True, print_level=True, print_origin=True, @@ -321,7 +325,7 @@ def success( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, print_time=True, print_level=True, print_origin=True, @@ -347,7 +351,7 @@ def warning( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, print_time=True, print_level=True, print_origin=True, @@ -373,7 +377,7 @@ def error( rank0_only: bool = None, sep=" ", end="\n", - escape=False, + escape=None, print_time=True, print_level=True, print_origin=True, @@ -399,12 +403,14 @@ def config( package_name: str = None, rank: int = None, print_rank0_only: bool = None, + escape: bool = None, ): self.rank = self.rank if rank is None else rank self.mode = self.mode if mode is None else mode self.package_name = self.package_name if package_name is None else package_name self.print_rank0_only = self.print_rank0_only if print_rank0_only is None else print_rank0_only self.verbosity = self.verbosity if verbosity is None else verbosity + self.escape = self.escape if escape is None else escape def set_rank(self, rank: int): self.rank = rank @@ -475,6 +481,7 @@ def my_func(arg1, arg2): exc_message = "".join([*formatted_traceback, formatted_exception]) if relative_to is not None: + def make_filepaths_relative(match): file_path, line_number, function_name = match.groups() if relative_to in file_path: