Delete modules that shouldn't be part of dir(). We used to have these deletions before. They were no longer needed when we used virtual pip package setup.But now they are needed again since virtual pip package was removed.
PiperOrigin-RevId: 321477672 Change-Id: I642e6d69bae8db721cec14cae36163e271a077be
This commit is contained in:
parent
fd535403c0
commit
540f8dbdd8
@ -12,6 +12,8 @@
|
||||
`TF_StringEncodedSize` are no longer relevant and have been removed; see
|
||||
core/platform/ctstring.h for string access/modification in C.
|
||||
* Removed `tf.distribute.Strategy.experimental_run_v2` method, which was deprecated in TF 2.2.
|
||||
* `tensorflow.python`, `tensorflow.core` and `tensorflow.compiler` modules are
|
||||
now hidden. These modules are not part of TensorFlow public API.
|
||||
|
||||
## Known Caveats
|
||||
|
||||
|
@ -158,4 +158,23 @@ if hasattr(_current_module, 'keras'):
|
||||
setattr(_current_module, "initializers", initializers)
|
||||
# pylint: enable=undefined-variable
|
||||
|
||||
# Delete modules that should be hidden from dir().
|
||||
# Don't fail if these modules are not available.
|
||||
# For e.g. this file will be originally placed under tensorflow/_api/v1 which
|
||||
# does not have 'python', 'core' directories. Then, it will be copied
|
||||
# to tensorflow/ which does have these two directories.
|
||||
# pylint: disable=undefined-variable
|
||||
try:
|
||||
del python
|
||||
except NameError:
|
||||
pass
|
||||
try:
|
||||
del core
|
||||
except NameError:
|
||||
pass
|
||||
try:
|
||||
del compiler
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
# __all__ PLACEHOLDER
|
||||
|
@ -156,4 +156,25 @@ if _running_from_pip_package():
|
||||
if _fi.file_exists(_plugin_dir):
|
||||
_ll.load_library(_plugin_dir)
|
||||
|
||||
# Delete modules that should be hidden from dir().
|
||||
# Don't fail if these modules are not available.
|
||||
# For e.g. this file will be originally placed under tensorflow/_api/v1 which
|
||||
# does not have 'python', 'core' directories. Then, it will be copied
|
||||
# to tensorflow/ which does have these two directories.
|
||||
|
||||
# pylint: disable=undefined-variable
|
||||
try:
|
||||
del python
|
||||
except NameError:
|
||||
pass
|
||||
try:
|
||||
del core
|
||||
except NameError:
|
||||
pass
|
||||
try:
|
||||
del compiler
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
|
||||
# __all__ PLACEHOLDER
|
||||
|
@ -21,7 +21,7 @@ from __future__ import print_function
|
||||
import numpy as onp
|
||||
import tensorflow.compat.v2 as tf
|
||||
|
||||
import tensorflow.python.ops.numpy_ops as np
|
||||
from tensorflow.python.ops import numpy_ops as np
|
||||
|
||||
|
||||
# Tests for code snippet put in README.md
|
||||
|
@ -59,9 +59,8 @@ class ModuleTest(test.TestCase):
|
||||
'tf.Tensor([1 2 3 4 5 6 7 8 9], shape=(9,), dtype=int32)',
|
||||
str(tf.range(1, 10)))
|
||||
else:
|
||||
self.assertEqual(
|
||||
'Tensor("range:0", shape=(9,), dtype=int32)',
|
||||
str(tf.range(1, 10)))
|
||||
self.assertEqual('Tensor("range:0", shape=(9,), dtype=int32)',
|
||||
str(tf.range(1, 10)))
|
||||
|
||||
def testCompatV2HasCompatV1(self):
|
||||
# pylint: disable=pointless-statement
|
||||
@ -79,6 +78,9 @@ class ModuleTest(test.TestCase):
|
||||
tf.compat.v1.summary.FileWriter
|
||||
# pylint: enable=pointless-statement
|
||||
|
||||
def testPythonModuleIsHidden(self):
|
||||
self.assertNotIn('python', dir(tf))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test.main()
|
||||
|
@ -29,7 +29,6 @@ from absl.testing import absltest
|
||||
import numpy as np
|
||||
import tensorflow.compat.v2 as tf
|
||||
|
||||
import tensorflow.python as tf_root
|
||||
from tensorflow.tools.docs import tf_doctest_lib
|
||||
|
||||
# We put doctest after absltest so that it picks up the unittest monkeypatch.
|
||||
@ -190,8 +189,9 @@ def load_tests(unused_loader, tests, unused_ignore):
|
||||
tf_modules = get_module_and_inject_docstring(FLAGS.file)
|
||||
|
||||
for module in tf_modules:
|
||||
if any(module.__name__.startswith(PACKAGE + prefix)
|
||||
for prefix in FLAGS.module_prefix_skip):
|
||||
if any(
|
||||
module.__name__.startswith(PACKAGE + prefix)
|
||||
for prefix in FLAGS.module_prefix_skip):
|
||||
continue
|
||||
testcase = TfTestCase()
|
||||
tests.addTests(
|
||||
@ -221,5 +221,9 @@ def setUpModule():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
recursive_import(tf_root)
|
||||
# Use importlib to import python submodule of tensorflow.
|
||||
# We delete python submodule in root __init__.py file. This means
|
||||
# normal import won't work for some Python versions.
|
||||
tf_python_root = importlib.import_module(PACKAGE[:-1])
|
||||
recursive_import(tf_python_root)
|
||||
absltest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user