From 0a702eb670970dfe015184c1e3b55181c111f45a Mon Sep 17 00:00:00 2001 From: Anna R Date: Tue, 3 Sep 2019 09:16:08 -0700 Subject: [PATCH] Only add ModuleWrapper when lazy loading is requested or when using TF 1.x (to print deprecation warnings). PiperOrigin-RevId: 266944067 --- .../tools/api/generator/create_python_api.py | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tensorflow/python/tools/api/generator/create_python_api.py b/tensorflow/python/tools/api/generator/create_python_api.py index 98cd159a63f..6f0cd226723 100644 --- a/tensorflow/python/tools/api/generator/create_python_api.py +++ b/tensorflow/python/tools/api/generator/create_python_api.py @@ -243,22 +243,25 @@ __all__ = [_s for _s in dir() if not _s.startswith('_')] __all__.extend([_s for _s in _names_with_underscore]) ''' % underscore_names_str - for dest_module, _ in self._module_imports.items(): - deprecation = 'False' - has_lite = 'False' - if self._api_version == 1: # Add 1.* deprecations. - if not dest_module.startswith(_COMPAT_MODULE_PREFIX): - deprecation = 'True' - # Workaround to make sure not load lite from lite/__init__.py - if (not dest_module and 'lite' in self._module_imports - and self._lazy_loading): - has_lite = 'True' - if self._lazy_loading: - public_apis_name = '_PUBLIC_APIS' - else: - public_apis_name = 'None' - footer_text_map[dest_module] = _DEPRECATION_FOOTER % ( - dest_module, public_apis_name, deprecation, has_lite) + # Add module wrapper if we need to print deprecation messages + # or if we use lazy loading. + if self._api_version == 1 or self._lazy_loading: + for dest_module, _ in self._module_imports.items(): + deprecation = 'False' + has_lite = 'False' + if self._api_version == 1: # Add 1.* deprecations. + if not dest_module.startswith(_COMPAT_MODULE_PREFIX): + deprecation = 'True' + # Workaround to make sure not load lite from lite/__init__.py + if (not dest_module and 'lite' in self._module_imports + and self._lazy_loading): + has_lite = 'True' + if self._lazy_loading: + public_apis_name = '_PUBLIC_APIS' + else: + public_apis_name = 'None' + footer_text_map[dest_module] = _DEPRECATION_FOOTER % ( + dest_module, public_apis_name, deprecation, has_lite) return module_text_map, footer_text_map