|
18 | 18 | from __future__ import division |
19 | 19 | from __future__ import print_function |
20 | 20 |
|
| 21 | +import contextlib |
| 22 | + |
21 | 23 | from tensorboard.compat import tf |
22 | 24 | from tensorboard.compat.proto import event_pb2 |
23 | 25 | from tensorboard.util import platform_util |
|
27 | 29 | logger = tb_logging.get_logger() |
28 | 30 |
|
29 | 31 |
|
| 32 | +@contextlib.contextmanager |
| 33 | +def _nullcontext(): |
| 34 | + """Pre-Python-3.7-compatible standin for contextlib.nullcontext.""" |
| 35 | + yield |
| 36 | + |
| 37 | + |
| 38 | +# Might as well make this a singleton. |
| 39 | +_NULLCONTEXT = _nullcontext() |
| 40 | + |
| 41 | + |
| 42 | +def _silence_deprecation_warnings(): |
| 43 | + """Context manager that best-effort silences TF deprecation warnings.""" |
| 44 | + try: |
| 45 | + # Learn this one weird trick to make TF deprecation warnings go away. |
| 46 | + from tensorflow.python.util import deprecation |
| 47 | + |
| 48 | + return deprecation.silence() |
| 49 | + except (ImportError, AttributeError): |
| 50 | + return _NULLCONTEXT |
| 51 | + |
| 52 | + |
30 | 53 | def _make_tf_record_iterator(file_path): |
31 | 54 | """Returns an iterator over TF records for the given tfrecord file.""" |
32 | 55 | # If we don't have TF at all, use the stub implementation. |
@@ -55,7 +78,9 @@ def _make_tf_record_iterator(file_path): |
55 | 78 | return _PyRecordReaderIterator(py_record_reader_new, file_path) |
56 | 79 | else: |
57 | 80 | logger.debug("Opening a tf_record_iterator pointing at %s", file_path) |
58 | | - return tf.compat.v1.io.tf_record_iterator(file_path) |
| 81 | + # TODO(#1711): Find non-deprecated replacement for tf_record_iterator. |
| 82 | + with _silence_deprecation_warnings(): |
| 83 | + return tf.compat.v1.io.tf_record_iterator(file_path) |
59 | 84 |
|
60 | 85 |
|
61 | 86 | class _PyRecordReaderIterator(object): |
|
0 commit comments