





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							:			Dict        =							threading.Lock()
_UpperCAmelCase							:			Optional[logging.Handler]        =							None

_UpperCAmelCase							:			Optional[Any]        =							{
    """debug""": logging.DEBUG,
    """info""": logging.INFO,
    """warning""": logging.WARNING,
    """error""": logging.ERROR,
    """critical""": logging.CRITICAL,
}

_UpperCAmelCase							:			Dict        =							logging.WARNING

_UpperCAmelCase							:			Optional[int]        =							True


def 			SCREAMING_SNAKE_CASE (			)     ->	List[str]:
    lowerCamelCase__       : List[str]   					=						os.getenv('TRANSFORMERS_VERBOSITY'		,      _UpperCAmelCase					)
    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:
    return __name__.split('.'					)[0]


def 			SCREAMING_SNAKE_CASE (			)     ->	logging.Logger:
    return logging.getLogger(_get_library_name()					)


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    global _default_handler

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

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


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    global _default_handler

    with _lock:
        if not _default_handler:
            return

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


def 			SCREAMING_SNAKE_CASE (			)     ->	Any:
    return log_levels


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase = None					)     ->	logging.Logger:

    if name is None:
        lowerCamelCase__       : Tuple   					=						_get_library_name()

    _configure_library_root_logger()
    return logging.getLogger(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			)     ->	int:
    _configure_library_root_logger()
    return _get_library_root_logger().getEffectiveLevel()


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	None:
    _configure_library_root_logger()
    _get_library_root_logger().setLevel(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			)     ->	Optional[int]:
    return set_verbosity(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			)     ->	Union[str, Any]:
    return set_verbosity(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			)     ->	Tuple:
    return set_verbosity(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			)     ->	Any:
    return set_verbosity(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    _configure_library_root_logger()

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


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    _configure_library_root_logger()

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


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	None:
    _configure_library_root_logger()

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


def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase					)     ->	None:
    _configure_library_root_logger()

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


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    _configure_library_root_logger()
    lowerCamelCase__       : List[str]   					=						False


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    _configure_library_root_logger()
    lowerCamelCase__       : List[Any]   					=						True


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    lowerCamelCase__       : Union[str, Any]   					=						_get_library_root_logger().handlers

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


def 			SCREAMING_SNAKE_CASE (			)     ->	None:
    lowerCamelCase__       : List[Any]   					=						_get_library_root_logger().handlers

    for handler in handlers:
        handler.setFormatter(_UpperCAmelCase					)


def 			SCREAMING_SNAKE_CASE (			self		,      *_UpperCAmelCase		,      **_UpperCAmelCase					)     ->	Tuple:
    lowerCamelCase__       : Optional[int]   					=						os.getenv('TRANSFORMERS_NO_ADVISORY_WARNINGS'		,      _UpperCAmelCase					)
    if no_advisory_warnings:
        return
    self.warning(*_UpperCAmelCase		,      **_UpperCAmelCase					)


_UpperCAmelCase							:			List[str]        =							warning_advice


@functools.lru_cache(_UpperCAmelCase					)
def 			SCREAMING_SNAKE_CASE (			self		,      *_UpperCAmelCase		,      **_UpperCAmelCase					)     ->	Tuple:
    self.warning(*_UpperCAmelCase		,      **_UpperCAmelCase					)


_UpperCAmelCase							:			Dict        =							warning_once

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

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

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







 def __exit__( self    : Optional[Any]     ,	UpperCAmelCase    : Dict     ,	UpperCAmelCase    : Any     ,	UpperCAmelCase    : Optional[Any]      )     ->      Optional[Any]:
     return


class   lowerCAmelCase				:
 def __call__( self    : Any     ,	*UpperCAmelCase    : Optional[Any]     ,	**UpperCAmelCase    : int      )     ->      Any:
     if _tqdm_active:
         return tqdm_lib.tqdm(*UpperCAmelCase     ,	**UpperCAmelCase      )
     else:
         return EmptyTqdm(*UpperCAmelCase     ,	**UpperCAmelCase      )
 def 	A_      ( self    : List[str]     ,	*UpperCAmelCase    : Dict     ,	**UpperCAmelCase    : List[Any]      )     ->      Any:
     lowerCamelCase__       : Optional[Any]   					=						None
     if _tqdm_active:
         return tqdm_lib.tqdm.set_lock(*UpperCAmelCase     ,	**UpperCAmelCase      )







 def 	A_      ( self    : Any      )     ->      List[Any]:
     if _tqdm_active:
         return tqdm_lib.tqdm.get_lock()


_UpperCAmelCase							:			List[str]        =							_tqdm_cls()


def 			SCREAMING_SNAKE_CASE (			)     ->	bool:
    global _tqdm_active
    return bool(_tqdm_active					)


def 			SCREAMING_SNAKE_CASE (			)     ->	Tuple:
    global _tqdm_active
    lowerCamelCase__       : Dict   					=						True
    hf_hub_utils.enable_progress_bars()


def 			SCREAMING_SNAKE_CASE (			)     ->	Dict:
    global _tqdm_active
    lowerCamelCase__       : str   					=						False
    hf_hub_utils.disable_progress_bars()












def 			SCREAMING_SNAKE_CASE (			_UpperCAmelCase		,      _UpperCAmelCase					)     ->	Union[str, Any]:
    lowerCamelCase__       : List[Any]   					=						[1]
    for i in range(2		,      _UpperCAmelCase					):
        factorials.append(factorials[-1] * i					)
    assert 0 <= k < factorials[-1] * n, "k out of bounds"

    lowerCamelCase__       : str   					=						[]
    lowerCamelCase__       : Optional[Any]   					=						list(range(_UpperCAmelCase					)					)

    # Find permutation
    while factorials:
        lowerCamelCase__       : List[str]   					=						factorials.pop()
        lowerCamelCase__					,				lowerCamelCase__       : Tuple   					=						divmod(_UpperCAmelCase		,      _UpperCAmelCase					)
        permutation.append(elements[number]					)
        elements.remove(elements[number]					)
    permutation.append(elements[0]					)

    return permutation


if __name__ == "__main__":
    import doctest

    doctest.testmod()





