




import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


UpperCamelCase								=					threading.Lock()
UpperCamelCase								=					None

UpperCamelCase								=					{
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

UpperCamelCase								=					logging.WARNING

UpperCamelCase								=					True



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			os.getenv("TRANSFORMERS_VERBOSITY"       ,    lowerCAmelCase_      )
     if env_level_str:
          if env_level_str in log_levels:
               return log_levels[env_level_str]
          else:
               logging.getLogger().warning(
                   F'Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '
                   F'has to be one of: { ", ".join(log_levels.keys()      ) }'      )
     return _default_log_level



def 							_A       (						):
     """simple docstring"""

     return __name__.split("."      )[0]



def 							_A       (						):
     """simple docstring"""

     return logging.getLogger(_get_library_name()      )



def 							_A       (						):
     """simple docstring"""

     global _default_handler

     with _lock:
          if _default_handler:
               # This library has already configured the library root logger.
               return
          lowerCAmelCase__          =			logging.StreamHandler()  # Set sys.stderr as stream.
          lowerCAmelCase__          =			sys.stderr.flush

          # Apply our default configuration to the library root logger.
          lowerCAmelCase__          =			_get_library_root_logger()
          library_root_logger.addHandler(_default_handler      )
          library_root_logger.setLevel(_get_default_logging_level()      )
          lowerCAmelCase__          =			False



def 							_A       (						):
     """simple docstring"""

     global _default_handler

     with _lock:
          if not _default_handler:
               return

          lowerCAmelCase__          =			_get_library_root_logger()
          library_root_logger.removeHandler(_default_handler      )
          library_root_logger.setLevel(logging.NOTSET      )
          lowerCAmelCase__          =			None



def 							_A       (						):
     """simple docstring"""

     return log_levels



def 							_A       (						lowerCAmelCase_					: Optional[str] = None      ):
     """simple docstring"""

     if name is None:
          lowerCAmelCase__          =			_get_library_name()

     _configure_library_root_logger()
     return logging.getLogger(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     _configure_library_root_logger()
     return _get_library_root_logger().getEffectiveLevel()



def 							_A       (						lowerCAmelCase_					: int      ):
     """simple docstring"""

     _configure_library_root_logger()
     _get_library_root_logger().setLevel(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     return set_verbosity(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     return set_verbosity(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     return set_verbosity(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     return set_verbosity(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     _configure_library_root_logger()

     assert _default_handler is not None
     _get_library_root_logger().removeHandler(_default_handler      )



def 							_A       (						):
     """simple docstring"""

     _configure_library_root_logger()

     assert _default_handler is not None
     _get_library_root_logger().addHandler(_default_handler      )



def 							_A       (						lowerCAmelCase_					: logging.Handler      ):
     """simple docstring"""

     _configure_library_root_logger()

     assert handler is not None
     _get_library_root_logger().addHandler(lowerCAmelCase_      )



def 							_A       (						lowerCAmelCase_					: logging.Handler      ):
     """simple docstring"""

     _configure_library_root_logger()

     assert handler is not None and handler not in _get_library_root_logger().handlers
     _get_library_root_logger().removeHandler(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     _configure_library_root_logger()
     lowerCAmelCase__          =			False



def 							_A       (						):
     """simple docstring"""

     _configure_library_root_logger()
     lowerCAmelCase__          =			True



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			_get_library_root_logger().handlers

     for handler in handlers:
          lowerCAmelCase__          =			logging.Formatter("[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"      )
          handler.setFormatter(lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			_get_library_root_logger().handlers

     for handler in handlers:
          handler.setFormatter(lowerCAmelCase_      )



def 							_A       (						self					: Union[str, Any]       ,    *lowerCAmelCase_					: int       ,    **lowerCAmelCase_					: Optional[Any]      ):
     """simple docstring"""

     lowerCAmelCase__          =			os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"       ,    lowerCAmelCase_      )
     if no_advisory_warnings:
          return
     self.warning(*lowerCAmelCase_       ,    **lowerCAmelCase_      )


UpperCamelCase								=					warning_advice



@functools.lru_cache(lowerCAmelCase_      )
def 							_A       (						self					: List[Any]       ,    *lowerCAmelCase_					: Any       ,    **lowerCAmelCase_					: Tuple      ):
     """simple docstring"""

     self.warning(*lowerCAmelCase_       ,    **lowerCAmelCase_      )


UpperCamelCase								=					warning_once





class 			__lowerCamelCase	:




    """simple docstring"""

    def __init__(	self					:					Optional[Any]       ,     *SCREAMING_SNAKE_CASE__					:					int       ,     **SCREAMING_SNAKE_CASE__					:					List[str]       )				->	Optional[Any]:  # pylint: disable=unused-argument
         lowerCAmelCase__          =			args[0] if args else None


    def __iter__(	self					:					Dict       )				->	int:
         return iter(self._iterator       )


    def __getattr__(	self					:					List[str]       ,     SCREAMING_SNAKE_CASE__					:					Optional[int]       )				->	Tuple:

         def empty_fn(*SCREAMING_SNAKE_CASE__					:					int       ,     **SCREAMING_SNAKE_CASE__					:					str       ):  # pylint: disable=unused-argument
              return

         return empty_fn


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


    def __exit__(	self					:					List[Any]       ,     SCREAMING_SNAKE_CASE__					:					Dict       ,     SCREAMING_SNAKE_CASE__					:					Optional[Any]       ,     SCREAMING_SNAKE_CASE__					:					str       )				->	List[str]:
         return






class 			__lowerCamelCase	:




    """simple docstring"""

    def __call__(	self					:					Any       ,     *SCREAMING_SNAKE_CASE__					:					Optional[Any]       ,     **SCREAMING_SNAKE_CASE__					:					str       )				->	Any:
         if _tqdm_active:
              return tqdm_lib.tqdm(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )
         else:
              return EmptyTqdm(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					str       ,     *SCREAMING_SNAKE_CASE__					:					Tuple       ,     **SCREAMING_SNAKE_CASE__					:					Dict       )				->	Any:
         lowerCAmelCase__          =			None
         if _tqdm_active:
              return tqdm_lib.tqdm.set_lock(*SCREAMING_SNAKE_CASE__       ,     **SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Union[str, Any]       )				->	Union[str, Any]:
         if _tqdm_active:
              return tqdm_lib.tqdm.get_lock()






UpperCamelCase								=					_tqdm_cls()



def 							_A       (						):
     """simple docstring"""

     global _tqdm_active
     return bool(_tqdm_active      )



def 							_A       (						):
     """simple docstring"""

     global _tqdm_active
     lowerCAmelCase__          =			True
     hf_hub_utils.enable_progress_bars()






def 							_A       (						):
     """simple docstring"""

     global _tqdm_active
     lowerCAmelCase__          =			False
     hf_hub_utils.disable_progress_bars()






import time
from contextlib import contextmanager
from pathlib import Path

import pytest
import requests
from huggingface_hub.hf_api import HfApi, HfFolder


UpperCamelCase								=					'__DUMMY_TRANSFORMERS_USER__'
UpperCamelCase								=					'Dummy User'
UpperCamelCase								=					'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'

UpperCamelCase								=					'https://hub-ci.huggingface.co'
UpperCamelCase								=					CI_HUB_ENDPOINT + '/datasets/{repo_id}/resolve/{revision}/{path}'
UpperCamelCase								=					CI_HUB_ENDPOINT + '/{repo_id}/resolve/{revision}/{filename}'
UpperCamelCase								=					Path('~/.huggingface/hub_ci_token').expanduser()



@pytest.fixture
def 							_A       (						lowerCAmelCase_					: Dict      ):
     """simple docstring"""

     monkeypatch.setattr(
         "huggingface_hub.file_download.HUGGINGFACE_CO_URL_TEMPLATE"       ,    lowerCAmelCase_      )



@pytest.fixture
def 							_A       (						lowerCAmelCase_					: int      ):
     """simple docstring"""

     monkeypatch.setattr("datasets.config.HF_ENDPOINT"       ,    lowerCAmelCase_      )
     monkeypatch.setattr("datasets.config.HUB_DATASETS_URL"       ,    lowerCAmelCase_      )



@pytest.fixture
def 							_A       (						lowerCAmelCase_					: str      ):
     """simple docstring"""

     monkeypatch.setattr("huggingface_hub.hf_api.HfFolder.path_token"       ,    lowerCAmelCase_      )



@pytest.fixture
def 							_A       (						lowerCAmelCase_					: int       ,    lowerCAmelCase_					: List[Any]      ):
     """simple docstring"""

     HfFolder.save_token(lowerCAmelCase_      )
     yield
     HfFolder.delete_token()



@pytest.fixture(scope="session"      )
def 							_A       (						):
     """simple docstring"""

     return HfApi(endpoint=lowerCAmelCase_      )



@pytest.fixture(scope="session"      )
def 							_A       (						lowerCAmelCase_					: HfApi      ):
     """simple docstring"""

     lowerCAmelCase__          =			HfFolder.get_token()
     HfFolder.save_token(lowerCAmelCase_      )
     yield CI_HUB_USER_TOKEN
     if previous_token is not None:
          HfFolder.save_token(lowerCAmelCase_      )



@pytest.fixture
def 							_A       (						lowerCAmelCase_					: Tuple      ):
     """simple docstring"""

     def _cleanup_repo(lowerCAmelCase_					: Optional[Any]      ):
          hf_api.delete_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"      )

     return _cleanup_repo



@pytest.fixture
def 							_A       (						lowerCAmelCase_					: Union[str, Any]      ):
     """simple docstring"""

     @contextmanager
     def _temporary_repo(lowerCAmelCase_					: str      ):
          try:
               yield repo_id
          finally:
               cleanup_repo(lowerCAmelCase_      )

     return _temporary_repo



@pytest.fixture(scope="session"      )
def 							_A       (						lowerCAmelCase_					: HfApi       ,    lowerCAmelCase_					: Union[str, Any]       ,    lowerCAmelCase_					: Any      ):
     """simple docstring"""

     lowerCAmelCase__          =			F'repo_txt_data-{int(time.time() * 1_0E3      )}'
     lowerCAmelCase__          =			F'{CI_HUB_USER}/{repo_name}'
     hf_api.create_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"       ,    private=lowerCAmelCase_      )
     hf_api.upload_file(
         token=lowerCAmelCase_       ,    path_or_fileobj=str(lowerCAmelCase_      )       ,    path_in_repo="data/text_data.txt"       ,    repo_id=lowerCAmelCase_       ,    repo_type="dataset"       ,    )
     yield repo_id
     try:
          hf_api.delete_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"      )
     except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
          pass



@pytest.fixture()
def 							_A       (						lowerCAmelCase_					: Optional[Any]       ,    lowerCAmelCase_					: Optional[Any]       ,    lowerCAmelCase_					: int      ):
     """simple docstring"""

     return hf_private_dataset_repo_txt_data_



@pytest.fixture(scope="session"      )
def 							_A       (						lowerCAmelCase_					: HfApi       ,    lowerCAmelCase_					: Tuple       ,    lowerCAmelCase_					: Tuple      ):
     """simple docstring"""

     lowerCAmelCase__          =			F'repo_zipped_txt_data-{int(time.time() * 1_0E3      )}'
     lowerCAmelCase__          =			F'{CI_HUB_USER}/{repo_name}'
     hf_api.create_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"       ,    private=lowerCAmelCase_      )
     hf_api.upload_file(
         token=lowerCAmelCase_       ,    path_or_fileobj=str(lowerCAmelCase_      )       ,    path_in_repo="data.zip"       ,    repo_id=lowerCAmelCase_       ,    repo_type="dataset"       ,    )
     yield repo_id
     try:
          hf_api.delete_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"      )
     except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
          pass



@pytest.fixture()
def 							_A       (						lowerCAmelCase_					: int       ,    lowerCAmelCase_					: List[str]       ,    lowerCAmelCase_					: Tuple      ):
     """simple docstring"""

     return hf_private_dataset_repo_zipped_txt_data_



@pytest.fixture(scope="session"      )
def 							_A       (						lowerCAmelCase_					: HfApi       ,    lowerCAmelCase_					: List[str]       ,    lowerCAmelCase_					: int      ):
     """simple docstring"""

     lowerCAmelCase__          =			F'repo_zipped_img_data-{int(time.time() * 1_0E3      )}'
     lowerCAmelCase__          =			F'{CI_HUB_USER}/{repo_name}'
     hf_api.create_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"       ,    private=lowerCAmelCase_      )
     hf_api.upload_file(
         token=lowerCAmelCase_       ,    path_or_fileobj=str(lowerCAmelCase_      )       ,    path_in_repo="data.zip"       ,    repo_id=lowerCAmelCase_       ,    repo_type="dataset"       ,    )
     yield repo_id
     try:
          hf_api.delete_repo(lowerCAmelCase_       ,    token=lowerCAmelCase_       ,    repo_type="dataset"      )
     except (requests.exceptions.HTTPError, ValueError):  # catch http error and token invalid error
          pass






@pytest.fixture()
def 							_A       (						lowerCAmelCase_					: Optional[Any]       ,    lowerCAmelCase_					: Dict       ,    lowerCAmelCase_					: List[str]      ):
     """simple docstring"""

     return hf_private_dataset_repo_zipped_img_data_
