


'''simple docstring'''


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

UpperCAmelCase_		:   Union[str, Any]							   =		{
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

UpperCAmelCase_		:   int							   =		logging.WARNING

UpperCAmelCase_		:   int							   =		True







def 			snake_case_   (  ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       List[Any]     		=      os.getenv("""TRANSFORMERS_VERBOSITY"""							,      SCREAMING_SNAKE_CASE__     )
				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 			snake_case_   (  ):







				"""simple docstring"""





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







def 			snake_case_   (  ):







				"""simple docstring"""





				return logging.getLogger(_get_library_name()     )







def 			snake_case_   (  ):







				"""simple docstring"""





				global _default_handler

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

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







def 			snake_case_   (  ):







				"""simple docstring"""





				global _default_handler

				with _lock:
								if not _default_handler:
												return

								_SCREAMING_SNAKE_CASE :       List[Any]     		=      _get_library_root_logger()
								library_root_logger.removeHandler(_default_handler     )
								library_root_logger.setLevel(logging.NOTSET     )
								_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      None







def 			snake_case_   (  ):







				"""simple docstring"""





				return log_levels







def 			snake_case_   (  SCREAMING_SNAKE_CASE__ = None     ):







				"""simple docstring"""





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

				_configure_library_root_logger()
				return logging.getLogger(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				_configure_library_root_logger()
				return _get_library_root_logger().getEffectiveLevel()







def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_configure_library_root_logger()
				_get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				return set_verbosity(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				return set_verbosity(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				return set_verbosity(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				return set_verbosity(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				_configure_library_root_logger()

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







def 			snake_case_   (  ):







				"""simple docstring"""





				_configure_library_root_logger()

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







def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_configure_library_root_logger()

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







def 			snake_case_   (  SCREAMING_SNAKE_CASE__     ):







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







def 			snake_case_   (  ):







				"""simple docstring"""





				_configure_library_root_logger()
				_SCREAMING_SNAKE_CASE :       List[str]     		=      False







def 			snake_case_   (  ):







				"""simple docstring"""





				_configure_library_root_logger()
				_SCREAMING_SNAKE_CASE :       List[Any]     		=      True







def 			snake_case_   (  ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       Dict     		=      _get_library_root_logger().handlers

				for handler in handlers:
								_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      logging.Formatter("""[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"""     )
								handler.setFormatter(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       Union[str, Any]     		=      _get_library_root_logger().handlers

				for handler in handlers:
								handler.setFormatter(SCREAMING_SNAKE_CASE__     )







def 			snake_case_   (  self							,      *SCREAMING_SNAKE_CASE__							,      **SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE :       int     		=      os.getenv("""TRANSFORMERS_NO_ADVISORY_WARNINGS"""							,      SCREAMING_SNAKE_CASE__     )
				if no_advisory_warnings:
								return
				self.warning(*SCREAMING_SNAKE_CASE__							,      **SCREAMING_SNAKE_CASE__     )


UpperCAmelCase_		:   List[Any]							   =		warning_advice







@functools.lru_cache(SCREAMING_SNAKE_CASE__     )
def 			snake_case_   (  self							,      *SCREAMING_SNAKE_CASE__							,      **SCREAMING_SNAKE_CASE__     ):







				"""simple docstring"""





				self.warning(*SCREAMING_SNAKE_CASE__							,      **SCREAMING_SNAKE_CASE__     )


UpperCAmelCase_		:   List[str]							   =		warning_once





class     lowercase__  :





							'''simple docstring'''


							def __init__(    self    ,					*__snake_case    ,					**__snake_case  ):  # pylint: disable=unused-argument
											_SCREAMING_SNAKE_CASE :       List[str]     		=      args[0] if args else None






							def __iter__(    self  ):
											return iter(self._iterator  )






							def __getattr__(    self    ,					__snake_case  ):

											def empty_fn(*__snake_case    ,					**__snake_case  ):  # pylint: disable=unused-argument
															return

											return empty_fn






							def __enter__(    self  ):
											return self






							def __exit__(    self    ,					__snake_case    ,					__snake_case    ,					__snake_case  ):
											return





class     lowercase__  :





							'''simple docstring'''


							def __call__(    self    ,					*__snake_case    ,					**__snake_case  ):
											if _tqdm_active:
															return tqdm_lib.tqdm(*__snake_case    ,					**__snake_case  )
											else:
															return EmptyTqdm(*__snake_case    ,					**__snake_case  )






							def UpperCAmelCase_	(    self    ,					*__snake_case    ,					**__snake_case  ):
											_SCREAMING_SNAKE_CASE :       List[Any]     		=      None
											if _tqdm_active:
															return tqdm_lib.tqdm.set_lock(*__snake_case    ,					**__snake_case  )






							def UpperCAmelCase_	(    self  ):
											if _tqdm_active:
															return tqdm_lib.tqdm.get_lock()



UpperCAmelCase_		:   int							   =		_tqdm_cls()







def 			snake_case_   (  ):







				"""simple docstring"""





				global _tqdm_active
				return bool(_tqdm_active     )







def 			snake_case_   (  ):







				"""simple docstring"""





				global _tqdm_active
				_SCREAMING_SNAKE_CASE :       Optional[int]     		=      True
				hf_hub_utils.enable_progress_bars()







def 			snake_case_   (  ):







				"""simple docstring"""





				global _tqdm_active
				_SCREAMING_SNAKE_CASE :       Any     		=      False
				hf_hub_utils.disable_progress_bars()








'''simple docstring'''


import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
				import ctypes
				import msvcrt  # noqa





				class     lowercase__  (						ctypes.Structure					):





											'''simple docstring'''


											A_							:      Optional[Any]      	=  [("""size""", ctypes.c_int), ("""visible""", ctypes.c_byte)]







def 			snake_case_   (  ):







				"""simple docstring"""





				if os.name == "nt":
								_SCREAMING_SNAKE_CASE :       Tuple     		=      CursorInfo()
								_SCREAMING_SNAKE_CASE :       Tuple     		=      ctypes.windll.kernelaa.GetStdHandle(-11     )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
								_SCREAMING_SNAKE_CASE :       Optional[Any]     		=      False
								ctypes.windll.kernelaa.SetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25l"""     )
								sys.stdout.flush()







def 			snake_case_   (  ):







				"""simple docstring"""





				if os.name == "nt":
								_SCREAMING_SNAKE_CASE :       int     		=      CursorInfo()
								_SCREAMING_SNAKE_CASE :       List[str]     		=      ctypes.windll.kernelaa.GetStdHandle(-11     )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
								_SCREAMING_SNAKE_CASE :       Tuple     		=      True
								ctypes.windll.kernelaa.SetConsoleCursorInfo(SCREAMING_SNAKE_CASE__							,      ctypes.byref(SCREAMING_SNAKE_CASE__     )     )
				elif os.name == "posix":
								sys.stdout.write("""\033[?25h"""     )
								sys.stdout.flush()







@contextmanager
def 			snake_case_   (  ):







				"""simple docstring"""





				try:
								hide_cursor()
								yield
				finally:
								show_cursor()




