marcoabreu closed pull request #13178: License header
URL: https://github.com/apache/incubator-mxnet/pull/13178
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/tools/license_header.py b/tools/license_header.py
index 2f12a14795c..10ba8b909e7 100755
--- a/tools/license_header.py
+++ b/tools/license_header.py
@@ -24,11 +24,11 @@
- add the default license header to source files that do not contain a valid
license:
- python license_header.py add
+ license_header.py add
- check if every files has a license header
- python license_header.py check
+ license_header.py check
"""
import re
@@ -126,24 +126,27 @@ def _valid_file(fname, verbose=False):
def process_file(fname, action, verbose=True):
if not _valid_file(fname, verbose):
return True
- with open(fname, 'r', encoding="utf-8") as f:
- lines = f.readlines()
- if not lines:
+ try:
+ with open(fname, 'r', encoding="utf-8") as f:
+ lines = f.readlines()
+ if not lines:
+ return True
+ if _has_license(lines):
+ return True
+ elif action == 'check':
+ return False
+ _, ext = os.path.splitext(fname)
+ with open(fname, 'w', encoding="utf-8") as f:
+ # shebang line
+ if lines[0].startswith('#!'):
+ f.write(lines[0].rstrip()+'\n\n')
+ del lines[0]
+ f.write(_get_license(_LANGS[ext]))
+ for l in lines:
+ f.write(l.rstrip()+'\n')
+ logging.info('added license header to ' + fname)
+ except UnicodeError:
return True
- if _has_license(lines):
- return True
- elif action == 'check':
- return False
- _, ext = os.path.splitext(fname)
- with open(fname, 'w', encoding="utf-8") as f:
- # shebang line
- if lines[0].startswith('#!'):
- f.write(lines[0].rstrip()+'\n\n')
- del lines[0]
- f.write(_get_license(_LANGS[ext]))
- for l in lines:
- f.write(l.rstrip()+'\n')
- logging.info('added license header to ' + fname)
return True
def process_folder(root, action):
@@ -155,7 +158,7 @@ def process_folder(root, action):
excepts.append(fname)
if action == 'check' and excepts:
logging.warning('The following files do not contain a valid license, '+
- 'you can use `python tools/license_header.py add
[file]` to add'+
+ 'you can use `tools/license_header.py add [file]` to
add'+
'them automatically: ')
for x in excepts:
logging.warning(x)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services