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 @@ -29,7 +29,7 @@ py_binary(
":program",
"//tensorboard:expect_tensorflow_installed",
"//tensorboard/plugins:base_plugin",
"//tensorboard/uploader:uploader_main_lib",
"//tensorboard/uploader:uploader_subcommand",
"//tensorboard/util:tb_logging",
"//tensorboard/util:timing", # non-strict dep, for patching convenience
],
Expand Down
4 changes: 2 additions & 2 deletions tensorboard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from tensorboard import program
from tensorboard.compat import tf
from tensorboard.plugins import base_plugin
from tensorboard.uploader import uploader_main
from tensorboard.uploader import uploader_subcommand
from tensorboard.util import tb_logging


Expand All @@ -64,7 +64,7 @@ def run_main():
tensorboard = program.TensorBoard(
default.get_plugins() + default.get_dynamic_plugins(),
program.get_default_assets_zip_provider(),
subcommands=[uploader_main.UploaderSubcommand()],
subcommands=[uploader_subcommand.UploaderSubcommand()],
)
try:
from absl import app
Expand Down
23 changes: 8 additions & 15 deletions tensorboard/uploader/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ licenses(["notice"]) # Apache 2.0
exports_files(["LICENSE"])

py_library(
name = "exporter_lib",
name = "exporter",
srcs = ["exporter.py"],
srcs_version = "PY3",
deps = [
Expand All @@ -25,7 +25,7 @@ py_test(
name = "exporter_test",
srcs = ["exporter_test.py"],
deps = [
":exporter_lib",
":exporter",
":test_util",
":util",
"//tensorboard:expect_grpc_installed",
Expand Down Expand Up @@ -59,24 +59,17 @@ py_test(
],
)

py_binary(
name = "uploader",
srcs = ["uploader_main.py"],
main = "uploader_main.py",
deps = [":uploader_main_lib"],
)

py_library(
name = "uploader_main_lib",
srcs = ["uploader_main.py"],
name = "uploader_subcommand",
Copy link
Contributor

Choose a reason for hiding this comment

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

This new name is much clearer; thanks!

srcs = ["uploader_subcommand.py"],
visibility = ["//tensorboard:internal"],
deps = [
":auth",
":exporter_lib",
":exporter",
":flags_parser",
":formatters",
":server_info",
":uploader_lib",
":uploader",
":util",
"//tensorboard:expect_absl_app_installed",
"//tensorboard:expect_absl_flags_argparse_flags_installed",
Expand All @@ -91,7 +84,7 @@ py_library(
)

py_library(
name = "uploader_lib",
name = "uploader",
srcs = ["uploader.py"],
deps = [
":logdir_loader",
Expand Down Expand Up @@ -119,7 +112,7 @@ py_test(
srcs_version = "PY3",
deps = [
":test_util",
":uploader_lib",
":uploader",
":util",
"//tensorboard:data_compat",
"//tensorboard:dataclass_compat",
Expand Down
18 changes: 0 additions & 18 deletions tensorboard/uploader/flags_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from __future__ import division
from __future__ import print_function

from absl.flags import argparse_flags

SUBCOMMAND_FLAG = "_uploader__subcommand"
SUBCOMMAND_KEY_UPLOAD = "UPLOAD"
Expand All @@ -33,23 +32,6 @@
DEFAULT_ORIGIN = "https://tensorboard.dev"


def parse_flags(argv):
"""Parse flags for TensorBoard.dev uploader.

Exits if flag values are invalid.

Args:
argv: CLI arguments, as with `sys.argv`, where the first argument is taken
to be the name of the program being executed.
"""
parser = argparse_flags.ArgumentParser(
prog="uploader",
description=("Upload your TensorBoard experiments to TensorBoard.dev"),
)
define_flags(parser)
return parser.parse_args(argv[1:])


def define_flags(parser):
"""Configures flags on the provided argument parser.

Expand Down
28 changes: 24 additions & 4 deletions tensorboard/uploader/flags_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,44 @@

import argparse

from absl.flags import argparse_flags

from tensorboard.uploader import flags_parser
from tensorboard import test as tb_test


def _define_and_parse_flags(argv):
"""Defines and parses flags.

Creates an `ArgumentParser`, defines flags on the parser (the logic really
being tested), and parses given arguments.

Args:
argv: CLI arguments, as with `sys.argv`, where the first argument is taken
to be the name of the program being executed.
"""
parser = argparse_flags.ArgumentParser(
prog="uploader",
description=("Upload your TensorBoard experiments to TensorBoard.dev"),
)
flags_parser.define_flags(parser)
return parser.parse_args(argv[1:])


class FlagsParserTest(tb_test.TestCase):
def test_unknown_command(self):
with self.assertRaises(SystemExit):
flags_parser.parse_flags(["uploader", "unknown"])
_define_and_parse_flags(["uploader", "unknown"])

def test_list(self):
flags = flags_parser.parse_flags(["uploader", "list"])
flags = _define_and_parse_flags(["uploader", "list"])
self.assertEqual(
flags_parser.SUBCOMMAND_KEY_LIST,
getattr(flags, flags_parser.SUBCOMMAND_FLAG),
)

def test_upload_logdir(self):
flags = flags_parser.parse_flags(
flags = _define_and_parse_flags(
["uploader", "upload", "--logdir", "some/log/dir"]
)
self.assertEqual(
Expand All @@ -47,7 +67,7 @@ def test_upload_logdir(self):
self.assertEqual("some/log/dir", flags.logdir)

def test_upload_with_plugins(self):
flags = flags_parser.parse_flags(
flags = _define_and_parse_flags(
["uploader", "upload", "--plugins", "plugin1,plugin2"]
)
self.assertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Main program for the TensorBoard.dev uploader."""
"""Entry point and high-level logic for TensorBoard.dev uploader."""

from __future__ import absolute_import
from __future__ import division
Expand Down Expand Up @@ -44,11 +44,6 @@
from tensorboard.plugins import base_plugin


# Temporary integration point for absl compatibility; will go away once
# migrated to TensorBoard subcommand.
_FLAGS = None


_MESSAGE_TOS = u"""\
Your use of this service is subject to Google's Terms of Service
<https://policies.google.com/terms> and Privacy Policy
Expand Down Expand Up @@ -79,25 +74,6 @@ def _prompt_for_user_ack(intent):
sys.stderr.write("\n")


def _parse_flags(argv=("",)):
"""Integration point for `absl.app`.

Exits if flag values are invalid.

Args:
argv: CLI arguments, as with `sys.argv`, where the first argument is taken
to be the name of the program being executed.

Returns:
Either argv[:1] if argv was non-empty, or [''] otherwise, as a mechanism
for absl.app.run() compatibility.
"""
arg0 = argv[0] if argv else ""
global _FLAGS
_FLAGS = flags_parser.parse_flags(argv)
return [arg0]


def _run(flags):
"""Runs the main uploader program given parsed flags.

Expand Down Expand Up @@ -611,15 +587,6 @@ def _die(message):
sys.exit(1)


def main(unused_argv):
global _FLAGS
flags = _FLAGS
# Prevent accidental use of `_FLAGS` until migration to TensorBoard
# subcommand is complete, at which point `_FLAGS` goes away.
del _FLAGS
return _run(flags)


class UploaderSubcommand(program.TensorBoardSubcommand):
"""Integration point with `tensorboard` CLI."""

Expand All @@ -634,7 +601,3 @@ def run(self, flags):

def help(self):
return "upload data to TensorBoard.dev"


if __name__ == "__main__":
app.run(main, flags_parser=_parse_flags)