Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions scripts/rm_set_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
DEFAULT_OPTIONS,
PROJECT_DIR,
commented_pattern,
is_annotated,
lake_build_with_progress,
lakefile_pattern,
removable_pattern,
Expand Down Expand Up @@ -198,6 +199,8 @@ def scan_files(dag: DAG, options: list[str], value: str = "false") -> dict[str,
for i, line in enumerate(lines):
if any(p.match(line) for p in commented_pats):
continue
if is_annotated(lines, i):
continue
if any(p.match(line) for p in removable_pats):
removable.append(i)
if removable:
Expand All @@ -206,12 +209,16 @@ def scan_files(dag: DAG, options: list[str], value: str = "false") -> dict[str,


def count_skipped(filepath: Path, options: list[str], value: str = "false") -> int:
"""Count set_option lines with trailing comments."""
"""Count set_option lines with trailing/preceding comments."""
commented_pats = [commented_pattern(opt, value) for opt in options]
removable_pats = [removable_pattern(opt, value) for opt in options]
lines = filepath.read_text().splitlines()
count = 0
for line in filepath.read_text().splitlines():
for i, line in enumerate(lines):
if any(p.match(line) for p in commented_pats):
count += 1
elif any(p.match(line) for p in removable_pats) and is_annotated(lines, i):
count += 1
return count


Expand Down
14 changes: 14 additions & 0 deletions scripts/set_option_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ def commented_pattern(option: str, value: str = "false") -> re.Pattern:
return re.compile(rf"^\s*set_option {escaped} {escaped_val} in\s+--")


def is_annotated(lines: list[str], idx: int) -> bool:
"""Check whether line `idx` is immediately preceded by a `--` comment
or by a (possibly multi-line) `/-- ... -/` doc comment.
Comment thread
vlad902 marked this conversation as resolved.
Outdated
"""
if idx == 0:
return False
prev = lines[idx - 1]
if re.search(r"^\s*--", prev):
return True
if re.search(r"-/\s*$", prev):
return True
return False


def lakefile_pattern(option: str, value: str = "false") -> re.Pattern:
"""Match lakefile entries for an option."""
escaped = re.escape(option)
Expand Down
Loading