From fd6c111f5e2eb33d1106b57b631da1a635217d8a Mon Sep 17 00:00:00 2001
From: Pierre Marcenac <pierremarcenac@google.com>
Date: Wed, 17 Apr 2024 01:24:39 -0700
Subject: [PATCH] Use epy.lazy_imports in datasets instead of try/except.

PiperOrigin-RevId: 625597756
---
 tensorflow_datasets/__init__.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tensorflow_datasets/__init__.py b/tensorflow_datasets/__init__.py
index 7d6cfcb1d8f..fdaf874b9fc 100644
--- a/tensorflow_datasets/__init__.py
+++ b/tensorflow_datasets/__init__.py
@@ -40,6 +40,7 @@
 
 _TIMESTAMP_IMPORT_STARTS = time.time()
 from absl import logging
+from etils import epy as _epy
 import tensorflow_datasets.core.logging as _tfds_logging
 from tensorflow_datasets.core.logging import call_metadata as _call_metadata
 
@@ -55,7 +56,7 @@
   # pytype: disable=import-error
   # For builds that don't include all dataset builders, we don't want to fail on
   # import errors of dataset builders.
-  try:
+  with _epy.lazy_api_imports(globals()):
     from tensorflow_datasets import audio
     from tensorflow_datasets import graphs
     from tensorflow_datasets import image
@@ -79,8 +80,6 @@
     from tensorflow_datasets import video
     from tensorflow_datasets import vision_language
 
-  except ImportError:
-    pass
   # pytype: enable=import-error
 
   _import_time_ms_dataset_builders = int(
@@ -103,3 +102,5 @@
       import_time_ms_tensorflow=0,
       import_time_ms_dataset_builders=_import_time_ms_dataset_builders,
   )
+
+del _epy