Skip to content
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

fix clean copyright #29

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
46 changes: 27 additions & 19 deletions data_prep/github/github_clean_dedup_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,46 @@ def get_timestamp() -> str:


def clean_copyright_comments(content: str):
r = PAT.search(content)
if r:
# found one, now see if it contains "copyright", if so strip it
span = r.span()
sub = content[span[0]:span[1]]
if CPAT.search(sub):
# cut it
content = content[: span[0]] + content[span[1]:]

return content

lines = content.split('\n')
skip = 0

# Greedy replace any file that begins with comment block, most
# are copyright headers
for k in range(len(lines)):
if (
lines[k].startswith("//") or
lines[k].startswith("#") or
lines[k].startswith("--") or
lines[k].lstrip().startswith("//") or
lines[k].lstrip().startswith("#") or
lines[k].lstrip().startswith("--") or
not lines[k]
):
skip = skip + 1
else:
break

if skip:
# we skipped, consume it
content = "\n".join(lines[skip:])

return content
lines = lines[skip:]

if len(lines) > 100:
top100_line_content = '\n'.join(lines[:100])
r = PAT.search(top100_line_content)
if r:
# found one, now see if it contains "copyright", if so strip it
span = r.span()
sub = top100_line_content[span[0]:span[1]]
if CPAT.search(sub):
# cut it
top100_line_content = top100_line_content[: span[0]] + top100_line_content[span[1]:]
return top100_line_content + '\n' + '\n'.join(lines[100:])
else:
content = '\n'.join(lines)
r = PAT.search(content)
if r:
# found one, now see if it contains "copyright", if so strip it
span = r.span()
sub = content[span[0]:span[1]]
if CPAT.search(sub):
# cut it
content = content[: span[0]] + content[span[1]:]
return content


def get_filecontent_stats(content: str) -> Dict[str, Union[int, str]]:
Expand Down