Skip to content

Commit

Permalink
Update multiple licence year ends in one run - close #94 (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C committed Jan 16, 2024
1 parent b26c56d commit d50596b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
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")

0 comments on commit d50596b

Please sign in to comment.