Skip to content

Commit 4aa6e07

Browse files
bmd3kcaisq
authored andcommitted
Remove standalone uploader binary target (#3538)
Remove standalone uploader binary target that shouldn't be used any longer. No longer make //tensorboard/uploader a binary target. Rename uploader_main to uploader_subcommand. Clean up some BUILD target names by removing "_lib" suffix.
1 parent 73285f2 commit 4aa6e07

File tree

6 files changed

+36
-78
lines changed

6 files changed

+36
-78
lines changed

tensorboard/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ py_binary(
2929
":program",
3030
"//tensorboard:expect_tensorflow_installed",
3131
"//tensorboard/plugins:base_plugin",
32-
"//tensorboard/uploader:uploader_main_lib",
32+
"//tensorboard/uploader:uploader_subcommand",
3333
"//tensorboard/util:tb_logging",
3434
"//tensorboard/util:timing", # non-strict dep, for patching convenience
3535
],

tensorboard/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
from tensorboard import program
4545
from tensorboard.compat import tf
4646
from tensorboard.plugins import base_plugin
47-
from tensorboard.uploader import uploader_main
47+
from tensorboard.uploader import uploader_subcommand
4848
from tensorboard.util import tb_logging
4949

5050

@@ -64,7 +64,7 @@ def run_main():
6464
tensorboard = program.TensorBoard(
6565
default.get_plugins() + default.get_dynamic_plugins(),
6666
program.get_default_assets_zip_provider(),
67-
subcommands=[uploader_main.UploaderSubcommand()],
67+
subcommands=[uploader_subcommand.UploaderSubcommand()],
6868
)
6969
try:
7070
from absl import app

tensorboard/uploader/BUILD

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ licenses(["notice"]) # Apache 2.0
88
exports_files(["LICENSE"])
99

1010
py_library(
11-
name = "exporter_lib",
11+
name = "exporter",
1212
srcs = ["exporter.py"],
1313
srcs_version = "PY3",
1414
deps = [
@@ -25,7 +25,7 @@ py_test(
2525
name = "exporter_test",
2626
srcs = ["exporter_test.py"],
2727
deps = [
28-
":exporter_lib",
28+
":exporter",
2929
":test_util",
3030
":util",
3131
"//tensorboard:expect_grpc_installed",
@@ -59,24 +59,17 @@ py_test(
5959
],
6060
)
6161

62-
py_binary(
63-
name = "uploader",
64-
srcs = ["uploader_main.py"],
65-
main = "uploader_main.py",
66-
deps = [":uploader_main_lib"],
67-
)
68-
6962
py_library(
70-
name = "uploader_main_lib",
71-
srcs = ["uploader_main.py"],
63+
name = "uploader_subcommand",
64+
srcs = ["uploader_subcommand.py"],
7265
visibility = ["//tensorboard:internal"],
7366
deps = [
7467
":auth",
75-
":exporter_lib",
68+
":exporter",
7669
":flags_parser",
7770
":formatters",
7871
":server_info",
79-
":uploader_lib",
72+
":uploader",
8073
":util",
8174
"//tensorboard:expect_absl_app_installed",
8275
"//tensorboard:expect_absl_flags_argparse_flags_installed",
@@ -91,7 +84,7 @@ py_library(
9184
)
9285

9386
py_library(
94-
name = "uploader_lib",
87+
name = "uploader",
9588
srcs = ["uploader.py"],
9689
deps = [
9790
":logdir_loader",
@@ -119,7 +112,7 @@ py_test(
119112
srcs_version = "PY3",
120113
deps = [
121114
":test_util",
122-
":uploader_lib",
115+
":uploader",
123116
":util",
124117
"//tensorboard:data_compat",
125118
"//tensorboard:dataclass_compat",

tensorboard/uploader/flags_parser.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from __future__ import division
1919
from __future__ import print_function
2020

21-
from absl.flags import argparse_flags
2221

2322
SUBCOMMAND_FLAG = "_uploader__subcommand"
2423
SUBCOMMAND_KEY_UPLOAD = "UPLOAD"
@@ -33,23 +32,6 @@
3332
DEFAULT_ORIGIN = "https://tensorboard.dev"
3433

3534

36-
def parse_flags(argv):
37-
"""Parse flags for TensorBoard.dev uploader.
38-
39-
Exits if flag values are invalid.
40-
41-
Args:
42-
argv: CLI arguments, as with `sys.argv`, where the first argument is taken
43-
to be the name of the program being executed.
44-
"""
45-
parser = argparse_flags.ArgumentParser(
46-
prog="uploader",
47-
description=("Upload your TensorBoard experiments to TensorBoard.dev"),
48-
)
49-
define_flags(parser)
50-
return parser.parse_args(argv[1:])
51-
52-
5335
def define_flags(parser):
5436
"""Configures flags on the provided argument parser.
5537

tensorboard/uploader/flags_parser_test.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,44 @@
2020

2121
import argparse
2222

23+
from absl.flags import argparse_flags
24+
2325
from tensorboard.uploader import flags_parser
2426
from tensorboard import test as tb_test
2527

2628

29+
def _define_and_parse_flags(argv):
30+
"""Defines and parses flags.
31+
32+
Creates an `ArgumentParser`, defines flags on the parser (the logic really
33+
being tested), and parses given arguments.
34+
35+
Args:
36+
argv: CLI arguments, as with `sys.argv`, where the first argument is taken
37+
to be the name of the program being executed.
38+
"""
39+
parser = argparse_flags.ArgumentParser(
40+
prog="uploader",
41+
description=("Upload your TensorBoard experiments to TensorBoard.dev"),
42+
)
43+
flags_parser.define_flags(parser)
44+
return parser.parse_args(argv[1:])
45+
46+
2747
class FlagsParserTest(tb_test.TestCase):
2848
def test_unknown_command(self):
2949
with self.assertRaises(SystemExit):
30-
flags_parser.parse_flags(["uploader", "unknown"])
50+
_define_and_parse_flags(["uploader", "unknown"])
3151

3252
def test_list(self):
33-
flags = flags_parser.parse_flags(["uploader", "list"])
53+
flags = _define_and_parse_flags(["uploader", "list"])
3454
self.assertEqual(
3555
flags_parser.SUBCOMMAND_KEY_LIST,
3656
getattr(flags, flags_parser.SUBCOMMAND_FLAG),
3757
)
3858

3959
def test_upload_logdir(self):
40-
flags = flags_parser.parse_flags(
60+
flags = _define_and_parse_flags(
4161
["uploader", "upload", "--logdir", "some/log/dir"]
4262
)
4363
self.assertEqual(
@@ -47,7 +67,7 @@ def test_upload_logdir(self):
4767
self.assertEqual("some/log/dir", flags.logdir)
4868

4969
def test_upload_with_plugins(self):
50-
flags = flags_parser.parse_flags(
70+
flags = _define_and_parse_flags(
5171
["uploader", "upload", "--plugins", "plugin1,plugin2"]
5272
)
5373
self.assertEqual(

tensorboard/uploader/uploader_main.py renamed to tensorboard/uploader/uploader_subcommand.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
"""Main program for the TensorBoard.dev uploader."""
15+
"""Entry point and high-level logic for TensorBoard.dev uploader."""
1616

1717
from __future__ import absolute_import
1818
from __future__ import division
@@ -44,11 +44,6 @@
4444
from tensorboard.plugins import base_plugin
4545

4646

47-
# Temporary integration point for absl compatibility; will go away once
48-
# migrated to TensorBoard subcommand.
49-
_FLAGS = None
50-
51-
5247
_MESSAGE_TOS = u"""\
5348
Your use of this service is subject to Google's Terms of Service
5449
<https://policies.google.com/terms> and Privacy Policy
@@ -79,25 +74,6 @@ def _prompt_for_user_ack(intent):
7974
sys.stderr.write("\n")
8075

8176

82-
def _parse_flags(argv=("",)):
83-
"""Integration point for `absl.app`.
84-
85-
Exits if flag values are invalid.
86-
87-
Args:
88-
argv: CLI arguments, as with `sys.argv`, where the first argument is taken
89-
to be the name of the program being executed.
90-
91-
Returns:
92-
Either argv[:1] if argv was non-empty, or [''] otherwise, as a mechanism
93-
for absl.app.run() compatibility.
94-
"""
95-
arg0 = argv[0] if argv else ""
96-
global _FLAGS
97-
_FLAGS = flags_parser.parse_flags(argv)
98-
return [arg0]
99-
100-
10177
def _run(flags):
10278
"""Runs the main uploader program given parsed flags.
10379
@@ -611,15 +587,6 @@ def _die(message):
611587
sys.exit(1)
612588

613589

614-
def main(unused_argv):
615-
global _FLAGS
616-
flags = _FLAGS
617-
# Prevent accidental use of `_FLAGS` until migration to TensorBoard
618-
# subcommand is complete, at which point `_FLAGS` goes away.
619-
del _FLAGS
620-
return _run(flags)
621-
622-
623590
class UploaderSubcommand(program.TensorBoardSubcommand):
624591
"""Integration point with `tensorboard` CLI."""
625592

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

635602
def help(self):
636603
return "upload data to TensorBoard.dev"
637-
638-
639-
if __name__ == "__main__":
640-
app.run(main, flags_parser=_parse_flags)

0 commit comments

Comments
 (0)