Skip to content

Commit 6a87eac

Browse files
Make update_copyright ignore shebangs
1 parent bd9843e commit 6a87eac

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

scripts/update_copyright.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# pylint: disable=line-too-long
77
copyright_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

4151
if __name__ == "__main__":
4252
parser = argparse.ArgumentParser(

0 commit comments

Comments
 (0)