Skip to content

Commit

Permalink
Convert all remaining Python 2 scripts to Python 3 (flutter#495)
Browse files Browse the repository at this point in the history
This applies all remaining migrations in the buildroot, and converts the
hashbang lines to invoke python3.
  • Loading branch information
cbracken authored Aug 1, 2021
1 parent 630be43 commit 6cee685
Show file tree
Hide file tree
Showing 67 changed files with 441 additions and 389 deletions.
2 changes: 1 addition & 1 deletion build/android/gyp/create_flutter_jar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down
5 changes: 2 additions & 3 deletions build/android/gyp/jar.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 Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down Expand Up @@ -48,8 +48,7 @@ def Jar(class_files, classes_dir, jar_path, manifest_file=None, additional_jar_f
def JarDirectory(classes_dir, excluded_classes, jar_path, manifest_file=None, additional_jar_files=None):
class_files = build_utils.FindInDirectory(classes_dir, '*.class')
for exclude in excluded_classes:
class_files = filter(
lambda f: not fnmatch.fnmatch(f, exclude), class_files)
class_files = [f for f in class_files if not fnmatch.fnmatch(f, exclude)]

Jar(class_files, classes_dir, jar_path, manifest_file=manifest_file,
additional_jar_files=additional_jar_files)
Expand Down
4 changes: 2 additions & 2 deletions build/android/gyp/javac.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 Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
Expand Down Expand Up @@ -301,7 +301,7 @@ def main(argv):
if options.jar_path:
if options.main_class or options.manifest_entry:
if options.manifest_entry:
entries = map(lambda e: e.split(":"), options.manifest_entry)
entries = [e.split(":") for e in options.manifest_entry]
else:
entries = []
manifest_file = os.path.join(temp_dir, 'manifest')
Expand Down
3 changes: 2 additions & 1 deletion build/apply_locales.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) 2009 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
3 changes: 2 additions & 1 deletion build/check_return_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2014 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
3 changes: 2 additions & 1 deletion build/check_sdk_extras_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# 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.
Expand Down
3 changes: 2 additions & 1 deletion build/clobber.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# 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.
Expand Down
3 changes: 2 additions & 1 deletion build/compiler_version.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
3 changes: 2 additions & 1 deletion build/config/linux/pkg-config.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) 2013 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
3 changes: 2 additions & 1 deletion build/config/mac/mac_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# Copyright (c) 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.
Expand Down
3 changes: 2 additions & 1 deletion build/config/mac/xcode_toolchain.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# Copyright (c) 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.
Expand Down
3 changes: 2 additions & 1 deletion build/copy_test_data_ios.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
3 changes: 2 additions & 1 deletion build/cp.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
3 changes: 2 additions & 1 deletion build/detect_host_arch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2014 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
3 changes: 2 additions & 1 deletion build/dir_exists.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) 2011 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
3 changes: 2 additions & 1 deletion build/download_gold_plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# 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.
Expand Down
3 changes: 2 additions & 1 deletion build/download_nacl_toolchains.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
3 changes: 2 additions & 1 deletion build/download_sdk_extras.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2014 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
5 changes: 3 additions & 2 deletions build/env_dump.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 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 Expand Up @@ -44,7 +45,7 @@ def main():

env_diff = {}
new_env = json.loads(output)
for k, val in new_env.items():
for k, val in list(new_env.items()):
if k == '_' or (k in os.environ and os.environ[k] == val):
continue
env_diff[k] = val
Expand Down
3 changes: 2 additions & 1 deletion build/extract_from_cab.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
3 changes: 2 additions & 1 deletion build/find_isolated_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 2014 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
8 changes: 4 additions & 4 deletions build/fuchsia/fidl_gen_cpp.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 @@ -36,7 +36,7 @@ def main():

parser.add_argument('--fidlc-bin', dest='fidlc_bin', action='store', required=True)
parser.add_argument('--fidlgen-bin', dest='fidlgen_bin', action='store', required=True)

