Skip to content

Commit

Permalink
Update tools/ modules for compatibility with python 3.
Browse files Browse the repository at this point in the history
Fixes #4097.
Fixes part of #4310.

Closes #4265.

PiperOrigin-RevId: 179437184
  • Loading branch information
akirabaruah authored and Copybara-Service committed Dec 18, 2017
1 parent 2040c60 commit 408ea37
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tools/android/aar_embedded_jars_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tools/android/aar_native_libs_zip_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
4 changes: 3 additions & 1 deletion tools/android/merge_manifests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

"""Merges two android manifest xml files."""

from __future__ import print_function

import re
import sys
import xml.dom.minidom
Expand Down Expand Up @@ -449,7 +451,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),
Expand Down
9 changes: 4 additions & 5 deletions tools/android/merge_manifests_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -625,4 +625,3 @@ def testMergeConflictingNamespaces(self):

if __name__ == '__main__':
unittest.main()

4 changes: 3 additions & 1 deletion tools/android/resource_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
python resource_extractor.py <input jar> <output zip>
"""

from __future__ import print_function

import sys
import zipfile

Expand Down Expand Up @@ -95,7 +97,7 @@ def ExtractResources(input_jar, output_zip):

def main(argv):
if len(argv) != 3:
print USAGE

This comment has been minimized.

Copy link
@stylite5

stylite5 Jan 24, 2018

Excuse me, i meet a problem when i build tensorflow_android_demo:
/tools/android/resource_extractor.py", line 98
print USAGE
SyntaxError: Missing parentheses in call to 'print'

The script need and assumes the default /usr/bin/python is linked to python 2.x which in my case is not,

It is an auto generated script. Though i correct the script, it will report the same error in the next build. I don't know where to change the suitable python path and how to solve the problem. You say that update tools and modules, and i don't understand which tool or module to update. I have updated the bazel to the latest version,but it's useless.
I also tried to change the python path in the build file and bazel.rc, it was also useless.
I hope to get your answer as soon as possible. Thank you very much.

This comment has been minimized.

Copy link
@akirabaruah

akirabaruah Jan 27, 2018

Author Contributor

Hi @stylite5 - thanks for bringing up the issue.

This commit updates files for compatibility with Python 3, resolving the first error you listed. If you're using the latest version of Bazel, you shouldn't have to modify any files yourself. Which versions/commits of Bazel, Tensorflow, Android SDK, and Android NDK did you finally use to build the tensorflow android demo?

Feel free to submit an Issue on this repository if you'd like more visibility on this problem. I think it'd help if you could list the details I asked about above to reproduce the problem. Thanks!

print(USAGE)
sys.exit(1)
with zipfile.ZipFile(argv[1], 'r') as input_jar:
with zipfile.ZipFile(argv[2], 'w') as output_zip:
Expand Down
4 changes: 3 additions & 1 deletion tools/android/stubify_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
Writes the old application class into the file designated by the third argument.
"""

from __future__ import print_function

import sys
from xml.etree import ElementTree

Expand Down Expand Up @@ -164,5 +166,5 @@ def main():
try:
main()
except BadManifestException as e:
print e
print(e)
sys.exit(1)
2 changes: 1 addition & 1 deletion tools/build_defs/pkg/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion tools/objc/protobuf_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

"""Dummy python executable."""

from __future__ import print_function

import sys

if __name__ == '__main__':
print 'Bazel does not yet support protobuf compiling.'
print('Bazel does not yet support protobuf compiling.')
sys.exit(1)

1 comment on commit 408ea37

@stylite5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuse me, i meet a problem when i build tensorflow_android_demo:
/tools/android/resource_extractor.py", line 98
print USAGE
SyntaxError: Missing parentheses in call to 'print'

The script need and assumes the default /usr/bin/python is linked to python 2.x which in my case is not,

It is an auto generated script. Though i correct the script, it will report the same error in the next build. I don't know where to change the suitable python path and how to solve the problem. You say that update tools and modules, and i don't understand which tool or module to update. I have updated the bazel to the latest version,but it's useless.
I also tried to change the python path in the build file and bazel.rc, it was also useless.
I hope to get your answer as soon as possible. Thank you very much.

Please sign in to comment.