Skip to content

refactor: random non-important change - #12

Merged
VioletsOleander merged 2 commits into
mainfrom
refa
May 26, 2026
Merged

refactor: random non-important change#12
VioletsOleander merged 2 commits into
mainfrom
refa

Conversation

@VioletsOleander

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 26, 2026 11:51

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors LogCanonicalizer to return the canonicalized lines, renames _LogSection.Other to _LogSection.OTHER, and moves _LogSection and _match_section to the bottom of the file. It also updates imports in main.py and updates the CLI description in parser.py. However, moving _LogSection and _match_section to the bottom of the file introduces a runtime NameError because they are referenced in type annotations before they are defined. This should be resolved by moving them back to the top or using from __future__ import annotations.

Comment on lines +144 to +158
class _LogSection(StrEnum):
DOC = "Doc"
PAPER = "Paper"
WIKI = "Wiki"
OTHER = "Other"


def _match_section(
line: str, section_patterns: dict[_LogSection, re.Pattern]
) -> _LogSection | None:
"""Return the log section type if the line matches any section pattern, else None."""
for section_type, pattern in section_patterns.items():
if pattern.fullmatch(line):
return section_type
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

Moving _LogSection and _match_section to the bottom of the file causes a NameError at runtime when importing this module.\n\nIn Python, type annotations in function/method signatures (such as log_section: _LogSection in _canonicalize_line and _canonicalize_item) are evaluated when the class/function is defined. Since _LogSection is now defined at the bottom of the file (after LogCanonicalizer), importing canonicalizer.py will fail with:\nNameError: name '_LogSection' is not defined\n\nTo resolve this, please move _LogSection and _match_section back to the top of the file (before LogCanonicalizer), or import from __future__ import annotations at the very top of the file.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the CLI argument parser messaging and refactors log canonicalization to return the processed lines, updating the main entrypoint accordingly.

Changes:

  • Updated CLI description text in the argument parser.
  • Switched main.py to import parse_args from vanillian.parser and to use the return value of LogCanonicalizer.canonicalize().
  • Refactored LogCanonicalizer.canonicalize() to return list[str] and normalized _LogSection.OTHER naming.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/vanillian/parser.py Updates CLI description string.
src/vanillian/main.py Fixes parse_args import and uses returned canonicalized lines.
src/vanillian/log/canonicalizer.py Changes canonicalize() to return lines and renames _LogSection member; moves enum/helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 12 to +18
class LogCanonicalizer:
def __init__(self) -> None:
self.section_patterns = {
_LogSection.DOC: re.compile(r"\\\[Doc\\\]\s"),
_LogSection.PAPER: re.compile(r"\\\[Paper\\\]\s"),
_LogSection.WIKI: re.compile(r"\\\[Wiki\\\]\s"),
_LogSection.Other: re.compile(r"\\\[.+\\\]\s"),
_LogSection.OTHER: re.compile(r"\\\[.+\\\]\s"),
Comment on lines +25 to 46
def canonicalize(self, lines: list[str], *, force: bool = False) -> list[str]:
"""Canonicalize log items in the provided lines.

Modifies the input lines in place.

Args:
lines (list[str]): The lines of the log file.
force (bool, optional): If True, canonicalize without asking for confirmation. Defaults to False.

Returns:
list[str]: The canonicalized log lines.
"""
logger.info("Starting log canonicalization.")
current_section = _LogSection.Other

current_section = _LogSection.OTHER
for idx, line in enumerate(lines):
if (match := _match_section(line, self.section_patterns)) is not None:
level = logger.info if current_section != _LogSection.Other else logger.debug
level = logger.info if current_section != _LogSection.OTHER else logger.debug
level("Line: %d: Entering section: '%s'", idx, match.value)
current_section = match
elif self.log_item_pattern.match(line) and current_section != _LogSection.Other:
elif self.log_item_pattern.match(line) and current_section != _LogSection.OTHER:
logger.info("Line: %d: Processing...", idx)
lines[idx] = self._canonicalize_line(current_section, line, force=force)
logger.info("Line: %d: Finished processing.", idx)
Copilot AI review requested due to automatic review settings May 26, 2026 12:42
@VioletsOleander
VioletsOleander merged commit 9bfaa61 into main May 26, 2026
2 of 5 checks passed
@VioletsOleander
VioletsOleander deleted the refa branch May 26, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +146 to +155
class _LogSection(StrEnum):
DOC = "Doc"
PAPER = "Paper"
WIKI = "Wiki"
OTHER = "Other"


def _match_section(
line: str, section_patterns: dict[_LogSection, re.Pattern]
) -> _LogSection | None:
Comment on lines +28 to +35
Modify the input lines in place.

Args:
lines (list[str]): The lines of the log file.
force (bool, optional): If True, canonicalize without asking for confirmation. Defaults to False.

Returns:
list[str]: The canonicalized log lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants