Skip to content

Commit

Permalink
Make update_copyright ignore shebangs
Browse files Browse the repository at this point in the history
  • Loading branch information
folmos-at-orange committed Jan 10, 2025
1 parent 1012a6f commit 09c337f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions scripts/update_copyright.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
######################################################################################
# Copyright (c) 2025 Orange. All rights reserved. #
# This software is distributed under the BSD 3-Clause-clear License, the text of #
# which is available at https://spdx.org/licenses/BSD-3-Clause-Clear.html or #
# see the "LICENSE.md" file for more details. #
######################################################################################
"""Updates the copyright notice of the input files"""

import argparse
Expand Down Expand Up @@ -27,16 +33,26 @@ def update_copyright(file_path):
lines = file.readlines()
skipped_copyright = False
with open(file_path, "w", encoding="utf8") as file:
file.write(copyright_blob)
for line in lines:
if line.startswith("#") and not skipped_copyright:
for line_number, line in enumerate(lines, start=1):
# Write any shebang
if line.startswith("#!") and line_number == 1:
file.write(line)
# Ignore a previous copyright banner
elif line.startswith("#") and not skipped_copyright:
continue
# After reading the old banner write the new and any line after
elif not line.startswith("#") and not skipped_copyright:
skipped_copyright = True
file.write(copyright_blob)
file.write(line)
elif skipped_copyright:
file.write(line)

# Write copyright if still in not in skipped_copyright state
# This case is for files with only the banner (ex.__init__.py)
if not skipped_copyright:
file.write(copyright_blob)


if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand Down

0 comments on commit 09c337f

Please sign in to comment.