55from __future__ import print_function
66import argparse
77import sys
8+ import os
89
910
1011new_copyright = (
@@ -16,17 +17,26 @@ lines = []
1617NO_COPYRIGHT = "NO_COPYRIGHT"
1718OTHER_COPYRIGHT = "OTHER_COPYRIGHT"
1819
20+ # just removes some verbosity in workflow so user can more easily see problems
21+ IN_WORKFLOW = (os .getenv ("GITHUB_ACTIONS" ) == "true" )
22+
1923
2024def find_existing_copyright ():
25+ i_comment_start = None
2126 i_start = None
2227
2328 for i , line in enumerate (lines ):
24- if line .startswith ('#' ) and "Copyright" in line :
25- if "Allan" in line or "Rez" in line :
26- i_start = i
27- break
28- else :
29- return OTHER_COPYRIGHT
29+ if line .startswith ('#' ):
30+ if i_comment_start is None :
31+ i_comment_start = i
32+
33+ if "Copyright" in line :
34+ if "Rez" in line :
35+ i_start = i_comment_start
36+ else :
37+ return OTHER_COPYRIGHT
38+ else :
39+ i_comment_start = None
3040
3141 if i_start is None :
3242 return NO_COPYRIGHT
@@ -59,7 +69,8 @@ if __name__ == "__main__":
5969 result = find_existing_copyright ()
6070
6171 if result == OTHER_COPYRIGHT :
62- print ("Other copyright, skipping %s" % opts .FILE , file = sys .stderr )
72+ if not IN_WORKFLOW :
73+ print ("Other copyright, skipping %s" % opts .FILE , file = sys .stderr )
6374 sys .exit (1 )
6475
6576 # strip existing copyright
@@ -90,6 +101,9 @@ if __name__ == "__main__":
90101
91102 if not opts .overwrite_file :
92103 print (new_txt )
104+ elif new_txt == txt :
105+ if not IN_WORKFLOW :
106+ print ("(file contents unchanged)" )
93107 else :
94108 with open (opts .FILE , 'w' ) as f :
95109 f .write (new_txt )
0 commit comments