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
[ci] add check for copyright header #41
[ci] add check for copyright header #41
Conversation
d94767a
to
4f45d5d
Compare
ci/checks/check_copyright.py
Outdated
@@ -0,0 +1,169 @@ | |||
#!/usr/bin/python |
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.
/usr/bin/env python3
ci/checks/check_copyright.py
Outdated
|
||
cpp_exts = {".hpp", ".cpp", ".cu", ".cuh", ".cc", ".h", ".c"} | ||
|
||
cpp_copyright = """/* |
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.
probably best put an r in front of this string
ci/checks/check_copyright.py
Outdated
Args: | ||
f - Path to file | ||
""" | ||
if 'Copyright (c)' in open(f).read(): |
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.
return 'Copyright (c)' in open(f).read()
more pythonic
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.
Also, don't know if you want to just use the regex module to check if the string we have is in there, might make it easier also to replace existing copyright notices etc
ci/checks/check_copyright.py
Outdated
|
||
# Get list of files to check. | ||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
root_dir = os.path.abspath(os.path.join(script_dir, "../../")) |
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.
better to use pathlib.
from pathlib import Path
Path('foo').parent
..
will break OS interop
ci/checks/check_copyright.py
Outdated
|
||
# Check/Add headers if need be. | ||
if (args.add_header): | ||
map(add_copyright, missing_header_files) |
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.
a matter of style, but list comprehensions are preferred to map
ci/checks/check_copyright.py
Outdated
|
||
import sys | ||
import os | ||
import mmap |
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.
unused import
ci/checks/check_copyright.py
Outdated
import argparse | ||
import re | ||
from subprocess import check_output | ||
from stat import * |
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.
best to never use import *
ci/checks/check_copyright.py
Outdated
add optionally copyright header to them. | ||
""" | ||
|
||
import sys |
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.
could these imports be sorted alphabetically
ci/checks/check_copyright.py
Outdated
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
root_dir = os.path.abspath(os.path.join(script_dir, "../../")) | ||
files = get_tracked_files(root_dir) | ||
files = filter_files(files, "LICENSE|README|data\/|docs\/") |
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.
this string should be a raw string r"LICENSE|README|data\/|docs\/"
. Otherwise the \/
character combination can be interpreted as an escape sequence (probably an invalid one) by different tools, editors etc
a971b39
to
6060670
Compare
5aff485
to
68c3eac
Compare
Add script to check for copyright header Fail CI if copyright headers are missing
68c3eac
to
23ad564
Compare
Add script to check for copyright header
Fail CI if copyright headers are missing