From: Yong Tang Date: Thu, 5 Apr 2018 23:52:07 +0000 (-0700) Subject: Fix an issue caused by (#18183) X-Git-Tag: tflite-v0.1.7~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=73f25fc34c69878c83ee2eeb8f030cb79a76472f;p=platform%2Fupstream%2Ftensorflow.git Fix an issue caused by (#18183) While trying to run on my machine (Ubuntu 16.04 Python 2.7) ``` bazel test -s --config=opt --cache_test_results=no //tensorflow/tools/api/tests:api_compatibility_test ``` The following error was encountered: ``` ...... File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/ad1e09741bb4109fbc70ef8216b59ee2/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/tools/api/generator/create_python_api.py", line 125, in get_api_imports if not module or 'tensorflow.' not in module.__name__: File "/usr/lib/python2.7/dist-packages/py/_apipkg.py", line 171, in __getattribute__ return getattr(getmod(), name) File "/usr/lib/python2.7/dist-packages/py/_error.py", line 43, in __getattr__ raise AttributeError(name) AttributeError: __name__ ``` The issue is that `` does not have a `__name__` attribute (See similiar issue in https://github.com/pytest-dev/py/issues/73). This fix tries to address the issue by adding an `hasattr()` check so that AttributeError is not thrown. Signed-off-by: Yong Tang --- diff --git a/tensorflow/tools/api/generator/create_python_api.py b/tensorflow/tools/api/generator/create_python_api.py index 183c473..70f9776 100644 --- a/tensorflow/tools/api/generator/create_python_api.py +++ b/tensorflow/tools/api/generator/create_python_api.py @@ -122,7 +122,8 @@ def get_api_imports(): # we want to traverse over TensorFlow Python modules. for module in sys.modules.values(): # Only look at tensorflow modules. - if not module or 'tensorflow.' not in module.__name__: + if (not module or not hasattr(module, "__name__") or + 'tensorflow.' not in module.__name__): continue # Do not generate __init__.py files for contrib modules for now. if '.contrib.' in module.__name__ or module.__name__.endswith('.contrib'):