





"""simple docstring"""



import importlib
import inspect
from functools import wraps
from typing import TYPE_CHECKING, Optional, Union

from .download.streaming_download_manager import (
    xbasename,
    xdirname,
    xet_parse,
    xexists,
    xgetsize,
    xglob,
    xgzip_open,
    xisdir,
    xisfile,
    xjoin,
    xlistdir,
    xnumpy_load,
    xopen,
    xpandas_read_csv,
    xpandas_read_excel,
    xPath,
    xrelpath,
    xsio_loadmat,
    xsplit,
    xsplitext,
    xwalk,
    xxml_dom_minidom_parse,
)
from .utils.logging import get_logger
from .utils.patching import patch_submodule
from .utils.py_utils import get_imports


a_				=    get_logger(__name__)


if TYPE_CHECKING:
       from .builder import DatasetBuilder







def 	__lowercase  (     snake_case_						:						Union[str, Any]       ,snake_case_						:						Optional[Union[str, bool]] = None		)     ->Dict:



    '''simple docstring'''







    __A					:		List[str]						=  importlib.import_module(snake_case_		)

    # TODO(QL): always update the module to add subsequent new authentication
    if hasattr(snake_case_       ,'''_patched_for_streaming'''		) and module._patched_for_streaming:
        return

    def wrap_auth(snake_case_						:						Optional[int]		):
        @wraps(snake_case_		)
        def wrapper(*snake_case_						:						int       ,**snake_case_						:						List[Any]		):
            return function(*snake_case_       ,use_auth_token=snake_case_       ,**snake_case_		)

        __A					:		Any						=  '''wrap_auth'''
        return wrapper

    # open files in a streaming fashion
    patch_submodule(snake_case_       ,'''open'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''os.listdir'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''os.walk'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''glob.glob'''       ,wrap_auth(snake_case_		)		).start()
    # allow to navigate in remote zip files
    patch_submodule(snake_case_       ,'''os.path.join'''       ,snake_case_		).start()
    patch_submodule(snake_case_       ,'''os.path.dirname'''       ,snake_case_		).start()
    patch_submodule(snake_case_       ,'''os.path.basename'''       ,snake_case_		).start()
    patch_submodule(snake_case_       ,'''os.path.relpath'''       ,snake_case_		).start()
    patch_submodule(snake_case_       ,'''os.path.split'''       ,snake_case_		).start()
    patch_submodule(snake_case_       ,'''os.path.splitext'''       ,snake_case_		).start()
    # allow checks on paths
    patch_submodule(snake_case_       ,'''os.path.exists'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''os.path.isdir'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''os.path.isfile'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''os.path.getsize'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''pathlib.Path'''       ,snake_case_		).start()
    # file readers
    patch_submodule(snake_case_       ,'''gzip.open'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''numpy.load'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''pandas.read_csv'''       ,wrap_auth(snake_case_		)       ,attrs=['''__version__''']		).start()
    patch_submodule(snake_case_       ,'''pandas.read_excel'''       ,wrap_auth(snake_case_		)       ,attrs=['''__version__''']		).start()
    patch_submodule(snake_case_       ,'''scipy.io.loadmat'''       ,wrap_auth(snake_case_		)       ,attrs=['''__version__''']		).start()
    patch_submodule(snake_case_       ,'''xml.etree.ElementTree.parse'''       ,wrap_auth(snake_case_		)		).start()
    patch_submodule(snake_case_       ,'''xml.dom.minidom.parse'''       ,wrap_auth(snake_case_		)		).start()
    __A					:		Optional[Any]						=  True







def 	__lowercase  (     snake_case_						:						"DatasetBuilder"		)     ->int:



    '''simple docstring'''







    extend_module_for_streaming(builder.__module__       ,use_auth_token=builder.use_auth_token		)
    # if needed, we also have to extend additional internal imports (like wmt14 -> wmt_utils)
    if not builder.__module__.startswith('''datasets.'''		):  # check that it's not a packaged builder like csv
        for imports in get_imports(inspect.getfile(builder.__class__		)		):
            if imports[0] == "internal":
                __A					:		List[Any]						=  imports[1]
                __A					:		Dict						=  '''.'''.join(builder.__module__.split('''.'''		)[:-1] + [internal_import_name]		)
                extend_module_for_streaming(snake_case_       ,use_auth_token=builder.use_auth_token		)

    # builders can inherit from other builders that might use streaming functionality
    # (for example, ImageFolder and AudioFolder inherit from FolderBuilder which implements examples generation)
    # but these parents builders are not patched automatically as they are not instantiated, so we patch them here
    from .builder import DatasetBuilder

    __A					:		Any						=  [
        cls.__module__
        for cls in type(snake_case_		).__mro__[1:]  # make sure it's not the same module we've already patched
        if issubclass(cls       ,snake_case_		) and cls.__module__ != DatasetBuilder.__module__
    ]  # check it's not a standard builder from datasets.builder
    for module in parent_builder_modules:
        extend_module_for_streaming(snake_case_       ,use_auth_token=builder.use_auth_token		)











"""simple docstring"""



import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


a_				=    """
Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
"""






class 	__snake_case      (	unittest.TestCase							,							SCREAMING_SNAKE_CASE__  ):





 """simple docstring"""


 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[Any]						=  load_tool('''summarization'''						)
     self.tool.setup()
     __A					:		Tuple						=  load_tool('''summarization'''      ,		remote=__lowerCamelCase						)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[str]						=  self.tool(__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		int						=  self.remote_tool(__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)

 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		List[Any]						=  self.tool(text=__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)







 def       UpperCamelCase__(					self						):



     '''simple docstring'''




     __A					:		Optional[int]						=  self.remote_tool(text=__lowerCamelCase						)
     self.assertEqual(
         __lowerCamelCase      ,		'''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''      ,		)




