Skip to content

Commit

Permalink
Update wording and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed Aug 27, 2024
1 parent 151e9d7 commit fbc7b9e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 23 deletions.
16 changes: 9 additions & 7 deletions src/rapids_pre_commit_hooks/copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ def add_copy_rename_note(
pass
else:
warning.add_note(
(0, len(linter.content)), f"file was {change_verb} from '{old_filename}'"
(0, len(linter.content)),
f"file was {change_verb} from '{old_filename}' and is assumed to share "
"history with it",
)
warning.add_note(
(0, len(linter.content)),
"change file contents if you want its copyright dates to only be "
"determined by its own edit history",
)


Expand All @@ -100,8 +107,6 @@ def apply_copyright_revert(

def apply_copyright_update(
linter: Linter,
change_type: str,
old_filename: Optional[Union[str, os.PathLike[str]]],
match: re.Match,
year: int,
) -> None:
Expand All @@ -113,7 +118,6 @@ def apply_copyright_update(
last_year=year,
),
)
add_copy_rename_note(linter, w, change_type, old_filename)


def apply_copyright_check(
Expand Down Expand Up @@ -145,9 +149,7 @@ def apply_copyright_check(
int(match.group("last_year") or match.group("first_year"))
< current_year
):
apply_copyright_update(
linter, change_type, old_filename, match, current_year
)
apply_copyright_update(linter, match, current_year)
else:
linter.add_warning((0, 0), "no copyright notice found")

Expand Down
104 changes: 88 additions & 16 deletions test/rapids_pre_commit_hooks/test_copyright.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ def test_strip_copyright():
LintWarning(
(15, 24),
"copyright is out of date",
notes=[
Note((0, 185), "file was renamed from 'file1.txt'"),
],
replacements=[
Replacement(
(1, 43), "Copyright (c) 2021-2024, NVIDIA CORPORATION"
Expand All @@ -303,9 +300,6 @@ def test_strip_copyright():
LintWarning(
(58, 62),
"copyright is out of date",
notes=[
Note((0, 185), "file was renamed from 'file1.txt'"),
],
replacements=[
Replacement(
(44, 81), "Copyright (c) 2023-2024, NVIDIA CORPORATION"
Expand Down Expand Up @@ -340,9 +334,6 @@ def test_strip_copyright():
LintWarning(
(15, 24),
"copyright is out of date",
notes=[
Note((0, 185), "file was copied from 'file1.txt'"),
],
replacements=[
Replacement(
(1, 43), "Copyright (c) 2021-2024, NVIDIA CORPORATION"
Expand All @@ -352,9 +343,6 @@ def test_strip_copyright():
LintWarning(
(58, 62),
"copyright is out of date",
notes=[
Note((0, 185), "file was copied from 'file1.txt'"),
],
replacements=[
Replacement(
(44, 81), "Copyright (c) 2023-2024, NVIDIA CORPORATION"
Expand All @@ -363,6 +351,54 @@ def test_strip_copyright():
),
],
),
(
"R",
"file1.txt",
dedent(
r"""
Copyright (c) 2021-2023 NVIDIA CORPORATION
Copyright (c) 2023 NVIDIA CORPORATION
Copyright (c) 2024 NVIDIA CORPORATION
Copyright (c) 2025 NVIDIA CORPORATION
This file has not been changed
"""
),
"file2.txt",
dedent(
r"""
Copyright (c) 2024 NVIDIA CORPORATION
Copyright (c) 2023-2024 NVIDIA CORPORATION
Copyright (c) 2024 NVIDIA CORPORATION
Copyright (c) 2025 NVIDIA CORPORATION
This file has been changed
"""
),
[],
),
(
"C",
"file1.txt",
dedent(
r"""
Copyright (c) 2021-2023 NVIDIA CORPORATION
Copyright (c) 2023 NVIDIA CORPORATION
Copyright (c) 2024 NVIDIA CORPORATION
Copyright (c) 2025 NVIDIA CORPORATION
This file has not been changed
"""
),
"file2.txt",
dedent(
r"""
Copyright (c) 2024 NVIDIA CORPORATION
Copyright (c) 2023-2024 NVIDIA CORPORATION
Copyright (c) 2024 NVIDIA CORPORATION
Copyright (c) 2025 NVIDIA CORPORATION
This file has been changed
"""
),
[],
),
(
"R",
"file1.txt",
Expand Down Expand Up @@ -390,7 +426,16 @@ def test_strip_copyright():
(15, 24),
"copyright is not out of date and should not be updated",
notes=[
Note((0, 189), "file was renamed from 'file1.txt'"),
Note(
(0, 189),
"file was renamed from 'file1.txt' and is assumed to "
"share history with it",
),
Note(
(0, 189),
"change file contents if you want its copyright dates to "
"only be determined by its own edit history",
),
],
replacements=[
Replacement(
Expand All @@ -402,7 +447,16 @@ def test_strip_copyright():
(120, 157),
"copyright is not out of date and should not be updated",
notes=[
Note((0, 189), "file was renamed from 'file1.txt'"),
Note(
(0, 189),
"file was renamed from 'file1.txt' and is assumed to "
"share history with it",
),
Note(
(0, 189),
"change file contents if you want its copyright dates to "
"only be determined by its own edit history",
),
],
replacements=[
Replacement(
Expand Down Expand Up @@ -439,7 +493,16 @@ def test_strip_copyright():
(15, 24),
"copyright is not out of date and should not be updated",
notes=[
Note((0, 189), "file was copied from 'file1.txt'"),
Note(
(0, 189),
"file was copied from 'file1.txt' and is assumed to share "
"history with it",
),
Note(
(0, 189),
"change file contents if you want its copyright dates to "
"only be determined by its own edit history",
),
],
replacements=[
Replacement(
Expand All @@ -451,7 +514,16 @@ def test_strip_copyright():
(120, 157),
"copyright is not out of date and should not be updated",
notes=[
Note((0, 189), "file was copied from 'file1.txt'"),
Note(
(0, 189),
"file was copied from 'file1.txt' and is assumed to share "
"history with it",
),
Note(
(0, 189),
"change file contents if you want its copyright dates to "
"only be determined by its own edit history",
),
],
replacements=[
Replacement(
Expand Down

0 comments on commit fbc7b9e

Please sign in to comment.