Skip to content

Commit

Permalink
Fix the usage of capitalize() in log.py
Browse files Browse the repository at this point in the history
By capitalizing the entire message strings in log.py, we have
accidentally transformed the path strings in the output to be
lowercase, which is confusing to the user.
  • Loading branch information
JiriPavela committed Jan 1, 2025
1 parent 6835637 commit b2a1c04
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 14 additions & 0 deletions perun/utils/common/common_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,20 @@ def format_counter_number(count: int, max_number: int) -> str:
return f"{count:{len(str(max_number))}d}"


def capitalize_first(string: str) -> str:
"""Helper function that capitalizes only the first letter of a string.
Note that contrary to the library string method `capitalize()` that changes the remaining
characters to lowercase, this helper function does not modify any other character except the
first.
:param string: the string to capitalize
:return: the string with the first letter being uppercase
"""
return string[0].upper() + string[1:]


def default_signal_handler(signum: int, frame: types.FrameType) -> None:
"""Default signal handler used by the HandledSignals CM.
Expand Down
18 changes: 13 additions & 5 deletions perun/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,23 +325,31 @@ def minor_status(msg: str, status: str = "", sep: str = "-") -> None:
It prints the status of some action, starting with `-` with indent and ending with newline.
:param msg: printed message, which will be stripped from whitespace and capitalized
Note, that there are some sanitizations happening to the message:
1. Leading and trailing whitespace characters will be stripped;
2. The first character will be made uppercase, if possible.
:param msg: message to print, will be sanitized
:param status: status of the info
:param sep: separator used to separate the info with its results
"""
write(" " * CURRENT_INDENT * 2 + f" - {msg.strip().capitalize()} {sep} {status}")
write(
" " * CURRENT_INDENT * 2 + f" - {common_kit.capitalize_first(msg.strip())} {sep} {status}"
)


def minor_info(msg: str, end: str = "\n") -> None:
"""Prints minor information, formatted with indent and starting with -
Note, that there are some sanitizations happening:
1. If we want to end the info in new line, we add the punctuations;
1. Leading and trailing whitespace characters will be stripped;
2. The first character will be made uppercase, if possible;
3. If the message ends with a new line, we add a punctuation.
:param msg: printed message, which will be stripped from whitespace and capitalized
:param msg: message to print, will be sanitized
:param end: ending of the message
"""
msg = msg.strip().capitalize()
msg = common_kit.capitalize_first(msg.strip())
if end == "\n" and msg[-1] not in ".!;":
msg += "."
write(" " * CURRENT_INDENT * 2 + f" - {msg}", end)
Expand Down

0 comments on commit b2a1c04

Please sign in to comment.