-
Notifications
You must be signed in to change notification settings - Fork 16
Fix failing copyright check for year 2026 #105
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Philipp Ahmann <Philipp.Ahmann@de.bosch.com>
32f4585 to
5e791d0
Compare
Signed-off-by: Philipp Ahmann <Philipp.Ahmann@de.bosch.com>
Signed-off-by: Philipp Ahmann <Philipp.Ahmann@de.bosch.com>
|
I hope my checks in the 3 commits were correct. My assumption was that the cr_checker.py from this PR is directly pulled and used to check the PR. If this is not the case the error actually is not really reproducible. |
Signed-off-by: Philipp Ahmann <Philipp.Ahmann@de.bosch.com>
cr_checker/tool/cr_checker.py
Outdated
| out.append(re.escape(ch)) | ||
| i += 1 | ||
|
|
||
| return "".join(out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this code is better or worse than the old regex.
But as long as it works... honestly... no one cares.
Do we know if it works? Like, it seems to accept this PR. But would it reject some other string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Alex, I am not sure, if it does it in all cases. I will use the script call as documented and see if I spot something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexanderLanin okay, I rerun the script locally. I checked with an "O" instead of "0" and also tried with 3 digit "202". It works properly. However, I also rerun the original unchanged script for a file with "2026" being the year and it also works there. So I cannot reproduce the original issue, so I also cannot check, if my change helps.
There was a problem hiding this comment.
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 fixes a bug in the copyright checking script that was causing failures when using year 2026 in copyright headers. The root cause was an invalid empty character class [] in the convert_bre_to_regex function's metacharacters string, which led to malformed regular expressions. The fix completely rewrites the function with a clearer, more maintainable implementation.
Changes:
- Rewrote
convert_bre_to_regexfunction to properly handle BRE-style escape sequences without the invalid[]character class - Updated copyright year to 2026 in the file header
- Fixed typo "coypright" → "copyright" in the
load_exclusiondocstring
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cr_checker/tool/cr_checker.py
Outdated
| L = len(template) | ||
|
|
||
| while i < L: | ||
| ch = template[i] | ||
|
|
||
| # Escape sequences | ||
| if ch == "\\" and i + 1 < L: |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a more descriptive variable name instead of 'L'. In Python, lowercase 'length' or 'template_len' would be more conventional and readable.
| L = len(template) | |
| while i < L: | |
| ch = template[i] | |
| # Escape sequences | |
| if ch == "\\" and i + 1 < L: | |
| template_len = len(template) | |
| while i < template_len: | |
| ch = template[i] | |
| # Escape sequences | |
| if ch == "\\" and i + 1 < template_len: |
cr_checker/tool/cr_checker.py
Outdated
| 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 one character into a regex meta character | ||
| - '*' is literal unless escaped as '\*' (implicitly covered) | ||
| - everything else is taken literally | ||
| """ | ||
| # 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 | ||
|
|
||
| out = [] | ||
| i = 0 | ||
| L = len(template) | ||
|
|
||
| while i < L: | ||
| ch = template[i] | ||
|
|
||
| # Escape sequences | ||
| if ch == "\\" and i + 1 < L: | ||
| nxt = template[i + 1] | ||
|
|
||
| # Next char becomes regex meta character | ||
| out.append(nxt) | ||
| i += 2 | ||
| continue | ||
|
|
||
| # Literal characters → re.escape | ||
| out.append(re.escape(ch)) | ||
| i += 1 | ||
|
|
||
| return "".join(out) |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convert_bre_to_regex function has been completely rewritten, but there are no direct unit tests for this function. Consider adding tests that verify the conversion logic with various inputs, such as templates with escaped characters, special regex metacharacters, and edge cases like trailing backslashes. This would help prevent regressions and document the expected behavior.
cr_checker/tool/cr_checker.py
Outdated
| - '\' escapes one character into a regex meta character | ||
| - '*' is literal unless escaped as '\*' (implicitly covered) | ||
| - everything else is taken literally |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring's second bullet point is potentially confusing. It currently says '' is literal unless escaped as '*', but '*' produces the regex metacharacter '' (zero or more), not a literal asterisk. Consider rewording to clarify that '*' produces the regex wildcard metacharacter, while an unescaped '' is treated as a literal asterisk character. For example: "- '' is treated as a literal asterisk character\n- '*' produces the regex metacharacter '*' (zero or more of the preceding element)"
| - '\' escapes one character into a regex meta character | |
| - '*' is literal unless escaped as '\*' (implicitly covered) | |
| - everything else is taken literally | |
| - '\' escapes the following character and inserts it as a regex metacharacter | |
| - '*' is treated as a literal asterisk character | |
| - '\*' in the template yields the regex metacharacter '*' (zero or more of the preceding element) | |
| - everything else is taken literally (escaped with re.escape) |
Signed-off-by: Philipp Ahmann <Philipp.Ahmann@de.bosch.com>
|
@pahmann maybe this was fixed in #88 which was released in https://github.com/eclipse-score/tooling/releases/tag/v1.0.5 Did you use an older tooling version? |
In recent PRs, when using 2026 in the copyright header the scripting was failing. This patch provides a rewrite of convert_bre_to_regex to what I thought is more readable.
An example of a failing PR can be found here:
https://github.com/eclipse-score/process_description/actions/runs/21507834771/job/61967674606?pr=542#step:4:46
AI explained the root cause as follows (which I was not aware about):
Note that the change still just checks for 4 digits and not if it is a reasonable year. So years like
1234are as valid as4321