Skip to content

Commit

Permalink
Migrate all Python hashbangs to Python 3 (flutter#27838)
Browse files Browse the repository at this point in the history
Migrates all `#!/usr/bin/env python` hashbang lines to use python3.

Also updates the licence tool to treat python3 scripts on par with
python 2 scripts.

Issue: flutter#83043
  • Loading branch information
cbracken committed Jul 31, 2021
1 parent b69df5e commit 9985bc0
Show file tree
Hide file tree
Showing 40 changed files with 95 additions and 74 deletions.
8 changes: 4 additions & 4 deletions build/copy_info_plist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand All @@ -13,9 +13,9 @@
usage: copy_info_plist.py <src_path> <dest_path> --bitcode=<enable_bitcode>
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



import subprocess

import sys
Expand Down
3 changes: 2 additions & 1 deletion build/dart/tools/dart_package_name.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
6 changes: 3 additions & 3 deletions build/dart/tools/dart_pkg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down Expand Up @@ -81,7 +81,7 @@ def copy(from_root, to_root, filter_func=None):
os.makedirs(to_dir)
shutil.copy(from_path, to_path)

dirs[:] = filter(wrapped_filter, dirs)
dirs[:] = list(filter(wrapped_filter, dirs))


def copy_or_link(from_root, to_root, filter_func=None):
Expand Down Expand Up @@ -114,7 +114,7 @@ def list_files(from_root, filter_func=None):
for name in filter(wrapped_filter, files):
path = os.path.join(root, name)
file_list.append(path)
dirs[:] = filter(wrapped_filter, dirs)
dirs[:] = list(filter(wrapped_filter, dirs))
return file_list


Expand Down
4 changes: 2 additions & 2 deletions build/generate_coverage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down Expand Up @@ -84,7 +84,7 @@ def main():

RemoveIfExists(raw_profile)

print "Running test %s to gather profile." % os.path.basename(absolute_test_path)
print("Running test %s to gather profile." % os.path.basename(absolute_test_path))

test_command = [absolute_test_path]

Expand Down
8 changes: 4 additions & 4 deletions build/git_revision.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Get the Git HEAD revision of a specified Git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function




import sys
import subprocess
Expand Down
3 changes: 2 additions & 1 deletion build/zip.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion ci/firebase_testlab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
2 changes: 1 addition & 1 deletion ci/licenses_golden/tool_signature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Signature: 17e2c7f169a5804317b8f79ab1f8a838
Signature: fdaf33383efb94fa6bbc158cbc25635c

3 changes: 2 additions & 1 deletion shell/platform/fuchsia/flutter/build/asset_package.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
3 changes: 2 additions & 1 deletion sky/tools/create_ios_framework.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
3 changes: 2 additions & 1 deletion sky/tools/create_macos_gen_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
9 changes: 5 additions & 4 deletions sky/tools/create_xcframework.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function




import argparse
import errno
Expand Down
3 changes: 2 additions & 1 deletion sky/tools/dist_dart_pkg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
9 changes: 5 additions & 4 deletions sky/tools/flutter_gdb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down Expand Up @@ -39,7 +40,7 @@ def _find_package_pid(adb_path, package):
ps_output = subprocess.check_output([adb_path, 'shell', 'ps'])
ps_match = re.search('^\S+\s+(\d+).*\s%s' % package, ps_output, re.MULTILINE)
if not ps_match:
print 'Unable to find pid for package %s on device' % package
print('Unable to find pid for package %s on device' % package)
return None
return int(ps_match.group(1))

Expand Down Expand Up @@ -114,7 +115,7 @@ class GdbClient(object):

dev_null = open(os.devnull, 'w')
for lib, local_path in sorted(device_libs):
print 'Copying %s' % lib
print('Copying %s' % lib)
local_path = os.path.join(GdbClient.SYSTEM_LIBS_PATH, local_path)
if not os.path.exists(os.path.dirname(local_path)):
os.makedirs(os.path.dirname(local_path))
Expand Down Expand Up @@ -144,7 +145,7 @@ class GdbClient(object):

debug_out_path = os.path.join(flutter_root, 'out/%s' % local_engine)
if not os.path.exists(os.path.join(debug_out_path, 'libflutter.so')):
print 'Unable to find libflutter.so. Make sure you have completed a %s build' % local_engine
print('Unable to find libflutter.so. Make sure you have completed a %s build' % local_engine)
return 1

eval_commands = []
Expand Down
3 changes: 2 additions & 1 deletion sky/tools/install_framework_headers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
3 changes: 2 additions & 1 deletion sky/tools/objcopy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
7 changes: 4 additions & 3 deletions sky/tools/roll/patch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down Expand Up @@ -33,10 +34,10 @@ def patch(dest_dir, relative_patches_dir=os.curdir):

os.chdir(dest_dir)
for p in utils.find(["*.patch"], patches_dir):
print "applying patch %s" % os.path.basename(p)
print("applying patch %s" % os.path.basename(p))
try:
utils.system(["git", "apply", p])
utils.commit("applied patch %s" % os.path.basename(p))
except subprocess.CalledProcessError:
print "ERROR: patch %s failed to apply" % os.path.basename(p)
print("ERROR: patch %s failed to apply" % os.path.basename(p))
raise
15 changes: 8 additions & 7 deletions sky/tools/roll/roll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand All @@ -8,7 +9,7 @@
import os
import subprocess
import sys
import urllib2
import urllib.request, urllib.error, urllib.parse
from utils import commit
from utils import system
import patch
Expand Down Expand Up @@ -96,12 +97,12 @@ def rev(source_dir, dest_dir, dirs_to_rev, name, revision_file=None):
else:
d = dir_to_rev
file_subset = None
print "removing directory %s" % d
print("removing directory %s" % d)
try:
system(["git", "rm", "-r", d], cwd=dest_dir)
except subprocess.CalledProcessError:
print "Could not remove %s" % d
print "cloning directory %s" % d
print("Could not remove %s" % d)
print("cloning directory %s" % d)

if file_subset is None:
files = system(["git", "ls-files", d], cwd=source_dir).splitlines()
Expand Down Expand Up @@ -151,8 +152,8 @@ def main():
try:
patch.patch_and_filter(dest_dir, os.path.join('patches', 'chromium'))
except subprocess.CalledProcessError:
print "ERROR: Roll failed due to a patch not applying"
print "Fix the patch to apply, commit the result, and re-run this script"
print("ERROR: Roll failed due to a patch not applying")
print("Fix the patch to apply, commit the result, and re-run this script")
return 1

return 0
Expand Down
3 changes: 2 additions & 1 deletion sky/tools/roll/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
3 changes: 2 additions & 1 deletion testing/rules/run_gradle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
21 changes: 11 additions & 10 deletions testing/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down Expand Up @@ -27,17 +28,17 @@


def PrintDivider(char='='):
print '\n'
for _ in xrange(4):
print(''.join([char for _ in xrange(80)]))
print '\n'
print('\n')
for _ in range(4):
print(''.join([char for _ in range(80)]))
print('\n')


def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs):
command_string = ' '.join(cmd)

