From 40f997b7bac1799ff481bad472d63b4d083fe89b Mon Sep 17 00:00:00 2001 From: Akira Baruah Date: Wed, 22 Nov 2017 14:53:22 -0800 Subject: [PATCH] Update tools/ modules for compatibility with python 3. Fixes #4097 (https://github.com/bazelbuild/bazel/issues/4097). --- tools/android/aar_embedded_jars_extractor.py | 2 +- tools/android/aar_native_libs_zip_creator.py | 4 ++-- tools/android/merge_manifests.py | 2 +- tools/android/merge_manifests_test.py | 10 +++++----- tools/android/resource_extractor.py | 2 +- tools/android/stubify_manifest.py | 2 +- tools/build_defs/pkg/archive.py | 2 +- tools/objc/protobuf_compiler.py | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tools/android/aar_embedded_jars_extractor.py b/tools/android/aar_embedded_jars_extractor.py index a46dd43b6fa538..393d3f4c5c3732 100644 --- a/tools/android/aar_embedded_jars_extractor.py +++ b/tools/android/aar_embedded_jars_extractor.py @@ -62,7 +62,7 @@ def _Main(input_aar, if not output_dir_orig: output_dir_orig = output_dir with zipfile.ZipFile(input_aar, "r") as aar: - with open(output_singlejar_param_file, "wb") as singlejar_param_file: + with open(output_singlejar_param_file, "w") as singlejar_param_file: ExtractEmbeddedJars(aar, singlejar_param_file, output_dir, output_dir_orig) diff --git a/tools/android/aar_native_libs_zip_creator.py b/tools/android/aar_native_libs_zip_creator.py index 0195d01cadb115..bcf5931ec7072d 100644 --- a/tools/android/aar_native_libs_zip_creator.py +++ b/tools/android/aar_native_libs_zip_creator.py @@ -63,8 +63,8 @@ def Main(input_aar_path, output_zip_path, cpu, input_aar_path_for_error_msg): try: CreateNativeLibsZip(input_aar, cpu, native_libs_zip) except UnsupportedArchitectureException: - print("AAR " + input_aar_path_for_error_msg + - " missing native libs for requested architecture: " + cpu) + print(("AAR " + input_aar_path_for_error_msg + + " missing native libs for requested architecture: " + cpu)) sys.exit(1) diff --git a/tools/android/merge_manifests.py b/tools/android/merge_manifests.py index 880c55f8503b12..3637030a990d7e 100644 --- a/tools/android/merge_manifests.py +++ b/tools/android/merge_manifests.py @@ -449,7 +449,7 @@ def main(): if FLAGS.exclude_permission: warning = _ValidateAndWarnPermissions(FLAGS.exclude_permission) if warning: - print warning + print(warning) merged_manifests = MergeManifests(_ReadFile(FLAGS.merger), _ReadFiles(FLAGS.mergee), diff --git a/tools/android/merge_manifests_test.py b/tools/android/merge_manifests_test.py index 62d0474e15a065..7567a489f7a48f 100644 --- a/tools/android/merge_manifests_test.py +++ b/tools/android/merge_manifests_test.py @@ -532,12 +532,12 @@ def testMerge(self): ['android.permission.READ_LOGS']) result = merger.Merge() expected = xml.dom.minidom.parseString(MANUALLY_MERGED).toprettyxml() - self.assertEquals(Reformat(expected), Reformat(result)) + self.assertEqual(Reformat(expected), Reformat(result)) def testReformat(self): text = ' a\n b\n\n\n \t c' expected = 'a\nb\nc' - self.assertEquals(expected, Reformat(text)) + self.assertEqual(expected, Reformat(text)) def testValidateAndWarnPermissions(self): permissions = ['android.permission.VIBRATE', 'android.permission.LAUGH'] @@ -589,7 +589,7 @@ def testMergeToCreateValidManifest(self): ['all']) result = merger.Merge() expected = xml.dom.minidom.parseString(VALID_MANIFEST).toprettyxml() - self.assertEquals(Reformat(expected), Reformat(result)) + self.assertEqual(Reformat(expected), Reformat(result)) def testMergeWithNoApplication(self): merger = merge_manifests.MergeManifests( @@ -609,7 +609,7 @@ def testMergeWithNamespaces(self): MERGED_MANIFEST_WITH_EXTRA_NAMESPACE).toprettyxml() # Make sure the result is valid xml (not missing xmlns declarations) result_reparsed = xml.dom.minidom.parseString(result).toprettyxml() - self.assertEquals(Reformat(expected), Reformat(result_reparsed)) + self.assertEqual(Reformat(expected), Reformat(result_reparsed)) def testMergeConflictingNamespaces(self): self.maxDiff = None @@ -618,7 +618,7 @@ def testMergeConflictingNamespaces(self): 'MANIFEST_WITH_CONFLICTING_NAMESPACE'), [(MANIFEST_WITH_EXTRA_NAMESPACE, 'MANIFEST_WITH_EXTRA_NAMESPACE')], ['all']) - with self.assertRaisesRegexp(merge_manifests.MalformedManifestException, + with self.assertRaisesRegex(merge_manifests.MalformedManifestException, 'different values for namespace xmlns:tools'): merger.Merge() diff --git a/tools/android/resource_extractor.py b/tools/android/resource_extractor.py index 2cd11d907c2809..473398cd4cc99c 100644 --- a/tools/android/resource_extractor.py +++ b/tools/android/resource_extractor.py @@ -95,7 +95,7 @@ def ExtractResources(input_jar, output_zip): def main(argv): if len(argv) != 3: - print USAGE + print(USAGE) sys.exit(1) with zipfile.ZipFile(argv[1], 'r') as input_jar: with zipfile.ZipFile(argv[2], 'w') as output_zip: diff --git a/tools/android/stubify_manifest.py b/tools/android/stubify_manifest.py index f415774938cd88..52a5be9f9ff251 100644 --- a/tools/android/stubify_manifest.py +++ b/tools/android/stubify_manifest.py @@ -164,5 +164,5 @@ def main(): try: main() except BadManifestException as e: - print e + print(e) sys.exit(1) diff --git a/tools/build_defs/pkg/archive.py b/tools/build_defs/pkg/archive.py index 9d5ddfa667d350..59728e0655b1cc 100644 --- a/tools/build_defs/pkg/archive.py +++ b/tools/build_defs/pkg/archive.py @@ -35,7 +35,7 @@ class SimpleArFile(object): with SimpleArFile(filename) as ar: nextFile = ar.next() while nextFile: - print nextFile.filename + print(nextFile.filename) nextFile = ar.next() Upon error, this class will raise a ArError exception. diff --git a/tools/objc/protobuf_compiler.py b/tools/objc/protobuf_compiler.py index bd789b7ddd0352..de6c4b9a702ba4 100644 --- a/tools/objc/protobuf_compiler.py +++ b/tools/objc/protobuf_compiler.py @@ -18,5 +18,5 @@ import sys if __name__ == '__main__': - print 'Bazel does not yet support protobuf compiling.' + print('Bazel does not yet support protobuf compiling.') sys.exit(1)