Skip to content
Open
Changes from all commits
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
44 changes: 32 additions & 12 deletions cr_checker/tool/cr_checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# *******************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
Expand All @@ -10,6 +10,9 @@
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************

# Some portions generated by Copilot

"""The tool for checking if artifacts have proper copyright."""

import argparse
Expand Down Expand Up @@ -124,17 +127,34 @@ def get_author_from_config(config_path: Path = None) -> str:

def convert_bre_to_regex(template: str) -> str:
"""
Convert BRE-style template (literal by default) to standard regex.
In the template: * is literal, \\* is a metacharacter.
Convert a BRE-like template into a regex:
- '\' escapes the following character and inserts it as a regex meta character
- '*' is treated as a literal asterisk character
- '\*' in the template yields the regex meta character '*' (zero or more of the preceding element)
- everything else is taken literally (escaped with re.escape)
"""
# First, escape all regex metacharacters to make them literal
escaped = re.escape(template)
# Now, find escaped backslashes followed by escaped metacharacters
# and convert them back to actual regex metacharacters
metacharacters = r"\\.*+-?[]{}()^$|"
for char in metacharacters:
escaped = escaped.replace(re.escape("\\" + char), char)
return escaped

escaped = []
i = 0
template_len = len(template)

while i < template_len:
current_ch = template[i]

# Escape sequences
if current_ch == "\\" and i + 1 < template_len:
nxt = template[i + 1]

# Next char becomes regex meta character
escaped.append(nxt)
i += 2
continue

# Literal characters → re.escape
escaped.append(re.escape(current_ch))
i += 1

return "".join(escaped)


def load_templates(path):
Expand Down Expand Up @@ -194,7 +214,7 @@ def load_exclusion(path):
path (str): Path to the exclusion file.

Returns:
tuple(list, bool): a list of files that are excluded from the coypright check and a boolean indicating whether
tuple(list, bool): a list of files that are excluded from the copyright check and a boolean indicating whether
all paths listed in the exclusion file exist and are files.
"""

Expand Down