


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_      : List[Any]  					=       threading.Lock()
UpperCAmelCase_      : Optional[logging.Handler]  					=       None

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

UpperCAmelCase_      : Any  					=       logging.WARNING

UpperCAmelCase_      : Dict  					=       True







def        SCREAMING_SNAKE_CASE_						(			)	->		Optional[Any]:

       """simple docstring"""

       a_					:		Union[str, Any]							=  os.getenv('TRANSFORMERS_VERBOSITY'  ,    __A				)
       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        SCREAMING_SNAKE_CASE_						(			)	->		str:

       """simple docstring"""

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







def        SCREAMING_SNAKE_CASE_						(			)	->		logging.Logger:

       """simple docstring"""

       return logging.getLogger(_get_library_name()				)







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       global _default_handler

       with _lock:
              if _default_handler:
                     # This library has already configured the library root logger.
                     return
              a_					:		List[Any]							=  logging.StreamHandler()  # Set sys.stderr as stream.
              a_					:		int							=  sys.stderr.flush

              # Apply our default configuration to the library root logger.
              a_					:		Any							=  _get_library_root_logger()
              library_root_logger.addHandler(_default_handler				)
              library_root_logger.setLevel(_get_default_logging_level()				)
              a_					:		Union[str, Any]							=  False







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       global _default_handler

       with _lock:
              if not _default_handler:
                     return

              a_					:		Union[str, Any]							=  _get_library_root_logger()
              library_root_logger.removeHandler(_default_handler				)
              library_root_logger.setLevel(logging.NOTSET				)
              a_					:		Dict							=  None







def        SCREAMING_SNAKE_CASE_						(			)	->		int:

       """simple docstring"""

       return log_levels







