Skip to content

Commit

Permalink
Migrate all Python scripts to Python 3
Browse files Browse the repository at this point in the history
This migrates all checked in Python scripts to run under Python 3.x.
Python 2.7 reached end-of-life in January of 2020 and has been removed
from may OS distributions at this point.

Rolls buildroot to 607277f

Issue: flutter/flutter#83043
  • Loading branch information
cbracken committed Jun 9, 2021
1 parent c913c75 commit b63f58f
Show file tree
Hide file tree
Showing 37 changed files with 89 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ allowed_hosts = [
]

deps = {
'src': 'https://github.com/flutter/buildroot.git' + '@' + '3ae5da28db8cb028e21150f7472d0938fba2e057',
'src': 'https://github.com/flutter/buildroot.git' + '@' + '607277f54052acd038edb4fe4c2f57fd81d96baf',

# Fuchsia compatibility
#
Expand Down
5 changes: 1 addition & 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,6 @@
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 @@ -75,7 +75,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))

subprocess.check_call([absolute_test_path], env={
"LLVM_PROFILE_FILE": raw_profile
Expand Down
5 changes: 1 addition & 4 deletions build/git_revision.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/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
3 changes: 2 additions & 1 deletion lib/spirv/test/exception_shaders/assemble.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 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,7 +1,9 @@
#!/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.

import argparse
import os
import re
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
7 changes: 2 additions & 5 deletions sky/tools/create_xcframework.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#!/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
import os
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
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
19 changes: 10 additions & 9 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 @@ -26,17 +27,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, **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 @@ -69,7 +70,7 @@ def RunCmd(cmd, forbidden_output=[], expect_failure=False, **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 @@ -394,12 +395,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
5 changes: 3 additions & 2 deletions tools/androidx/generate_pom_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# Copyright 2019 The Flutter Authors. All rights reserved.
#!/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
5 changes: 3 additions & 2 deletions tools/dia_dll.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
#!/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 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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -102,7 +102,7 @@ def main():
raise

if not os.path.exists(dbg_prefix_base):
print 'Unable to create directory: %s.' % dbg_prefix_base
print('Unable to create directory: %s.' % dbg_prefix_base)
return 1

dbg_suffix = ''
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
6 changes: 3 additions & 3 deletions tools/fuchsia/gather_flutter_runner_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 Expand Up @@ -58,11 +58,11 @@ def GatherArtifacts(src_root, dst_root, create_meta_package=True):
else:
shutil.rmtree(dst_root)

for src_rel, dst_rel in _ARTIFACT_PATH_TO_DST.iteritems():
for src_rel, dst_rel in _ARTIFACT_PATH_TO_DST.items():
src_full = os.path.join(src_root, src_rel)
dst_full = os.path.join(dst_root, dst_rel)
if not os.path.exists(src_full):
print 'Unable to find artifact: ', str(src_full)
print('Unable to find artifact: ', str(src_full))
sys.exit(1)
CopyPath(src_full, dst_full)

Expand Down
2 changes: 1 addition & 1 deletion tools/fuchsia/gen_package.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/gen_repo.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/make_build_info.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 b63f58f

Please sign in to comment.