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

Update multiple licence year ends in one run - close #94 #98

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions pre_commit_hooks/insert_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,15 @@ def try_update_year_range(
:return: source file contents and a flag indicating update
"""
current_year = datetime.now().year
changed = False
for i in range(license_header_index, license_header_index + license_length):
updated = try_update_year(
src_file_content[i], src_filepath, current_year, introduce_range=True
)
if updated:
src_file_content[i] = updated
return src_file_content, True
return src_file_content, False
changed = True
return src_file_content, changed


def license_found(
Expand Down
14 changes: 14 additions & 0 deletions tests/insert_license_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ def _convert_line_ending(file_path, new_line_endings):
),
),
),
product(
("LICENSE_with_multiple_year_ranges.txt",),
("\n",),
(
(
"module_with_multiple_stale_years_in_license.py",
"#",
"module_with_multiple_years_in_license.py",
"",
True,
["--use-current-year"],
),
),
),
),
),
)
Expand Down
5 changes: 5 additions & 0 deletions tests/resources/LICENSE_with_multiple_year_ranges.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Copyright (C) 2016-2017 Teela O'Malley

Licensed under the Apache License, Version 2.0 (the "License");

@copyright 2012-2015 Teela O'Malley
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (C) 2012-2015 Teela O'Malley
#
# Licensed under the Apache License, Version 2.0 (the "License");
#
# @copyright 2012-2015 Teela O'Malley

import sys
sys.stdout.write("FOO")
8 changes: 8 additions & 0 deletions tests/resources/module_with_multiple_years_in_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (C) 2012-2017 Teela O'Malley
#
# Licensed under the Apache License, Version 2.0 (the "License");
#
# @copyright 2012-2017 Teela O'Malley

import sys
sys.stdout.write("FOO")