Use #!/usr/bin/env python/2/3 in remaining .py files
Replace every shebang like /usr/bin/python[23] with /usr/bin/env
python[23] as appropriate in Chromium and Blink, except for WPT. Also,
add a presubmit check to disallow the former going forward.
build/print_python_deps.py is changed from using python2.7 to python2.
remoting/ python scripts are left out as they are meant to be run in
users' machines.
Bug: 1191100
Change-Id: If7ebf7bd8ad9b2695a471e0a403a592815a0d959
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537832
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/main@{#946427}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 1ffbe52..646b3ed 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -5514,3 +5514,28 @@
'section in //base/memory/raw_ptr.md)'.format(
path=f.LocalPath(), line=line_num)))
return errors
+
+
+def CheckPythonShebang(input_api, output_api):
+ """Checks that python scripts use #!/usr/bin/env instead of hardcoding a
+ system-wide python.
+ """
+ errors = []
+ sources = lambda affected_file: input_api.FilterSourceFile(
+ affected_file,
+ files_to_skip=((_THIRD_PARTY_EXCEPT_BLINK,
+ r'third_party/blink/web_tests/external/') + input_api.
+ DEFAULT_FILES_TO_SKIP),
+ files_to_check=[r'.*\.py$'])
+ for f in input_api.AffectedSourceFiles(sources):
+ [line_num, line] = f.ChangedContents()[0]
+ if line_num == 1 and line.startswith('#!/usr/bin/python'):
+ errors.append(f.LocalPath())
+
+ result = []
+ for file in errors:
+ result.append(
+ output_api.PresubmitError(
+ "Please use '#!/usr/bin/env python/2/3' as the shebang of %s" %
+ file))
+ return result