From fbc7b9e21bdb9b7e1823a780fa76877b73f94118 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 27 Aug 2024 11:12:24 -0400 Subject: [PATCH] Update wording and logic --- src/rapids_pre_commit_hooks/copyright.py | 16 +-- .../rapids_pre_commit_hooks/test_copyright.py | 104 +++++++++++++++--- 2 files changed, 97 insertions(+), 23 deletions(-) diff --git a/src/rapids_pre_commit_hooks/copyright.py b/src/rapids_pre_commit_hooks/copyright.py index 4a12fdf..53de97e 100644 --- a/src/rapids_pre_commit_hooks/copyright.py +++ b/src/rapids_pre_commit_hooks/copyright.py @@ -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", ) @@ -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: @@ -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( @@ -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") diff --git a/test/rapids_pre_commit_hooks/test_copyright.py b/test/rapids_pre_commit_hooks/test_copyright.py index ee6c1db..3fdec5e 100644 --- a/test/rapids_pre_commit_hooks/test_copyright.py +++ b/test/rapids_pre_commit_hooks/test_copyright.py @@ -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" @@ -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" @@ -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" @@ -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" @@ -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", @@ -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( @@ -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( @@ -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( @@ -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(