Skip to content

Commit

Permalink
Fix copyright year in pre-commit test
Browse files Browse the repository at this point in the history
The copyright test uses the current date, rather than the file
modification date. Mock the current date in the pre-commit test.
  • Loading branch information
KyleFromNVIDIA committed Jan 9, 2025
1 parent 6d067aa commit f6ac801
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/rapids_pre_commit_hooks/copyright.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -127,7 +127,14 @@ def apply_copyright_check(
old_content: str | None,
) -> None:
if linter.content != old_content:
current_year = datetime.datetime.now().year
year_env = os.getenv("RAPIDS_TEST_YEAR")
if year_env:
try:
current_year = int(year_env)
except ValueError:
current_year = datetime.datetime.now().year
else:
current_year = datetime.datetime.now().year
new_copyright_matches = match_copyright(linter.content)

if old_content is not None:
Expand Down
4 changes: 2 additions & 2 deletions test/test_pre_commit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2024, NVIDIA CORPORATION.
# Copyright (c) 2024-2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,7 +97,7 @@ def list_files(top):
):
subprocess.check_call(
[sys.executable, "-m", "pre_commit", "try-repo", REPO_DIR, hook_name, "-a"],
env={**os.environ, "TARGET_BRANCH": "master"},
env={**os.environ, "TARGET_BRANCH": "master", "RAPIDS_TEST_YEAR": "2024"},
)


Expand Down

0 comments on commit f6ac801

Please sign in to comment.