4141from reuse import extract
4242from reuse .cli import common
4343from reuse .cli .annotate import add_header_to_file , get_comment_style , get_reuse_info , get_template
44+ from reuse .copyright import YearRange
4445
4546DEFAULT_TEMPLATE = "ansys"
4647"""Default template to use for license headers."""
@@ -518,12 +519,15 @@ def add_header(
518519 tmp: Union[NamedTemporaryFile, IO[str]]
519520 Temporary file to capture the stdout of the add_header_to_file() function or ``sys.stdout``.
520521 """
522+ # Create a YearRange object from the years string to pass into the get_reuse_info function
523+ year_range = YearRange .tuple_from_string (years )
524+
521525 # Get the REUSE information from the file.
522526 reuse_info = get_reuse_info (
523527 copyrights = copyright ,
524528 licenses = license ,
525529 copyright_prefix = "string-c" ,
526- year = years ,
530+ years = year_range ,
527531 contributors = "" ,
528532 )
529533
@@ -538,6 +542,15 @@ def add_header(
538542 out = out ,
539543 )
540544
545+ # Add a space before and after the year range if there is not already one
546+ with Path (file ).open (encoding = "utf-8" , newline = "" , mode = "r" ) as read_file :
547+ content = read_file .read ()
548+ content = re .sub (r"(\d{4})-(\d{4})" , r"\1 - \2" , content )
549+
550+ # Write the updated content back to the file
551+ with Path (file ).open (encoding = "utf-8" , newline = "" , mode = "w" ) as write_file :
552+ write_file .write (content )
553+
541554
542555def check_same_content (before_hook : str , after_hook : str ) -> bool :
543556 """
0 commit comments