Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9985bc0

Browse files
authored
Migrate all Python hashbangs to Python 3 (#27838)
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/flutter#83043
1 parent b69df5e commit 9985bc0

40 files changed

+95
-74
lines changed

build/copy_info_plist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be
@@ -13,9 +13,9 @@
1313
usage: copy_info_plist.py <src_path> <dest_path> --bitcode=<enable_bitcode>
1414
"""
1515

16-
from __future__ import absolute_import
17-
from __future__ import division
18-
from __future__ import print_function
16+
17+
18+
1919
import subprocess
2020

2121
import sys

build/dart/tools/dart_package_name.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

build/dart/tools/dart_pkg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be
@@ -81,7 +81,7 @@ def copy(from_root, to_root, filter_func=None):
8181
os.makedirs(to_dir)
8282
shutil.copy(from_path, to_path)
8383

84-
dirs[:] = filter(wrapped_filter, dirs)
84+
dirs[:] = list(filter(wrapped_filter, dirs))
8585

8686

8787
def copy_or_link(from_root, to_root, filter_func=None):
@@ -114,7 +114,7 @@ def list_files(from_root, filter_func=None):
114114
for name in filter(wrapped_filter, files):
115115
path = os.path.join(root, name)
116116
file_list.append(path)
117-
dirs[:] = filter(wrapped_filter, dirs)
117+
dirs[:] = list(filter(wrapped_filter, dirs))
118118
return file_list
119119

120120

build/generate_coverage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be
@@ -84,7 +84,7 @@ def main():
8484

8585
RemoveIfExists(raw_profile)
8686

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

8989
test_command = [absolute_test_path]
9090

build/git_revision.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be
55
# found in the LICENSE file.
66

77
"""Get the Git HEAD revision of a specified Git repository."""
8-
from __future__ import absolute_import
9-
from __future__ import division
10-
from __future__ import print_function
8+
9+
10+
1111

1212
import sys
1313
import subprocess

build/zip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

ci/firebase_testlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

ci/licenses_golden/tool_signature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Signature: 17e2c7f169a5804317b8f79ab1f8a838
1+
Signature: fdaf33383efb94fa6bbc158cbc25635c
22

shell/platform/fuchsia/flutter/build/asset_package.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

shell/platform/fuchsia/flutter/build/gen_debug_wrapper_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

sky/tools/create_ios_framework.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

sky/tools/create_macos_gen_snapshots.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

sky/tools/create_xcframework.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.
56

6-
from __future__ import absolute_import
7-
from __future__ import division
8-
from __future__ import print_function
7+
8+
9+
910

1011
import argparse
1112
import errno

sky/tools/dist_dart_pkg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

sky/tools/flutter_gdb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.
@@ -39,7 +40,7 @@ def _find_package_pid(adb_path, package):
3940
ps_output = subprocess.check_output([adb_path, 'shell', 'ps'])
4041
ps_match = re.search('^\S+\s+(\d+).*\s%s' % package, ps_output, re.MULTILINE)
4142
if not ps_match:
42-
print 'Unable to find pid for package %s on device' % package
43+
print('Unable to find pid for package %s on device' % package)
4344
return None
4445
return int(ps_match.group(1))
4546

@@ -114,7 +115,7 @@ class GdbClient(object):
114115

115116
dev_null = open(os.devnull, 'w')
116117
for lib, local_path in sorted(device_libs):
117-
print 'Copying %s' % lib
118+
print('Copying %s' % lib)
118119
local_path = os.path.join(GdbClient.SYSTEM_LIBS_PATH, local_path)
119120
if not os.path.exists(os.path.dirname(local_path)):
120121
os.makedirs(os.path.dirname(local_path))
@@ -144,7 +145,7 @@ class GdbClient(object):
144145

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

150151
eval_commands = []

sky/tools/install_framework_headers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

sky/tools/objcopy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

sky/tools/roll/patch.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.
@@ -33,10 +34,10 @@ def patch(dest_dir, relative_patches_dir=os.curdir):
3334

3435
os.chdir(dest_dir)
3536
for p in utils.find(["*.patch"], patches_dir):
36-
print "applying patch %s" % os.path.basename(p)
37+
print("applying patch %s" % os.path.basename(p))
3738
try:
3839
utils.system(["git", "apply", p])
3940
utils.commit("applied patch %s" % os.path.basename(p))
4041
except subprocess.CalledProcessError:
41-
print "ERROR: patch %s failed to apply" % os.path.basename(p)
42+
print("ERROR: patch %s failed to apply" % os.path.basename(p))
4243
raise

sky/tools/roll/roll.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.
@@ -8,7 +9,7 @@
89
import os
910
import subprocess
1011
import sys
11-
import urllib2
12+
import urllib.request, urllib.error, urllib.parse
1213
from utils import commit
1314
from utils import system
1415
import patch
@@ -96,12 +97,12 @@ def rev(source_dir, dest_dir, dirs_to_rev, name, revision_file=None):
9697
else:
9798
d = dir_to_rev
9899
file_subset = None
99-
print "removing directory %s" % d
100+
print("removing directory %s" % d)
100101
try:
101102
system(["git", "rm", "-r", d], cwd=dest_dir)
102103
except subprocess.CalledProcessError:
103-
print "Could not remove %s" % d
104-
print "cloning directory %s" % d
104+
print("Could not remove %s" % d)
105+
print("cloning directory %s" % d)
105106

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

158159
return 0

sky/tools/roll/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

testing/rules/run_gradle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

testing/run_tests.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.
@@ -27,17 +28,17 @@
2728

2829

2930
def PrintDivider(char='='):
30-
print '\n'
31-
for _ in xrange(4):
32-
print(''.join([char for _ in xrange(80)]))
33-
print '\n'
31+
print('\n')
32+
for _ in range(4):
33+
print(''.join([char for _ in range(80)]))
34+
print('\n')
3435

3536

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

3940
PrintDivider('>')
40-
print 'Running command "%s"' % command_string
41+
print('Running command "%s"' % command_string)
4142

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

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

7576

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

343344
embedding_deps_dir = os.path.join(buildroot_dir, 'third_party', 'android_embedding_dependencies', 'lib')
344-
classpath = map(str, [
345+
classpath = list(map(str, [
345346
os.path.join(buildroot_dir, 'third_party', 'android_tools', 'sdk', 'platforms', 'android-30', 'android.jar'),
346347
os.path.join(embedding_deps_dir, '*'), # Wildcard for all jars in the directory
347348
os.path.join(android_out_dir, 'flutter.jar'),
348349
os.path.join(android_out_dir, 'robolectric_tests.jar')
349-
])
350+
]))
350351

351352
test_class = filter if filter else 'io.flutter.FlutterTestSuite'
352353
command = [

tools/android_illegal_imports.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2013 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

tools/androidx/generate_pom_file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright 2019 The Flutter Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

tools/dia_dll.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
2+
#
23
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
34
# Use of this source code is governed by a BSD-style license that can be
45
# found in the LICENSE file.

tools/font-subset/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

tools/fuchsia/build_fuchsia_artifacts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

tools/fuchsia/compile_cml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

tools/fuchsia/copy_debug_symbols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

tools/fuchsia/copy_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright 2013 The Flutter Authors. All rights reserved.
44
# Use of this source code is governed by a BSD-style license that can be

0 commit comments

Comments
 (0)