Fix "from tensorflow._api.v1 import *".

PiperOrigin-RevId: 214055060
This commit is contained in:
Michael Case 2018-09-21 15:36:17 -07:00 committed by TensorFlower Gardener
parent 9655bbd9d6
commit 47d8a750bc
3 changed files with 11 additions and 8 deletions
tensorflow

View File

@ -14,9 +14,9 @@
# ============================================================================== # ==============================================================================
"""Bring in all of the public TensorFlow interface into this module.""" """Bring in all of the public TensorFlow interface into this module."""
from __future__ import absolute_import from __future__ import absolute_import as _absolute_import
from __future__ import division from __future__ import division as _division
from __future__ import print_function from __future__ import print_function as _print_function
import os as _os import os as _os
@ -41,6 +41,11 @@ except (ImportError, AttributeError):
from tensorflow.python.util.lazy_loader import LazyLoader # pylint: disable=g-import-not-at-top from tensorflow.python.util.lazy_loader import LazyLoader # pylint: disable=g-import-not-at-top
contrib = LazyLoader('contrib', globals(), 'tensorflow.contrib') contrib = LazyLoader('contrib', globals(), 'tensorflow.contrib')
del LazyLoader del LazyLoader
# The templated code that replaces the placeholder above sometimes
# sets the __all__ variable. If it does, we have to be sure to add
# "contrib".
if '__all__' in vars():
vars()['__all__'].append('contrib')
from tensorflow.python.platform import flags # pylint: disable=g-import-not-at-top from tensorflow.python.platform import flags # pylint: disable=g-import-not-at-top
app.flags = flags # pylint: disable=undefined-variable app.flags = flags # pylint: disable=undefined-variable
@ -51,10 +56,6 @@ _tf_api_dir = _os.path.dirname(_os.path.dirname(app.__file__)) # pylint: disabl
if _tf_api_dir not in __path__: if _tf_api_dir not in __path__:
__path__.append(_tf_api_dir) __path__.append(_tf_api_dir)
del absolute_import
del division
del print_function
# These symbols appear because we import the python package which # These symbols appear because we import the python package which
# in turn imports from tensorflow.core and tensorflow.python. They # in turn imports from tensorflow.core and tensorflow.python. They
# must come from this module. So python adds these symbols for the # must come from this module. So python adds these symbols for the

View File

@ -181,7 +181,6 @@ class _ModuleInitCodeBuilder(object):
_names_with_underscore = [%s] _names_with_underscore = [%s]
__all__ = [_s for _s in dir() if not _s.startswith('_')] __all__ = [_s for _s in dir() if not _s.startswith('_')]
__all__.extend([_s for _s in _names_with_underscore]) __all__.extend([_s for _s in _names_with_underscore])
__all__.remove('print_function')
''' % underscore_names_str ''' % underscore_names_str
return module_text_map return module_text_map

View File

@ -37,6 +37,7 @@ BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
FUTURES_PATTERN = re.compile(r'^from __future__ import (\w+)\s*$') FUTURES_PATTERN = re.compile(r'^from __future__ import (\w+)\s*$')
FUTURES_PATTERN_2 = re.compile( FUTURES_PATTERN_2 = re.compile(
r'^from __future__ import (\w+), (\w+), (\w+)\s*$') r'^from __future__ import (\w+), (\w+), (\w+)\s*$')
FUTURES_PATTERN_3 = re.compile(r'^from __future__ import (\w+) as \w+\s*$')
REQUIRED_FUTURES = frozenset(['absolute_import', 'division', 'print_function']) REQUIRED_FUTURES = frozenset(['absolute_import', 'division', 'print_function'])
WHITELIST = [ WHITELIST = [
@ -59,6 +60,8 @@ def check_file(path, old_division):
for line in open(path, encoding='utf-8') if six.PY3 else open(path): for line in open(path, encoding='utf-8') if six.PY3 else open(path):
count += 1 count += 1
m = FUTURES_PATTERN.match(line) m = FUTURES_PATTERN.match(line)
if not m:
m = FUTURES_PATTERN_3.match(line)
if m: if m:
futures.add(m.group(1)) futures.add(m.group(1))
else: else: