55
66# pylint: disable=line-too-long
77copyright_blob = f"""######################################################################################
8- # Copyright (c) { datetime .today ().year } Orange. All rights reserved. #
8+ # Copyright (c) 2023- { datetime .today ().year } Orange. All rights reserved. #
99# This software is distributed under the BSD 3-Clause-clear License, the text of #
1010# which is available at https://spdx.org/licenses/BSD-3-Clause-Clear.html or #
1111# see the "LICENSE.md" file for more details. #
@@ -27,16 +27,26 @@ def update_copyright(file_path):
2727 lines = file .readlines ()
2828 skipped_copyright = False
2929 with open (file_path , "w" , encoding = "utf8" ) as file :
30- file .write (copyright_blob )
31- for line in lines :
32- if line .startswith ("#" ) and not skipped_copyright :
30+ for line_number , line in enumerate (lines , start = 1 ):
31+ # Write any shebang
32+ if line .startswith ("#!" ) and line_number == 1 :
33+ file .write (line )
34+ # Ignore a previous copyright banner
35+ elif line .startswith ("#" ) and not skipped_copyright :
3336 continue
37+ # After reading the old banner write the new and any line after
3438 elif not line .startswith ("#" ) and not skipped_copyright :
3539 skipped_copyright = True
40+ file .write (copyright_blob )
3641 file .write (line )
3742 elif skipped_copyright :
3843 file .write (line )
3944
45+ # Write copyright if in not in skipped_copyright state at the end of the file
46+ # This case is for files with only the banner (ex. __init__.py)
47+ if not skipped_copyright :
48+ file .write (copyright_blob )
49+
4050
4151if __name__ == "__main__" :
4252 parser = argparse .ArgumentParser (
0 commit comments