Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tensorboard/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ py_library(
srcs_version = "PY2AND3",
visibility = ["//visibility:public"],
deps = [
"//tensorboard:expect_tensorflow_installed",
"//tensorboard/plugins:base_plugin",
"//tensorboard/plugins/audio:audio_plugin",
"//tensorboard/plugins/beholder:beholder_plugin",
Expand Down Expand Up @@ -303,6 +302,7 @@ py_library(
deps = [
"//tensorboard:expect_tensorflow_installed",
"//tensorboard/util",
"//tensorboard/util:platform_util",
"@org_pythonhosted_six",
],
)
Expand Down
1 change: 1 addition & 0 deletions tensorboard/backend/event_processing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ py_library(
srcs_version = "PY2AND3",
deps = [
"//tensorboard/compat:tensorflow",
"//tensorboard/util:platform_util",
],
)

Expand Down
3 changes: 2 additions & 1 deletion tensorboard/backend/event_processing/event_file_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import inspect

from tensorboard.compat import tf
from tensorboard.util import platform_util


class RawEventFileLoader(object):
Expand All @@ -29,7 +30,7 @@ class RawEventFileLoader(object):
def __init__(self, file_path):
if file_path is None:
raise ValueError('A file path is required')
file_path = tf.resource_loader.readahead_file_path(file_path)
file_path = platform_util.readahead_file_path(file_path)
tf.logging.debug('Opening a record reader pointing at %s', file_path)
with tf.errors.raise_exception_on_not_ok_status() as status:
self._reader = tf.pywrap_tensorflow.PyRecordReader_New(
Expand Down
1 change: 0 additions & 1 deletion tensorboard/compat/tensorflow_stub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@
from . import gfile # noqa
from . import logging # noqa
from . import pywrap_tensorflow # noqa
from . import resource_loader # noqa
from . import tensor_manip # noqa
from . import tensor_shape # noqa
120 changes: 0 additions & 120 deletions tensorboard/compat/tensorflow_stub/resource_loader.py

This file was deleted.

16 changes: 0 additions & 16 deletions tensorboard/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from tensorboard.plugins.projector import projector_plugin
from tensorboard.plugins.scalar import scalars_plugin
from tensorboard.plugins.text import text_plugin
import tensorflow as tf


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -81,18 +80,3 @@ def get_plugins():
:rtype: list[Union[base_plugin.TBLoader, Type[base_plugin.TBPlugin]]]
"""
return _PLUGINS[:]

def get_assets_zip_provider():
"""Opens stock TensorBoard web assets collection.

Returns:
Returns function that returns a newly opened file handle to zip file
containing static assets for stock TensorBoard, or None if webfiles.zip
could not be found. The value the callback returns must be closed. The
paths inside the zip file are considered absolute paths on the web server.
"""
path = os.path.join(tf.resource_loader.get_data_files_path(), 'webfiles.zip')
if not os.path.exists(path):
logger.warning('webfiles.zip static assets not found: %s', path)
return None
return lambda: open(path, 'rb')
3 changes: 2 additions & 1 deletion tensorboard/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import six

from tensorboard import db
from tensorboard.util import platform_util
from tensorboard.util import util
import tensorflow as tf

Expand Down Expand Up @@ -145,7 +146,7 @@ def close(self):
def _open(self):
with tf.errors.raise_exception_on_not_ok_status() as status:
return tf.pywrap_tensorflow.PyRecordReader_New(
tf.resource_loader.readahead_file_path(tf.compat.as_bytes(self.path)),
platform_util.readahead_file_path(tf.compat.as_bytes(self.path)),
self._offset, tf.compat.as_bytes(''), status)

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion tensorboard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run_main():
"""Initializes flags and calls main()."""
program.setup_environment()
tensorboard = program.TensorBoard(default.get_plugins(),
default.get_assets_zip_provider())
program.get_default_assets_zip_provider())
try:
from absl import app
# Import this to check that app.run() will accept the flags_parser argument.
Expand Down
19 changes: 1 addition & 18 deletions tensorboard/main_notf.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,11 @@ def get_notf_plugins():
"""
return _NOTF_PLUGINS[:]


def get_assets_zip_provider():
"""Opens stock TensorBoard web assets collection.

Returns:
Returns function that returns a newly opened file handle to zip file
containing static assets for stock TensorBoard, or None if webfiles.zip
could not be found. The value the callback returns must be closed. The
paths inside the zip file are considered absolute paths on the web server.
"""
path = os.path.join(tf.resource_loader.get_data_files_path(), 'webfiles.zip')
if not os.path.exists(path):
logger.warning('webfiles.zip static assets not found: %s', path)
return None
return lambda: open(path, 'rb')


def run_main():
"""Initializes flags and calls main()."""
program.setup_environment()
tensorboard = program.TensorBoard(get_notf_plugins(),
get_assets_zip_provider())
program.get_default_assets_zip_provider())
try:
from absl import app
# Import this to check that app.run() will accept the flags_parser argument.
Expand Down
19 changes: 17 additions & 2 deletions tensorboard/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import socket
import sys
import threading
import inspect

from werkzeug import serving

Expand Down Expand Up @@ -74,6 +75,21 @@ def setup_environment():
# Content-Length header, or do chunked encoding for streaming.
serving.WSGIRequestHandler.protocol_version = 'HTTP/1.1'

def get_default_assets_zip_provider():
"""Opens stock TensorBoard web assets collection.

Returns:
Returns function that returns a newly opened file handle to zip file
containing static assets for stock TensorBoard, or None if webfiles.zip
could not be found. The value the callback returns must be closed. The
paths inside the zip file are considered absolute paths on the web server.
"""
path = os.path.join(os.path.dirname(inspect.getfile(sys._getframe(1))),
'webfiles.zip')
if not os.path.exists(path):
logger.warning('webfiles.zip static assets not found: %s', path)
return None
return lambda: open(path, 'rb')

class TensorBoard(object):
"""Class for running TensorBoard.
Expand Down Expand Up @@ -106,8 +122,7 @@ def __init__(self,
from tensorboard import default
plugins = default.get_plugins()
if assets_zip_provider is None:
from tensorboard import default
assets_zip_provider = default.get_assets_zip_provider()
assets_zip_provider = get_default_assets_zip_provider()
if server_class is None:
server_class = WerkzeugServer
def make_loader(plugin):
Expand Down
5 changes: 5 additions & 0 deletions tensorboard/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ py_test(
],
)

py_library(
name = "platform_util",
srcs = ["platform_util.py"],
srcs_version = "PY2AND3",
)

py_library(
name = "test_util",
Expand Down
25 changes: 25 additions & 0 deletions tensorboard/util/platform_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""TensorBoard helper routine for platform.
"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


def readahead_file_path(path, unused_readahead=None):
"""Readahead files not implemented; simply returns given path."""
return path