def        SCREAMING_SNAKE_CASE_						(			__A :			Optional[str] = None				)	->		logging.Logger:

       """simple docstring"""

       if name is None:
              a_					:		Any							=  _get_library_name()

       _configure_library_root_logger()
       return logging.getLogger(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		int:

       """simple docstring"""

       _configure_library_root_logger()
       return _get_library_root_logger().getEffectiveLevel()







def        SCREAMING_SNAKE_CASE_						(			__A :			int				)	->		None:

       """simple docstring"""

       _configure_library_root_logger()
       _get_library_root_logger().setLevel(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		Tuple:

       """simple docstring"""

       return set_verbosity(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		Any:

       """simple docstring"""

       return set_verbosity(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		List[Any]:

       """simple docstring"""

       return set_verbosity(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		List[str]:

       """simple docstring"""

       return set_verbosity(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       _configure_library_root_logger()

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







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       _configure_library_root_logger()

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







def        SCREAMING_SNAKE_CASE_						(			__A :			logging.Handler				)	->		None:

       """simple docstring"""

       _configure_library_root_logger()

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







def        SCREAMING_SNAKE_CASE_						(			__A :			logging.Handler				)	->		None:

       """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(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       _configure_library_root_logger()
       a_					:		List[str]							=  False







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       _configure_library_root_logger()
       a_					:		int							=  True







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       a_					:		Any							=  _get_library_root_logger().handlers

       for handler in handlers:
              a_					:		Dict							=  logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'				)
              handler.setFormatter(__A				)







def        SCREAMING_SNAKE_CASE_						(			)	->		None:

       """simple docstring"""

       a_					:		int							=  _get_library_root_logger().handlers

       for handler in handlers:
              handler.setFormatter(__A				)







def        SCREAMING_SNAKE_CASE_						(			self :			List[str]  ,    *__A :			Any  ,    **__A :			str				)	->		Tuple:

       """simple docstring"""

       a_					:		Optional[Any]							=  os.getenv('TRANSFORMERS_NO_ADVISORY_WARNINGS'  ,    __A				)
       if no_advisory_warnings:
              return
       self.warning(*__A  ,    **__A				)


UpperCAmelCase_      : Tuple  					=       warning_advice







@functools.lru_cache(__A				)
def        SCREAMING_SNAKE_CASE_						(			self :			Dict  ,    *__A :			List[Any]  ,    **__A :			Optional[int]				)	->		List[Any]:

       """simple docstring"""

       self.warning(*__A  ,    **__A				)


UpperCAmelCase_      : Union[str, Any]  					=       warning_once
class  SCREAMING_SNAKE_CASE__  :
      def __init__(       self				:       Dict     ,							*SCREAMING_SNAKE_CASE__				:       Tuple     ,							**SCREAMING_SNAKE_CASE__				:       Union[str, Any]     )		->			List[Any]:  # pylint: disable=unused-argument
             a_					:		Optional[int]							=  args[0] if args else None
      def __iter__(       self				:       List[str]     )		->			List[Any]:
             return iter(self._iterator     )
      def __getattr__(       self				:       Tuple     ,							SCREAMING_SNAKE_CASE__				:       List[Any]     )		->			Optional[Any]:

             def empty_fn(*SCREAMING_SNAKE_CASE__				:       List[Any]     ,							**SCREAMING_SNAKE_CASE__				:       int     ):  # pylint: disable=unused-argument
                    return

             return empty_fn
      def __enter__(       self				:       List[str]     )		->			Any:
             return self

      def __exit__(       self				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       Dict     ,							SCREAMING_SNAKE_CASE__				:       Optional[int]     ,							SCREAMING_SNAKE_CASE__				:       List[str]     )		->			Tuple:
             return
class  SCREAMING_SNAKE_CASE__  :
      def __call__(       self				:       Any     ,							*SCREAMING_SNAKE_CASE__				:       List[Any]     ,							**SCREAMING_SNAKE_CASE__				:       Optional[int]     )		->			List[str]:
             if _tqdm_active:
                    return tqdm_lib.tqdm(*SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )
             else:
                    return EmptyTqdm(*SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )
      def        SCREAMING_SNAKE_CASE							(       self				:       List[str]     ,							*SCREAMING_SNAKE_CASE__				:       Dict     ,							**SCREAMING_SNAKE_CASE__				:       List[str]     )		->			List[str]:
             a_					:		Union[str, Any]							=  None
             if _tqdm_active:
                    return tqdm_lib.tqdm.set_lock(*SCREAMING_SNAKE_CASE__     ,							**SCREAMING_SNAKE_CASE__     )

      def        SCREAMING_SNAKE_CASE							(       self				:       Union[str, Any]     )		->			Union[str, Any]:
             if _tqdm_active:
                    return tqdm_lib.tqdm.get_lock()
UpperCAmelCase_      : List[str]  					=       _tqdm_cls()







def        SCREAMING_SNAKE_CASE_						(			)	->		bool:

       """simple docstring"""

       global _tqdm_active
       return bool(_tqdm_active				)







def        SCREAMING_SNAKE_CASE_						(			)	->		Dict:

       """simple docstring"""

       global _tqdm_active
       a_					:		Any							=  True
       hf_hub_utils.enable_progress_bars()







def        SCREAMING_SNAKE_CASE_						(			)	->		int:

       """simple docstring"""

       global _tqdm_active
       a_					:		Optional[Any]							=  False
       hf_hub_utils.disable_progress_bars()






import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text







def        SCREAMING_SNAKE_CASE_						(			__A :			List[str]				)	->		str:

       """simple docstring"""

       a_					:		Tuple							=  []
       for line in lines:
              a_					:		Any							=  re.sub(R'#.*'  ,    ''  ,    __A				)  # remove comments
              if line:
                     filtered_lines.append(__A				)
       a_					:		Tuple							=  '\n'.join(__A				)

       # Make a hash from all this code
       a_					:		Tuple							=  full_str.encode('utf-8'				)
       return shaaaa(__A				).hexdigest()


# get importable module names and hash for caching
UpperCAmelCase_      : List[Any]  					=       {
    'csv': (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    'json': (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    'pandas': (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    'parquet': (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    'arrow': (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    'text': (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    'imagefolder': (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    'audiofolder': (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
UpperCAmelCase_      : Dict  					=       {
    '.csv': ('csv', {}),
    '.tsv': ('csv', {'sep': '\t'}),
    '.json': ('json', {}),
    '.jsonl': ('json', {}),
    '.parquet': ('parquet', {}),
    '.arrow': ('arrow', {}),
    '.txt': ('text', {}),
}
_EXTENSION_TO_MODULE.update({ext: ('imagefolder', {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ('imagefolder', {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ('audiofolder', {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ('audiofolder', {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
UpperCAmelCase_      : Optional[int]  					=       {'imagefolder', 'audiofolder'}

# Used to filter data files based on extensions given a module name
UpperCAmelCase_      : Dict[str, List[str]]  					=       {}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
   _MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append('.zip')
_MODULE_TO_EXTENSIONS["audiofolder"].append('.zip')


