Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"@graphql-codegen/cli": "^6.1.2",
"@graphql-codegen/typescript-graphql-request": "^6.4.0",
"@graphql-codegen/typescript-operations": "^5.0.8",
"@open-cmsis-pack/vsce-helper": "^0.2.4",
"@open-cmsis-pack/vsce-helper": "^0.3.0",
"@playwright/test": "^1.58.2",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
Expand Down
81 changes: 56 additions & 25 deletions update_copyright_years.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/usr/bin/env python3
"""
Copyright (C) 2025-2026 Arm Limited
Copyright 2025-2026 Arm Limited

This script updates copyright headers in source files to reflect the current year.
It supports headers in the format:
Copyright (C) <original year> Arm Limited
Copyright (C) <original year>-<current year> Arm Limited
If the header does not reflect the current year, it will be updated to <original year>-<current year>.
SPDX-FileCopyrightText headers are also updated similarly.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

The script is generated using ChatGPT
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

generated with AI
"""

import re, sys, pathlib
Expand All @@ -18,39 +23,63 @@
CURRENT_YEAR = datetime.datetime.now().year # Use system year

COPYRIGHT_PATTERN = re.compile(
r'(?P<prefix>Copyright(?:\s*\(c\))?[^0-9\n]{0,40})'
r'\bCopyright(?:[ \t]*\(c\))?[ \t]*'
r'(?P<y1>\d{4})'
r'(?:\s*-\s*(?P<y2>\d{4}))?',
flags=re.IGNORECASE
)
SPDX_PATTERN = re.compile(
r'(?P<prefix>SPDX-FileCopyrightText:\s*)'
r'(?P<y1>\d{4})'
r'(?:\s*-\s*(?P<y2>\d{4}))?',
r'(?:[ \t]*-[ \t]*(?P<y2>\d{4}))?'
r'(?:[ \t]+Arm[ \t]+Limited\b)*',
flags=re.IGNORECASE
)

def update_text(t: str):
changed = False

def canonical_copyright(y1: int, y2: int | None) -> str:
if y2 is None:
return f"Copyright {y1} Arm Limited"
return f"Copyright {y1}-{y2} Arm Limited"

def repl(m):
nonlocal changed
y1 = int(m.group('y1'))
y2 = m.group('y2')
if y2:
y2 = int(y2)
if y2 >= CURRENT_YEAR: return m.group(0)
changed = True
return f"{m.group('prefix')}{y1}-{CURRENT_YEAR}"
target_y2 = y2 if y2 >= CURRENT_YEAR else CURRENT_YEAR
new_text = canonical_copyright(y1, target_y2)
else:
if y1 == CURRENT_YEAR: return m.group(0)
changed = True
return f"{m.group('prefix')}{y1}-{CURRENT_YEAR}"
new_text = (
canonical_copyright(y1, None)
if y1 == CURRENT_YEAR
else canonical_copyright(y1, CURRENT_YEAR)
)

if new_text == m.group(0):
return m.group(0)

changed = True
return new_text

t2 = COPYRIGHT_PATTERN.sub(repl, t)
t2 = SPDX_PATTERN.sub(repl, t2)
return t2, changed


def collect_paths() -> list[str]:
# Prefer explicit CLI paths; otherwise read piped stdin.
if len(sys.argv) > 1:
return [p.strip() for p in sys.argv[1:] if p.strip()]
if not sys.stdin.isatty():
return [p.strip() for p in sys.stdin if p.strip()]
return []

def main():
paths = [p.strip() for p in sys.stdin if p.strip()]
paths = collect_paths()
if not paths:
print(
"Usage: python update_copyright_years.py <file1> <file2> ...\n"
" or: <command that outputs file paths> | python update_copyright_years.py"
)
return 2

updated = 0
for p in paths:
fp = pathlib.Path(p)
Expand All @@ -69,5 +98,7 @@ def main():
print(f"[OK ] {p}")
updated += 1
print(f"Updated {updated} files to year {CURRENT_YEAR}")
return 0

if __name__ == "__main__":
main()
raise SystemExit(main())
Loading