Skip to content

[COPYRIGHT] add copyright pre-commit#481

Merged
mayank31398 merged 2 commits into
mainfrom
copyright
Jun 25, 2026
Merged

[COPYRIGHT] add copyright pre-commit#481
mayank31398 merged 2 commits into
mainfrom
copyright

Conversation

@mayank31398

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Mayank Mishra <mayank31398@gmail.com>
Signed-off-by: Mayank Mishra <mayank31398@gmail.com>
@mayank31398 mayank31398 merged commit 4d1914b into main Jun 25, 2026
2 checks passed
@mayank31398 mayank31398 deleted the copyright branch June 25, 2026 20:20

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

Copy link
Copy Markdown
Contributor

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 integrates automated copyright header management by adding local pre-commit hooks, updating the tools/copyright.py script with a --check option, and applying copyright headers to various files. The review feedback suggests critical improvements: ensuring the --check flag verifies the exact expected header content rather than just matching a generic pattern, expanding the pre-commit hooks to cover all supported file types (not just Python), and optimizing the file extension checks in the copyright script using Python's native endswith tuple support.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tools/copyright.py
Comment on lines +131 to +132
if args.check:
return bool(pattern.match(code))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The check-copyright hook is intended to verify that the copyright header is correct and up-to-date (e.g., checking the correct year and authors). However, using pattern.match(code) only checks if any copyright header matching the general structure exists. It does not verify if the header content (such as the year or author list) matches the expected header. For example, an outdated year like 2025 would still pass the check.

To fix this, we should check if the file starts with the expected header generated by build_header_fn(file).

Suggested change
if args.check:
return bool(pattern.match(code))
if args.check:
header = build_header_fn(file)
return code.startswith(header)

Comment thread .pre-commit-config.yaml
name: add copyright header
language: python
entry: python tools/copyright.py --repo . --header "Copyright (c) 2026, Mayank Mishra" --no-contributors
types: [python]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Since types: [python] is specified, this pre-commit hook will only be triggered if a Python file is staged in the commit. If a developer only modifies C++ (.cpp, .h), YAML, or Markdown files, the hook will be skipped entirely, allowing those files to be committed without copyright headers.

To ensure the hook runs when any supported file type is modified, use types_or with all supported types.

        types_or: [python, c, c++, cuda, yaml, html, markdown]

Comment thread .pre-commit-config.yaml
name: check copyright year
language: python
entry: python tools/copyright.py --repo . --header "Copyright (c) 2026, Mayank Mishra" --no-contributors --check
types: [python]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Since types: [python] is specified, this pre-commit hook will only be triggered if a Python file is staged in the commit. If a developer only modifies C++ (.cpp, .h), YAML, or Markdown files, the hook will be skipped entirely, allowing those files to be committed without copyright headers.

To ensure the hook runs when any supported file type is modified, use types_or with all supported types.

        types_or: [python, c, c++, cuda, yaml, html, markdown]

Comment thread tools/copyright.py
Comment on lines 170 to +175
if any([file.endswith(i) for i in _CPP_LIKE_EXTENSIONS]):
_check_and_add_copyright_header(file, _build_cpp_header, _CPP_PATTERN)
ok = _check_and_add_copyright_header(file, _build_cpp_header, _CPP_PATTERN)
elif any([file.endswith(i) for i in _PYTHON_LIKE_EXTENSIONS]):
_check_and_add_copyright_header(file, _build_python_header, _PYTHON_PATTERN)
ok = _check_and_add_copyright_header(file, _build_python_header, _PYTHON_PATTERN)
elif any([file.endswith(i) for i in _HTML_LIKE_EXTENSIONS]):
_check_and_add_copyright_header(file, _build_html_header, _HTML_PATTERN)
ok = _check_and_add_copyright_header(file, _build_html_header, _HTML_PATTERN)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using any([file.endswith(i) for i in ...]) creates an unnecessary list comprehension and iterates manually. In Python, str.endswith() natively accepts a tuple of strings and performs this check efficiently. We can convert the extension lists to tuples and pass them directly to endswith.

Suggested change
if any([file.endswith(i) for i in _CPP_LIKE_EXTENSIONS]):
_check_and_add_copyright_header(file, _build_cpp_header, _CPP_PATTERN)
ok = _check_and_add_copyright_header(file, _build_cpp_header, _CPP_PATTERN)
elif any([file.endswith(i) for i in _PYTHON_LIKE_EXTENSIONS]):
_check_and_add_copyright_header(file, _build_python_header, _PYTHON_PATTERN)
ok = _check_and_add_copyright_header(file, _build_python_header, _PYTHON_PATTERN)
elif any([file.endswith(i) for i in _HTML_LIKE_EXTENSIONS]):
_check_and_add_copyright_header(file, _build_html_header, _HTML_PATTERN)
ok = _check_and_add_copyright_header(file, _build_html_header, _HTML_PATTERN)
if file.endswith(tuple(_CPP_LIKE_EXTENSIONS)):
ok = _check_and_add_copyright_header(file, _build_cpp_header, _CPP_PATTERN)
elif file.endswith(tuple(_PYTHON_LIKE_EXTENSIONS)):
ok = _check_and_add_copyright_header(file, _build_python_header, _PYTHON_PATTERN)
elif file.endswith(tuple(_HTML_LIKE_EXTENSIONS)):
ok = _check_and_add_copyright_header(file, _build_html_header, _HTML_PATTERN)

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.

1 participant