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}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
dd0a664ba1
commit
f9819f2e35
PRESUBMIT.pyPRESUBMIT_test.py
build
chrome/updater
components/feed/core/v2/tools
testing/libfuzzer
third_party/blink/web_tests/mhtml/resources
tools
25
PRESUBMIT.py
25
PRESUBMIT.py
@@ -5514,3 +5514,28 @@ def CheckRawPtrUsage(input_api, output_api):
|
||||
'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
|
||||
|
@@ -4057,5 +4057,28 @@ class CheckRawPtrUsageTest(unittest.TestCase):
|
||||
error.message)
|
||||
|
||||
|
||||
class AssertPythonShebangTest(unittest.TestCase):
|
||||
def testError(self):
|
||||
input_api = MockInputApi()
|
||||
input_api.files = [
|
||||
MockFile('ash/test.py', ['#!/usr/bin/python']),
|
||||
MockFile('chrome/test.py', ['#!/usr/bin/python2']),
|
||||
MockFile('third_party/blink/test.py', ['#!/usr/bin/python3']),
|
||||
]
|
||||
errors = PRESUBMIT.CheckPythonShebang(input_api, MockOutputApi())
|
||||
self.assertEqual(3, len(errors))
|
||||
|
||||
def testNonError(self):
|
||||
input_api = MockInputApi()
|
||||
input_api.files = [
|
||||
MockFile('chrome/browser/BUILD.gn', ['#!/usr/bin/python']),
|
||||
MockFile('third_party/blink/web_tests/external/test.py',
|
||||
['#!/usr/bin/python2']),
|
||||
MockFile('third_party/test/test.py', ['#!/usr/bin/python3']),
|
||||
]
|
||||
errors = PRESUBMIT.CheckPythonShebang(input_api, MockOutputApi())
|
||||
self.assertEqual(0, len(errors))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2.7
|
||||
#!/usr/bin/env python2
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2020 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python2
|
||||
#
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python2
|
||||
#
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python2
|
||||
#
|
||||
# Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python2
|
||||
# Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python2
|
||||
# Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python2
|
||||
#!/usr/bin/env python2
|
||||
#
|
||||
# Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2013, Opera Software ASA. All rights reserved.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python3
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
Reference in New Issue
Block a user