PrintDivider('>')
print 'Running command "%s"' % command_string
print('Running command "%s"' % command_string)

start_time = time.time()
stdout_pipe = sys.stdout if not forbidden_output else subprocess.PIPE
Expand Down Expand Up @@ -70,7 +71,7 @@ def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs):
raise Exception('command "%s" contained forbidden string %s' % (command_string, forbidden_string))

PrintDivider('<')
print 'Command run successfully in %.2f seconds: %s' % (end_time - start_time, command_string)
print('Command run successfully in %.2f seconds: %s' % (end_time - start_time, command_string))


def IsMac():
Expand Down Expand Up @@ -146,7 +147,7 @@ def RunEngineExecutable(build_dir, executable_name, filter, flags=[],
core_path = os.path.join(cwd, 'core')
if luci_test_outputs_path and os.path.exists(core_path) and os.path.exists(unstripped_exe):
dump_path = os.path.join(luci_test_outputs_path, '%s_%s.txt' % (executable_name, sys.platform))
print 'Writing core dump analysis to %s' % dump_path
print('Writing core dump analysis to %s' % dump_path)
subprocess.call([
os.path.join(buildroot_dir, 'flutter', 'testing', 'analyze_core_dump.sh'),
buildroot_dir, unstripped_exe, core_path, dump_path,
Expand Down Expand Up @@ -341,12 +342,12 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'):
EnsureJavaTestsAreBuilt(android_out_dir)

embedding_deps_dir = os.path.join(buildroot_dir, 'third_party', 'android_embedding_dependencies', 'lib')
classpath = map(str, [
classpath = list(map(str, [
os.path.join(buildroot_dir, 'third_party', 'android_tools', 'sdk', 'platforms', 'android-30', 'android.jar'),
os.path.join(embedding_deps_dir, '*'), # Wildcard for all jars in the directory
os.path.join(android_out_dir, 'flutter.jar'),
os.path.join(android_out_dir, 'robolectric_tests.jar')
])
]))

test_class = filter if filter else 'io.flutter.FlutterTestSuite'
command = [
Expand Down
3 changes: 2 additions & 1 deletion tools/android_illegal_imports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
3 changes: 2 additions & 1 deletion tools/androidx/generate_pom_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2019 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
Expand Down
3 changes: 2 additions & 1 deletion tools/dia_dll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2012 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.
Expand Down
2 changes: 1 addition & 1 deletion tools/font-subset/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
2 changes: 1 addition & 1 deletion tools/fuchsia/build_fuchsia_artifacts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
2 changes: 1 addition & 1 deletion tools/fuchsia/compile_cml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
2 changes: 1 addition & 1 deletion tools/fuchsia/copy_debug_symbols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
2 changes: 1 addition & 1 deletion tools/fuchsia/copy_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
Loading

0 comments on commit 9985bc0

Please sign in to comment.