aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/platform
diff options
context:
space:
mode:
authorGravatar Charles Nicholson <nicholsonc@google.com>2017-04-21 10:59:14 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-04-21 12:09:42 -0700
commit8e5041918f2e709ded94e63fb1779d6bb363becb (patch)
tree5ec03d51d2e15b1247b68298b2ccd9138075513e /tensorflow/python/platform
parentc3bf39b7a6c3cc41f209ac863c764498b503d4f5 (diff)
Introduce TFDecorator, a base class for Python TensorFlow decorators. Provides basic introspection and "unwrap" services, allowing tooling code to fully 'understand' the wrapped object.
Change: 153854044
Diffstat (limited to 'tensorflow/python/platform')
-rw-r--r--tensorflow/python/platform/benchmark.py5
-rw-r--r--tensorflow/python/platform/googletest.py21
-rw-r--r--tensorflow/python/platform/resource_loader.py8
3 files changed, 18 insertions, 16 deletions
diff --git a/tensorflow/python/platform/benchmark.py b/tensorflow/python/platform/benchmark.py
index ea29399ed2..aa74a419d8 100644
--- a/tensorflow/python/platform/benchmark.py
+++ b/tensorflow/python/platform/benchmark.py
@@ -18,7 +18,6 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import inspect
import numbers
import os
import re
@@ -33,6 +32,8 @@ from tensorflow.python.client import timeline
from tensorflow.python.platform import app
from tensorflow.python.platform import gfile
from tensorflow.python.platform import tf_logging as logging
+from tensorflow.python.util import tf_inspect
+
# When a subclass of the Benchmark class is created, it is added to
# the registry automatically
@@ -135,7 +136,7 @@ class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)):
"""Returns full name of class and method calling report_benchmark."""
# Find the caller method (outermost Benchmark class)
- stack = inspect.stack()
+ stack = tf_inspect.stack()
calling_class = None
name = None
for frame in stack[::-1]:
diff --git a/tensorflow/python/platform/googletest.py b/tensorflow/python/platform/googletest.py
index 1e74b1512b..96219faab7 100644
--- a/tensorflow/python/platform/googletest.py
+++ b/tensorflow/python/platform/googletest.py
@@ -19,7 +19,6 @@ from __future__ import division
from __future__ import print_function
import atexit
-import inspect
import itertools
import os
import sys
@@ -35,6 +34,9 @@ from tensorflow.python.lib.io import file_io
from tensorflow.python.platform import app
from tensorflow.python.platform import benchmark
from tensorflow.python.platform import tf_logging as logging
+from tensorflow.python.util import tf_decorator
+from tensorflow.python.util import tf_inspect
+
Benchmark = benchmark.TensorFlowBenchmark # pylint: disable=invalid-name
@@ -101,9 +103,9 @@ def GetTempDir():
"""Return a temporary directory for tests to use."""
global _googletest_temp_dir
if not _googletest_temp_dir:
- first_frame = inspect.stack()[-1][0]
- temp_dir = os.path.join(
- tempfile.gettempdir(), os.path.basename(inspect.getfile(first_frame)))
+ first_frame = tf_inspect.stack()[-1][0]
+ temp_dir = os.path.join(tempfile.gettempdir(),
+ os.path.basename(tf_inspect.getfile(first_frame)))
temp_dir = tempfile.mkdtemp(prefix=temp_dir.rstrip('.py'))
def delete_temp_dir(dirname=temp_dir):
@@ -204,15 +206,16 @@ class StubOutForTesting(object):
Raises:
AttributeError: If the attribute cannot be found.
"""
- if (inspect.ismodule(obj) or
- (not inspect.isclass(obj) and attr_name in obj.__dict__)):
+ _, obj = tf_decorator.unwrap(obj)
+ if (tf_inspect.ismodule(obj) or
+ (not tf_inspect.isclass(obj) and attr_name in obj.__dict__)):
orig_obj = obj
orig_attr = getattr(obj, attr_name)
else:
- if not inspect.isclass(obj):
- mro = list(inspect.getmro(obj.__class__))
+ if not tf_inspect.isclass(obj):
+ mro = list(tf_inspect.getmro(obj.__class__))
else:
- mro = list(inspect.getmro(obj))
+ mro = list(tf_inspect.getmro(obj))
mro.reverse()
diff --git a/tensorflow/python/platform/resource_loader.py b/tensorflow/python/platform/resource_loader.py
index a53fc541cb..2455acb4c0 100644
--- a/tensorflow/python/platform/resource_loader.py
+++ b/tensorflow/python/platform/resource_loader.py
@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
-
"""Resource management library.
@@get_data_files_path
@@ -25,10 +24,10 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
-import inspect as _inspect
import os as _os
import sys as _sys
+from tensorflow.python.util import tf_inspect as _inspect
from tensorflow.python.util.all_util import remove_undocumented
@@ -44,9 +43,8 @@ def load_resource(path):
Raises:
IOError: If the path is not found, or the resource can't be opened.
"""
- tensorflow_root = (
- _os.path.join(
- _os.path.dirname(__file__), _os.pardir, _os.pardir))
+ tensorflow_root = (_os.path.join(
+ _os.path.dirname(__file__), _os.pardir, _os.pardir))
path = _os.path.join(tensorflow_root, path)
path = _os.path.abspath(path)
with open(path, 'rb') as f: