Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorboard/__init__.py: 59%

27 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

1# Copyright 2017 The TensorFlow Authors. All Rights Reserved. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================== 

15"""TensorBoard is a webapp for understanding TensorFlow runs and graphs.""" 

16 

17 

18from tensorboard import lazy as _lazy 

19from tensorboard import version as _version 

20 

21# TensorBoard public API. 

22__all__ = [ 

23 "__version__", 

24 "errors", 

25 "notebook", 

26 "program", 

27 "summary", 

28] 

29 

30 

31# Please be careful when changing the structure of this file. 

32# 

33# The lazy imports in this file must use `importlib.import_module`, not 

34# `import tensorboard.foo` or `from tensorboard import foo`, or it will 

35# be impossible to reload the TensorBoard module without breaking these 

36# top-level public APIs. This has to do with the gory details of 

37# Python's module system. Take `tensorboard.notebook` as an example: 

38# 

39# - When the `tensorboard` module (that's us!) is initialized, its 

40# `notebook` attribute is initialized to a new LazyModule. The 

41# actual `tensorboard.notebook` submodule is not loaded. 

42# 

43# - When the `tensorboard.notebook` submodule is first loaded, Python 

44# _reassigns_ the `notebook` attribute on the `tensorboard` module 

45# object to point to the underlying `tensorboard.notebook` module 

46# object, rather than its former LazyModule value. This occurs 

47# whether the module is loaded via the lazy module or directly as an 

48# import: 

49# 

50# - import tensorboard; tensorboard.notebook.start(...) # one way 

51# - from tensorboard import notebook # other way; same effect 

52# 

53# - When the `tensorboard` module is reloaded, its `notebook` 

54# attribute is once again bound to a (new) LazyModule, while the 

55# `tensorboard.notebook` module object is unaffected and still 

56# exists in `sys.modules`. But then... 

57# 

58# - When the new LazyModule is forced, it must resolve to the existing 

59# `tensorboard.notebook` module object rather than itself (which 

60# just creates a stack overflow). If the LazyModule load function 

61# uses `import tensorboard.notebook; return tensorboard.notebook`, 

62# then the first statement will do _nothing_ because the 

63# `tensorboard.notebook` module is already loaded, and the second 

64# statement will return the LazyModule itself. The same goes for the 

65# `from tensorboard import notebook` form. We need to ensure that 

66# the submodule is loaded and then pull the actual module object out 

67# of `sys.modules`... which is exactly what `importlib` handles for 

68# us. 

69# 

70# See <https://github.com/tensorflow/tensorboard/issues/1989> for 

71# additional discussion. 

72 

73 

74@_lazy.lazy_load("tensorboard.data") 

75def data(): 

76 import importlib 

77 

78 return importlib.import_module("tensorboard.data") 

79 

80 

81@_lazy.lazy_load("tensorboard.errors") 

82def errors(): 

83 import importlib 

84 

85 return importlib.import_module("tensorboard.errors") 

86 

87 

88@_lazy.lazy_load("tensorboard.notebook") 

89def notebook(): 

90 import importlib 

91 

92 return importlib.import_module("tensorboard.notebook") 

93 

94 

95@_lazy.lazy_load("tensorboard.program") 

96def program(): 

97 import importlib 

98 

99 return importlib.import_module("tensorboard.program") 

100 

101 

102@_lazy.lazy_load("tensorboard.summary") 

103def summary(): 

104 import importlib 

105 

106 return importlib.import_module("tensorboard.summary") 

107 

108 

109def load_ipython_extension(ipython): 

110 """IPython API entry point. 

111 

112 Only intended to be called by the IPython runtime. 

113 

114 See: 

115 https://ipython.readthedocs.io/en/stable/config/extensions/index.html 

116 """ 

117 notebook._load_ipython_extension(ipython) 

118 

119 

120__version__ = _version.VERSION