




from typing import Optional

from .. import Features, NamedSplit
from ..packaged_modules.text.text import Text
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader
class 						_A (  _lowerCamelCase				):






  def __init__(  self		:     List[Any]				,						_A		:     NestedDataStructureLike[PathLike]				,						_A		:     Optional[NamedSplit] = None				,						_A		:     Optional[Features] = None				,						_A		:     str = None				,						_A		:     bool = False				,						_A		:     bool = False				,						_A		:     Optional[int] = None				,						**_A		:     Dict				,						)		->   Optional[int]:






       """simple docstring"""







       super().__init__(
           _A				,						split=_A				,						features=_A				,						cache_dir=_A				,						keep_in_memory=_A				,						streaming=_A				,						num_proc=_A				,						**_A				,						)
       lowercase :       Dict       =			path_or_paths if isinstance(_A				,						_A				) else {self.split: path_or_paths}
       lowercase :       Dict       =			Text(
           cache_dir=_A				,						data_files=_A				,						features=_A				,						**_A				,						)






  def  __a      (  self		:     str				)		->   List[Any]:






       """simple docstring"""







       if self.streaming:
            lowercase :       Any       =			self.builder.as_streaming_dataset(split=self.split				)
       # Build regular (map-style) dataset
       else:
            lowercase :       List[Any]       =			None
            lowercase :       int       =			None
            lowercase :       int       =			None
            lowercase :       Optional[Any]       =			None

            self.builder.download_and_prepare(
                download_config=_A				,						download_mode=_A				,						verification_mode=_A				,						base_path=_A				,						num_proc=self.num_proc				,						)
            lowercase :       Any       =			self.builder.as_dataset(
                split=self.split				,						verification_mode=_A				,						in_memory=self.keep_in_memory				)
       return dataset





import os
import sys
import unittest


lowerCAmelCase_						=			os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, 'utils'))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
lowerCAmelCase_						=			os.path.join(git_repo_path, 'src', 'diffusers')
class 						_A (  unittest.TestCase				):






  def  __a      (  self		:     Any				)		->   str:






       """simple docstring"""







       lowercase :       List[str]       =			find_backend('''    if not is_torch_available():'''				)
       self.assertEqual(_A				,						'''torch'''				)

       # backend_with_underscore = find_backend("    if not is_tensorflow_text_available():")
       # self.assertEqual(backend_with_underscore, "tensorflow_text")

       lowercase :       str       =			find_backend('''    if not (is_torch_available() and is_transformers_available()):'''				)
       self.assertEqual(_A				,						'''torch_and_transformers'''				)

       # double_backend_with_underscore = find_backend(
       #    "    if not (is_sentencepiece_available() and is_tensorflow_text_available()):"
       # )
       # self.assertEqual(double_backend_with_underscore, "sentencepiece_and_tensorflow_text")

       lowercase :       str       =			find_backend(
           '''    if not (is_torch_available() and is_transformers_available() and is_onnx_available()):'''				)
       self.assertEqual(_A				,						'''torch_and_transformers_and_onnx'''				)






  def  __a      (  self		:     Optional[int]				)		->   Any:






       """simple docstring"""







       lowercase :       Dict       =			read_init()
       # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
       self.assertIn('''torch'''				,						_A				)
       self.assertIn('''torch_and_transformers'''				,						_A				)
       self.assertIn('''flax_and_transformers'''				,						_A				)
       self.assertIn('''torch_and_transformers_and_onnx'''				,						_A				)

       # Likewise, we can't assert on the exact content of a key
       self.assertIn('''UNet2DModel'''				,						objects['''torch''']				)
       self.assertIn('''FlaxUNet2DConditionModel'''				,						objects['''flax''']				)
       self.assertIn('''StableDiffusionPipeline'''				,						objects['''torch_and_transformers''']				)
       self.assertIn('''FlaxStableDiffusionPipeline'''				,						objects['''flax_and_transformers''']				)
       self.assertIn('''LMSDiscreteScheduler'''				,						objects['''torch_and_scipy''']				)
       self.assertIn('''OnnxStableDiffusionPipeline'''				,						objects['''torch_and_transformers_and_onnx''']				)






  def  __a      (  self		:     Union[str, Any]				)		->   str:






       """simple docstring"""







       lowercase :       List[str]       =			create_dummy_object('''CONSTANT'''				,						'''\'torch\''''				)
       self.assertEqual(_A				,						'''\nCONSTANT = None\n'''				)

       lowercase :       List[Any]       =			create_dummy_object('''function'''				,						'''\'torch\''''				)
       self.assertEqual(
           _A				,						'''\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n'''				)

       lowercase :       Tuple       =			'''
class FakeClass(metaclass=DummyObject):
    _backends = \'torch\'

    def __init__(self, *args, **kwargs):
        requires_backends(self, \'torch\')

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, \'torch\')
'''
       lowercase :       List[Any]       =			create_dummy_object('''FakeClass'''				,						'''\'torch\''''				)
       self.assertEqual(_A				,						_A				)






  def  __a      (  self		:     Union[str, Any]				)		->   str:






       """simple docstring"""







       lowercase :       Optional[int]       =			'''# This file is autogenerated by the command `make fix-copies`, do not edit.
from ..utils import DummyObject, requires_backends


CONSTANT = None


def function(*args, **kwargs):
    requires_backends(function, ["torch"])


class FakeClass(metaclass=DummyObject):
    _backends = ["torch"]

    def __init__(self, *args, **kwargs):
        requires_backends(self, ["torch"])

    @classmethod
    def from_config(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])

    @classmethod
    def from_pretrained(cls, *args, **kwargs):
        requires_backends(cls, ["torch"])
'''
       lowercase :       int       =			create_dummy_files({'''torch''': ['''CONSTANT''', '''function''', '''FakeClass''']}				)
       self.assertEqual(dummy_files['''torch''']				,						_A				)