Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code to avoid use of rich library #4396

Merged
merged 1 commit into from
Dec 4, 2024
Merged

Refactor code to avoid use of rich library #4396

merged 1 commit into from
Dec 4, 2024

Conversation

ssbarnea
Copy link
Member

@ssbarnea ssbarnea commented Nov 10, 2024

@ssbarnea ssbarnea added the major Used for release notes, requires major versioning bump label Nov 10, 2024
ssbarnea added a commit that referenced this pull request Dec 2, 2024
This change removes the --format option from the affecting the
output of --list-rules. That change is not marked as major because
because it only affect output that is not used in automations.

Related: #4396 AAP-36125
ssbarnea added a commit that referenced this pull request Dec 2, 2024
This change removes the --format option from the affecting the
output of --list-rules. That change is not marked as major because
because it only affect output that is not used in automations.

Related: #4396 AAP-36125
ssbarnea added a commit that referenced this pull request Dec 2, 2024
Related: #4396 AAP-36125Related: #4396 AAP-36125ERER
@ssbarnea ssbarnea changed the title [POC] Refactor code to avoid use of rich library Refactor code to avoid use of rich library Dec 4, 2024
ssbarnea added a commit that referenced this pull request Dec 4, 2024
@ssbarnea ssbarnea marked this pull request as ready for review December 4, 2024 09:40
@ssbarnea ssbarnea requested a review from a team as a code owner December 4, 2024 09:40
ssbarnea added a commit that referenced this pull request Dec 4, 2024
ssbarnea added a commit that referenced this pull request Dec 4, 2024
@ssbarnea ssbarnea requested a review from audgirka December 4, 2024 10:15
@shatakshiiii shatakshiiii marked this pull request as draft December 4, 2024 13:03
ssbarnea added a commit that referenced this pull request Dec 4, 2024
ssbarnea added a commit that referenced this pull request Dec 4, 2024
@ssbarnea ssbarnea marked this pull request as ready for review December 4, 2024 13:59
@ssbarnea ssbarnea merged commit 74afc71 into main Dec 4, 2024
28 of 29 checks passed
@ssbarnea ssbarnea deleted the rm/rich branch December 4, 2024 14:27
@ssbarnea ssbarnea removed major Used for release notes, requires major versioning bump enhancement labels Dec 4, 2024
Copy link
Contributor

@cidrblock cidrblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nitpicky stuff, looks great tho. Sorry about the late review,

# Regex to find opening tags and their content
tag_pattern = re.compile(r"\[([\w\.]+)(?:=(.*?))?\]|\[/\]")

def replace_bb_links(text: str) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get rid of these nested functions? It's really hard to grok.


# Replace matches with HTML <a> tags

def replacement(match: re.Match[str]) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 deep?

print(self.render(data), end=end, file=file or self._file, flush=flush)

def render(self, text: str) -> str:
"""Parses a string containing nested BBCode with a generic block terminator ([/])."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add params to docstrings in google format :)

class AnsiStyle(PlainStyle):
"""Theme."""

@dataclass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is atypical, was there a need to nest this?

file: TextIO | None = None,
flush: bool = False,
) -> None:
"""Internal print implementation."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you comment why this was necessary on the docstring?

"success": (style.success, style.normal),
}
# Regex to find opening tags and their content
tag_pattern = re.compile(r"\[([\w\.]+)(?:=(.*?))?\]|\[/\]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've found putting the regex and the use of in it's own fn to make testing easier and demostrate what it does in the unit tests.

DIM = "\033[1;30m"
BOLD_CYAN = "\033[1;36m"

warning = "\033[33m" # yellow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ref the constant in ANSI?

BOLD_CYAN = "\033[1;36m"

warning = "\033[33m" # yellow
error = ANSI.RED # "\033[31m" # red
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment here probably not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants