-
Notifications
You must be signed in to change notification settings - Fork 38.6k
contrib: remove copyright_header.py
#34119
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
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34119. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste |
-BEGIN VERIFY SCRIPT-
sed --in-place --regexp-extended \
's;( 20[0-2][0-9])(-20[0-2][0-9])? The Bitcoin Core developers;\1-present The Bitcoin Core developers;g' \
$( git grep -l 'The Bitcoin Core developers' -- ':(exclude)COPYING' ':(exclude)src/ipc/libmultiprocess' ':(exclude)src/minisketch' )
-END VERIFY SCRIPT-
2d851ce to
ba6315d
Compare
|
Should we add copyrights to the sources that don't currently have any such header (see: #34084 (comment))? |
|
ACK ba6315d Double-checked that no further references to the script anywhere else in the docs were missed with some grepping. |
I think they've all been added. |
rkrux
left a comment
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.
crACK ba6315d
While the script is detailed enough, agree on removing it now - prefer to not have code present if it will not be used anymore.
janb84
left a comment
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.
ACK ba6315d
PR removes script that manages copyright headers. Given that the new approach is to use -present or no range at all, make the script obsolete.
NIT / suggestion: transform the script to be a linter so that the CI checks for a (correct) copyright:
lint-copyright.py
#!/usr/bin/env python3
#
# Copyright (c) 2025-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
Check that all source files have proper copyright headers.
"""
import re
import sys
import fnmatch
from subprocess import check_output
# Excludes for specific files
EXCLUDE = [
# Autogenerated:
'src/qt/bitcoinstrings.cpp',
'src/chainparamsseeds.h',
# Other external copyrights:
'src/test/fuzz/FuzzedDataProvider.h',
'src/tinyformat.h',
'src/bench/nanobench.h',
'contrib/devtools/clang-format-diff.py',
# Python init files:
'*__init__.py',
# Devtools bitcoin-tidy example:
'contrib/devtools/bitcoin-tidy/example_nontrivial-threadlocal.cpp',
# contrib files:
'contrib/devtools/check-deps.sh',
'contrib/macdeploy/gen-sdk.py',
'contrib/verify-binaries/test.py',
]
EXCLUDE_DIRS = [
# git subtrees
"src/crypto/ctaes/",
"src/leveldb/",
"src/minisketch/",
"src/secp256k1/",
"src/crc32c/",
]
# File extensions to include
INCLUDE = ['*.h', '*.cpp', '*.cc', '*.c', '*.mm', '*.py', '*.sh', '*.bash-completion']
# Compile patterns
EXCLUDE_COMPILED = re.compile('|'.join([fnmatch.translate(m) for m in EXCLUDE]))
INCLUDE_COMPILED = re.compile('|'.join([fnmatch.translate(m) for m in INCLUDE]))
# Generic copyright pattern (accepts any copyright holder)
# Matches "Copyright" with optional "(c)", and optional year/year-range
COPYRIGHT_COMPILED = re.compile(r'Copyright', re.IGNORECASE)
def applies_to_file(filename: str) -> bool:
for excluded_dir in EXCLUDE_DIRS:
if filename.startswith(excluded_dir):
return False
return (EXCLUDE_COMPILED.match(filename) is None and
INCLUDE_COMPILED.match(filename) is not None)
def get_filenames_to_examine() -> list[str]:
git_ls_cmd = ['git', 'ls-files', '--full-name']
all_files = check_output(git_ls_cmd, text=True).splitlines()
return sorted([f for f in all_files if applies_to_file(f)])
def file_has_copyright(filename: str) -> bool:
"""
Check if file has a copyright header in the first 10 lines.
"""
try:
with open(filename, 'r', encoding='utf-8') as f:
# Read first 10 lines
first_lines = ''.join(f.readline() for _ in range(10))
except (UnicodeDecodeError, IOError):
# Skip binary files or files that can't be read
return True
return COPYRIGHT_COMPILED.search(first_lines) is not None
def main():
exit_code = 0
files_to_examine = get_filenames_to_examine()
missing_copyright = []
for filename in files_to_examine:
if not file_has_copyright(filename):
missing_copyright.append(filename)
if missing_copyright:
print(f"The following {len(missing_copyright)} file(s) have no copyright notice:")
for filename in missing_copyright:
print(f" {filename}")
exit_code = 1
sys.exit(exit_code)
if __name__ == '__main__':
main()
After #34084, our copyright headers shouldn't need "managing"; so remove the Python script.