parser.add_argument('--sdk-base', dest='sdk_base', action='store', required=True)
parser.add_argument('--root', dest='root', action='store', required=True)
parser.add_argument('--json', dest='json', action='store', required=True)
Expand All @@ -63,9 +63,9 @@ def main():

# Create an iterator that works on both python3 and python2
try:
fidl_files_by_name_iter = fidl_files_by_name.items()
fidl_files_by_name_iter = list(fidl_files_by_name.items())
except AttributeError:
fidl_files_by_name_iter = fidl_files_by_name.iteritems()
fidl_files_by_name_iter = iter(fidl_files_by_name.items())

for _, fidl_files in fidl_files_by_name_iter:
fidlc_command.append('--files')
Expand Down
5 changes: 2 additions & 3 deletions build/fuchsia/pave_device.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 @@ -29,9 +29,8 @@ def main():

parser.add_argument('--target',
type=str, dest='target', choices=['chromebook'], default='chromebook')

args = parser.parse_args()


sdk_dir = os.path.join(os.path.dirname(sys.argv[0]),
"..", "..", "fuchsia", "sdk", SDKSubDirectory())
Expand Down
3 changes: 2 additions & 1 deletion build/get_landmines.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 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
3 changes: 2 additions & 1 deletion build/get_sdk_extras_packages.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) 2014 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
17 changes: 9 additions & 8 deletions build/get_syzygy_binaries.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2014 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 Expand Up @@ -86,18 +87,18 @@ def _StateIsValid(state):
_LOGGER.debug('State must be a dict.')
return False
r = state.get('revision', None)
if not isinstance(r, basestring) or not _REVISION_RE.match(r):
if not isinstance(r, str) or not _REVISION_RE.match(r):
_LOGGER.debug('State contains an invalid revision.')
return False
c = state.get('contents', None)
if not isinstance(c, dict):
_LOGGER.debug('State must contain a contents dict.')
return False
for (relpath, md5) in c.iteritems():
if not isinstance(relpath, basestring) or len(relpath) == 0:
for (relpath, md5) in c.items():
if not isinstance(relpath, str) or len(relpath) == 0:
_LOGGER.debug('State contents dict contains an invalid path.')
return False
if not isinstance(md5, basestring) or not _MD5_RE.match(md5):
if not isinstance(md5, str) or not _MD5_RE.match(md5):
_LOGGER.debug('State contents dict contains an invalid MD5 digest.')
return False
return True
Expand All @@ -111,7 +112,7 @@ def _BuildActualState(stored, revision, output_dir):
"""
contents = {}
state = { 'revision': revision, 'contents': contents }
for relpath, md5 in stored['contents'].iteritems():
for relpath, md5 in stored['contents'].items():
abspath = os.path.abspath(os.path.join(output_dir, relpath))
if os.path.isfile(abspath):
m = _Md5(abspath)
Expand All @@ -129,7 +130,7 @@ def _StatesAreConsistent(stored, actual):
return False
cont_stored = stored['contents']
cont_actual = actual['contents']
for relpath, md5 in cont_stored.iteritems():
for relpath, md5 in cont_stored.items():
if relpath not in cont_actual:
_LOGGER.debug('Missing content: %s', relpath)
return False
Expand Down Expand Up @@ -226,7 +227,7 @@ def _CleanState(output_dir, state, dry_run=False):

# Sort directories from longest name to shortest. This lets us remove empty
# directories from the most nested paths first.
dirs = sorted(dirs.keys(), key=lambda x: len(x), reverse=True)
dirs = sorted(list(dirs.keys()), key=lambda x: len(x), reverse=True)
for p in dirs:
if os.path.exists(p) and _DirIsEmpty(p):
_LOGGER.debug('Deleting empty directory "%s".', p)
Expand Down
30 changes: 15 additions & 15 deletions build/gyp_chromium
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/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
Expand Down Expand Up @@ -116,7 +116,7 @@ def GetGypVars(supplemental_files):
with open(supplement, 'r') as f:
try:
file_data = eval(f.read(), {'__builtins__': None}, None)
except SyntaxError, e:
except SyntaxError as e:
e.filename = os.path.abspath(supplement)
raise
variables = file_data.get('variables', [])
Expand Down Expand Up @@ -210,13 +210,13 @@ if __name__ == '__main__':
args.append('-Ganalyzer_output_path=' + args.pop(0))

if int(os.environ.get('GYP_CHROMIUM_NO_ACTION', 0)):
print 'Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.'
print('Skipping gyp_chromium due to GYP_CHROMIUM_NO_ACTION env var.')
sys.exit(0)

# Use the Psyco JIT if available.
if psyco:
psyco.profile()
print "Enabled Psyco JIT."
print("Enabled Psyco JIT.")

# Fall back on hermetic python if we happen to get run under cygwin.
# TODO(bradnelson): take this out once this issue is fixed:
Expand Down Expand Up @@ -273,14 +273,14 @@ if __name__ == '__main__':
# We explicitly don't support the make gyp generator (crbug.com/348686). Be
# nice and fail here, rather than choking in gyp.
if re.search(r'(^|,|\s)make($|,|\s)', os.environ.get('GYP_GENERATORS', '')):
print 'Error: make gyp generator not supported (check GYP_GENERATORS).'
print('Error: make gyp generator not supported (check GYP_GENERATORS).')
sys.exit(1)

# We explicitly don't support the native msvs gyp generator. Be nice and
# fail here, rather than generating broken projects.
if re.search(r'(^|,|\s)msvs($|,|\s)', os.environ.get('GYP_GENERATORS', '')):
print 'Error: msvs gyp generator not supported (check GYP_GENERATORS).'
print 'Did you mean to use the `msvs-ninja` generator?'
print('Error: msvs gyp generator not supported (check GYP_GENERATORS).')
print('Did you mean to use the `msvs-ninja` generator?')
sys.exit(1)

# If CHROMIUM_GYP_SYNTAX_CHECK is set to 1, it will invoke gyp with --check
Expand All @@ -292,13 +292,13 @@ if __name__ == '__main__':
# TODO(dmikurube): Remove these checks and messages after a while.
if ('linux_use_tcmalloc' in gyp_vars_dict or
'android_use_tcmalloc' in gyp_vars_dict):
print '*****************************************************************'
print '"linux_use_tcmalloc" and "android_use_tcmalloc" are deprecated!'
print '-----------------------------------------------------------------'
print 'You specify "linux_use_tcmalloc" or "android_use_tcmalloc" in'
print 'your GYP_DEFINES. Please switch them into "use_allocator" now.'
print 'See http://crbug.com/345554 for the details.'
print '*****************************************************************'
print('*****************************************************************')
print('"linux_use_tcmalloc" and "android_use_tcmalloc" are deprecated!')
print('-----------------------------------------------------------------')
print('You specify "linux_use_tcmalloc" or "android_use_tcmalloc" in')
print('your GYP_DEFINES. Please switch them into "use_allocator" now.')
print('See http://crbug.com/345554 for the details.')
print('*****************************************************************')

# Automatically turn on crosscompile support for platforms that need it.
# (The Chrome OS build sets CC_host / CC_target which implicitly enables
Expand All @@ -316,7 +316,7 @@ if __name__ == '__main__':
args.extend(['-D', 'gyp_output_dir=' + GetOutputDirectory()])

if not use_analyzer:
print 'Updating projects from gyp files...'
print('Updating projects from gyp files...')
sys.stdout.flush()

# Off we go...
Expand Down
3 changes: 2 additions & 1 deletion build/gyp_chromium_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# 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.
Expand Down
3 changes: 2 additions & 1 deletion build/install-build-deps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# 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.
Expand Down
3 changes: 2 additions & 1 deletion build/inverse_depth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2014 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
3 changes: 2 additions & 1 deletion build/landmines.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
Loading

0 comments on commit 6cee685

Please sign in to comment.