-
Notifications
You must be signed in to change notification settings - Fork 1.7k
infra: create dev target #4588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
infra: create dev target #4588
Changes from all commits
b9e344e
0389506
f00530d
8d48717
f5d0803
14c5069
7190644
fd41ae0
fa5af70
3d13bcd
a454dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,12 @@ package_group( | |
| py_binary( | ||
| name = "tensorboard", | ||
| srcs = ["main.py"], | ||
| data = ["webfiles.zip"], | ||
| main = "main.py", | ||
| srcs_version = "PY3", | ||
| deps = [ | ||
| ":default", | ||
| ":dynamic_plugins", | ||
| ":dynamic_plugins", # loads internal dynamic plugin like projector | ||
| ":lib", | ||
| ":main_lib", | ||
| ":program", | ||
|
|
@@ -45,6 +46,22 @@ py_library( | |
| ], | ||
| ) | ||
|
|
||
| py_binary( | ||
| name = "dev", | ||
| srcs = ["main_dev.py"], | ||
| data = ["dev_webfiles.zip"], | ||
| main = "main_dev.py", | ||
| srcs_version = "PY3", | ||
| deps = [ | ||
| ":default", | ||
| ":dynamic_plugins", # loads internal dynamic plugin like projector | ||
| ":lib", | ||
| ":main_lib", | ||
| ":program", | ||
| "//tensorboard/uploader:uploader_subcommand", | ||
| ], | ||
| ) | ||
|
|
||
| # The public TensorBoard python library, bundled with the pip package and | ||
| # available via 'import tensorboard as tb' once installed. | ||
| py_library( | ||
|
|
@@ -248,7 +265,6 @@ py_library( | |
| py_library( | ||
| name = "default", | ||
| srcs = ["default.py"], | ||
| data = ["webfiles.zip"], | ||
| srcs_version = "PY3", | ||
| deps = [ | ||
| "//tensorboard:expect_pkg_resources_installed", | ||
|
|
@@ -336,6 +352,29 @@ tf_web_library( | |
| ], | ||
| ) | ||
|
|
||
| tensorboard_zip_file( | ||
| name = "dev_webfiles", | ||
| deps = [":dev_assets"], | ||
| ) | ||
|
|
||
| # Should keep the asset dependencies in sync with :assets. | ||
| tf_web_library( | ||
| name = "dev_assets", | ||
|
||
| srcs = [ | ||
| "//tensorboard/webapp:index.html", | ||
| "//tensorboard/webapp:index.js", | ||
| "//tensorboard/webapp:svg_bundle", | ||
| "//tensorboard/webapp/widgets/line_chart_v2/lib/worker:chart_worker.js", | ||
| ], | ||
| path = "/", | ||
| suppress = ["strictDependencies"], | ||
| deps = [ | ||
| "//tensorboard/webapp/widgets/source_code/monaco:monaco_editor", | ||
| "//tensorboard/webapp/widgets/source_code/monaco:monaco_languages", | ||
| "@com_google_fonts_roboto", | ||
| ], | ||
| ) | ||
|
|
||
| # This is a dummy rule used as a numpy dependency in open-source. | ||
| # We expect numpy to already be installed on the system, e.g. via | ||
| # `pip install numpy` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright 2021 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 dev main module.""" | ||
|
|
||
| import inspect | ||
| import os | ||
| import sys | ||
|
|
||
| from absl import app | ||
| from tensorboard import default | ||
| from tensorboard import main_lib | ||
| from tensorboard import program | ||
| from tensorboard.plugins import base_plugin | ||
| from tensorboard.uploader import uploader_subcommand | ||
|
|
||
|
|
||
| def run_main(): | ||
| """Initializes flags and calls main().""" | ||
| main_lib.global_init() | ||
|
|
||
| path = os.path.join( | ||
| os.path.dirname(inspect.getfile(sys._getframe(0))), "dev_webfiles.zip" | ||
| ) | ||
|
|
||
| tensorboard = program.TensorBoard( | ||
| lambda: open(path, "rb"), | ||
| plugins=default.get_plugins(), | ||
| subcommands=[uploader_subcommand.UploaderSubcommand()], | ||
| ) | ||
|
|
||
| try: | ||
| app.run(tensorboard.main, flags_parser=tensorboard.configure) | ||
| except base_plugin.FlagsError as e: | ||
| print("Error: %s" % e, file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run_main() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,37 +26,51 @@ | |
| from tensorboard.plugins.core import core_plugin | ||
|
|
||
|
|
||
| def fake_asset_provider(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we wanted to avoid the boilerplate here we could always make the argument still optional, but if omitted, we would generate a dummy zip file that just contains
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer things to be a bit more explicit so I will keep it as is. |
||
| pass | ||
|
|
||
|
|
||
| class TensorBoardTest(tb_test.TestCase): | ||
| """Tests the TensorBoard program.""" | ||
|
|
||
| def testPlugins_pluginClass(self): | ||
| tb = program.TensorBoard(plugins=[core_plugin.CorePlugin]) | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, plugins=[core_plugin.CorePlugin] | ||
| ) | ||
| self.assertIsInstance(tb.plugin_loaders[0], base_plugin.BasicLoader) | ||
| self.assertIs(tb.plugin_loaders[0].plugin_class, core_plugin.CorePlugin) | ||
|
|
||
| def testPlugins_pluginLoaderClass(self): | ||
| tb = program.TensorBoard(plugins=[core_plugin.CorePluginLoader]) | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, plugins=[core_plugin.CorePluginLoader] | ||
| ) | ||
| self.assertIsInstance( | ||
| tb.plugin_loaders[0], core_plugin.CorePluginLoader | ||
| ) | ||
|
|
||
| def testPlugins_pluginLoader(self): | ||
| loader = core_plugin.CorePluginLoader() | ||
| tb = program.TensorBoard(plugins=[loader]) | ||
| tb = program.TensorBoard(fake_asset_provider, plugins=[loader]) | ||
| self.assertIs(tb.plugin_loaders[0], loader) | ||
|
|
||
| def testPlugins_invalidType(self): | ||
| plugin_instance = core_plugin.CorePlugin(base_plugin.TBContext()) | ||
| with self.assertRaisesRegex(TypeError, "CorePlugin"): | ||
| tb = program.TensorBoard(plugins=[plugin_instance]) | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, plugins=[plugin_instance] | ||
| ) | ||
|
|
||
| def testConfigure(self): | ||
| tb = program.TensorBoard(plugins=[core_plugin.CorePluginLoader]) | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, plugins=[core_plugin.CorePluginLoader] | ||
| ) | ||
| tb.configure(logdir="foo") | ||
| self.assertEqual(tb.flags.logdir, "foo") | ||
|
|
||
| def testConfigure_unknownFlag(self): | ||
| tb = program.TensorBoard(plugins=[core_plugin.CorePlugin]) | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, plugins=[core_plugin.CorePlugin] | ||
| ) | ||
| with self.assertRaisesRegex(ValueError, "Unknown TensorBoard flag"): | ||
| tb.configure(foo="bar") | ||
|
|
||
|
|
@@ -150,6 +164,7 @@ def tearDown(self): | |
|
|
||
| def testImplicitServe(self): | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand(lambda parser: None)], | ||
| ) | ||
|
|
@@ -162,6 +177,7 @@ def testImplicitServe(self): | |
|
|
||
| def testExplicitServe(self): | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand()], | ||
| ) | ||
|
|
@@ -179,6 +195,7 @@ def define_flags(parser): | |
| parser.add_argument("--hello") | ||
|
|
||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand(define_flags=define_flags)], | ||
| ) | ||
|
|
@@ -190,6 +207,7 @@ def define_flags(parser): | |
|
|
||
| def testSubcommand_ExitCode(self): | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand()], | ||
| ) | ||
|
|
@@ -199,6 +217,7 @@ def testSubcommand_ExitCode(self): | |
|
|
||
| def testSubcommand_DoesNotInheritBaseArgs(self): | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand()], | ||
| ) | ||
|
|
@@ -214,6 +233,7 @@ def define_flags(parser): | |
| parser.add_argument("payload") | ||
|
|
||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand(define_flags=define_flags)], | ||
| ) | ||
|
|
@@ -226,6 +246,7 @@ def define_flags(parser): | |
| def testConflictingNames_AmongSubcommands(self): | ||
| with self.assertRaises(ValueError) as cm: | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand(), _TestSubcommand()], | ||
| ) | ||
|
|
@@ -235,6 +256,7 @@ def testConflictingNames_AmongSubcommands(self): | |
| def testConflictingNames_WithServe(self): | ||
| with self.assertRaises(ValueError) as cm: | ||
| tb = program.TensorBoard( | ||
| fake_asset_provider, | ||
| plugins=[core_plugin.CorePluginLoader], | ||
| subcommands=[_TestSubcommand(name="serve")], | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I agree this is where the data dep belongs, but right now the code in
main.pyactually reads it fromprogram.get_default_assets_zip_provider(). It used to live indefaultbut was moved to program back in #1631 (not really sure why, at this point).IMO better at this point to just inline it into
main.pyand remove the fallback logic inprogram.TensorBoard()that calls it, so thatassets_zip_providermust be specified by the caller. That way we don't have skew between where the data dep is defined in the BUILD file, and where the code actually expects it to exist. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Done.