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

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

UpperCAmelCase_       :   str   =       logging.WARNING

UpperCAmelCase_       :   Dict   =       True







def 		A_       (	):



      """simple docstring"""




      _lowerCamelCase				:   List[str]								=   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				:   Optional[int]								=   logging.StreamHandler()  # Set sys.stderr as stream.
            _lowerCamelCase				:   Optional[Any]								=   sys.stderr.flush

            # Apply our default configuration to the library root logger.
            _lowerCamelCase				:   List[str]								=   _get_library_root_logger()
            library_root_logger.addHandler(_default_handler							)
            library_root_logger.setLevel(_get_default_logging_level()							)
            _lowerCamelCase				:   Tuple								=   False







def 		A_       (	):



      """simple docstring"""




      global _default_handler

      with _lock:
            if not _default_handler:
                  return

            _lowerCamelCase				:   str								=   _get_library_root_logger()
            library_root_logger.removeHandler(_default_handler							)
            library_root_logger.setLevel(logging.NOTSET							)
            _lowerCamelCase				:   int								=   None







def 		A_       (	):



      """simple docstring"""




      return log_levels







def 		A_       (	_lowerCAmelCase   :    Optional[str] = None							):



      """simple docstring"""




      if name is None:
            _lowerCamelCase				:   Optional[Any]								=   _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				:   Union[str, Any]								=   False







def 		A_       (	):



      """simple docstring"""




      _configure_library_root_logger()
      _lowerCamelCase				:   List[Any]								=   True







def 		A_       (	):



      """simple docstring"""




      _lowerCamelCase				:   Optional[Any]								=   _get_library_root_logger().handlers

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







def 		A_       (	):



      """simple docstring"""




      _lowerCamelCase				:   Optional[Any]								=   _get_library_root_logger().handlers

      for handler in handlers:
            handler.setFormatter(_lowerCAmelCase							)







def 		A_       (	self   :    List[str]				,	*_lowerCAmelCase   :    int				,	**_lowerCAmelCase   :    str							):



      """simple docstring"""




      _lowerCamelCase				:   Union[str, Any]								=   os.getenv("TRANSFORMERS_NO_ADVISORY_WARNINGS"				,	_lowerCAmelCase							)
      if no_advisory_warnings:
            return
      self.warning(*_lowerCAmelCase				,	**_lowerCAmelCase							)


UpperCAmelCase_       :   Any   =       warning_advice







@functools.lru_cache(_lowerCAmelCase							)
def 		A_       (	self   :    Dict				,	*_lowerCAmelCase   :    Any				,	**_lowerCAmelCase   :    str							):



      """simple docstring"""




      self.warning(*_lowerCAmelCase				,	**_lowerCAmelCase							)


UpperCAmelCase_       :   int   =       warning_once

class  UpperCAmelCase__						:



    def __init__(	self      :       Optional[Any],*__A      :       List[str],**__A      :       Union[str, Any]     ):  # pylint: disable=unused-argument
          _lowerCamelCase				:   Optional[Any]								=   args[0] if args else None



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



    def __getattr__(	self      :       List[Any],__A      :       Union[str, Any]     ):

          def empty_fn(*__A      :       Optional[Any],**__A      :       Tuple     ):  # pylint: disable=unused-argument
                return

          return empty_fn



    def __enter__(	self      :       Any     ):
          return self



    def __exit__(	self      :       Any,__A      :       List[Any],__A      :       Optional[int],__A      :       int     ):
          return


class  UpperCAmelCase__						:



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



    def   lowerCamelCase_  (	self      :       str,*__A      :       Tuple,**__A      :       Optional[int]     ):
          _lowerCamelCase				:   Any								=   None
          if _tqdm_active:
                return tqdm_lib.tqdm.set_lock(*__A,**__A     )



    def   lowerCamelCase_  (	self      :       Optional[Any]     ):
          if _tqdm_active:
                return tqdm_lib.tqdm.get_lock()


UpperCAmelCase_       :   str   =       _tqdm_cls()







def 		A_       (	):



      """simple docstring"""




      global _tqdm_active
      return bool(_tqdm_active							)







def 		A_       (	):



      """simple docstring"""




      global _tqdm_active
      _lowerCamelCase				:   Union[str, Any]								=   True
      hf_hub_utils.enable_progress_bars()







def 		A_       (	):



      """simple docstring"""




      global _tqdm_active
      _lowerCamelCase				:   List[Any]								=   False
      hf_hub_utils.disable_progress_bars()

'''simple docstring'''






import warnings

from ..trainer import Trainer
from ..utils import logging


UpperCAmelCase_       :   Union[str, Any]   =       logging.get_logger(__name__)

class  UpperCAmelCase__						(       A ):



    def __init__(	self      :       int,__A      :       Any=None,**__A      :       Optional[Any]     ):
          warnings.warn(
              "`SageMakerTrainer` is deprecated and will be removed in v5 of Transformers. You can use `Trainer` "
              "instead.",__A,)
          super().__init__(args=__A,**__A     )