






"""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		:  Optional[Any]						=		threading.Lock()
_UpperCamelCase		:  Optional[int]						=		None

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

_UpperCamelCase		:  Optional[int]						=		logging.WARNING

_UpperCamelCase		:  str						=		True
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  lowercase							    =       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 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return __name__.split('.'    )[0]
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return logging.getLogger(_get_library_name()    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  global _default_handler

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

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





  '''simple docstring'''





  global _default_handler

  with _lock:
    if not _default_handler:
      return

    lowercase							    =       _get_library_root_logger()
    library_root_logger.removeHandler(_default_handler    )
    library_root_logger.setLevel(logging.NOTSET    )
    lowercase							    =       None
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return log_levels
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  Optional[str] = None    ):





  '''simple docstring'''





  if name is None:
    lowercase							    =       _get_library_name()

  _configure_library_root_logger()
  return logging.getLogger(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  _configure_library_root_logger()
  return _get_library_root_logger().getEffectiveLevel()
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  int    ):





  '''simple docstring'''





  _configure_library_root_logger()
  _get_library_root_logger().setLevel(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return set_verbosity(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return set_verbosity(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return set_verbosity(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  return set_verbosity(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().removeHandler(_default_handler    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().addHandler(_default_handler    )
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  logging.Handler    ):





  '''simple docstring'''





  _configure_library_root_logger()

  assert handler is not None
  _get_library_root_logger().addHandler(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    __snake_case			:  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(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  _configure_library_root_logger()
  lowercase							    =       False
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  _configure_library_root_logger()
  lowercase							    =       True
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  lowercase							    =       _get_library_root_logger().handlers

  for handler in handlers:
    lowercase							    =       logging.Formatter('[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'    )
    handler.setFormatter(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  lowercase							    =       _get_library_root_logger().handlers

  for handler in handlers:
    handler.setFormatter(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    self			:  List[Any]		,					*__snake_case			:  Optional[int]		,					**__snake_case			:  int    ):





  '''simple docstring'''





  lowercase							    =       os.getenv('TRANSFORMERS_NO_ADVISORY_WARNINGS'		,					SCREAMING_SNAKE_CASE_    )
  if no_advisory_warnings:
    return
  self.warning(*SCREAMING_SNAKE_CASE_		,					**SCREAMING_SNAKE_CASE_    )


_UpperCamelCase		:  int						=		warning_advice
@functools.lru_cache(SCREAMING_SNAKE_CASE_    )
def 						_SCREAMING_SNAKE_CASE (    self			:  Tuple		,					*__snake_case			:  int		,					**__snake_case			:  Optional[int]    ):





  '''simple docstring'''





  self.warning(*SCREAMING_SNAKE_CASE_		,					**SCREAMING_SNAKE_CASE_    )


_UpperCamelCase		:  List[Any]						=		warning_once

class        a     :







    def __init__(			self							,		*_lowerCamelCase							,		**_lowerCamelCase       ):  # pylint: disable=unused-argument
      lowercase							    =       args[0] if args else None







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







    def __getattr__(			self							,		_lowerCamelCase       ):



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

      return empty_fn







    def __enter__(			self       ):
      return self







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


class        a     :







    def __call__(			self							,		*_lowerCamelCase							,		**_lowerCamelCase       ):



      if _tqdm_active:
        return tqdm_lib.tqdm(*_A							,		**_A       )
      else:
        return EmptyTqdm(*_A							,		**_A       )







    def 			UpperCamelCase_      (			self							,		*_lowerCamelCase							,		**_lowerCamelCase       ):
      lowercase							    =       None
      if _tqdm_active:
        return tqdm_lib.tqdm.set_lock(*_A							,		**_A       )







    def 			UpperCamelCase_      (			self       ):



      if _tqdm_active:
        return tqdm_lib.tqdm.get_lock()


_UpperCamelCase		:  str						=		_tqdm_cls()
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  global _tqdm_active
  return bool(_tqdm_active    )
def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  global _tqdm_active
  lowercase							    =       True
  hf_hub_utils.enable_progress_bars()



def 						_SCREAMING_SNAKE_CASE (    ):





  '''simple docstring'''





  global _tqdm_active
  lowercase							    =       False
  hf_hub_utils.disable_progress_bars()








import pytest

from datasets import inspect_metric, list_metrics, load_metric







@pytest.fixture
def 	_a      (						SCREAMING_SNAKE_CASE_							:				Optional[Any]     ):
					monkeypatch.setattr("datasets.utils.deprecation_utils._emitted_deprecation_warnings"      ,      set()     )







@pytest.fixture
def 	_a      (						SCREAMING_SNAKE_CASE_							:				List[Any]     ):
					class 			a__    :






											def __init__(   self		,			_A			):




																"""simple docstring"""



																__lowerCAmelCase				   =       metric_id






					class 			a__    :
											_a							:    Optional[int]					=    [MetricMock(snake_case__      ) for metric_id in ["""accuracy""", """mse""", """precision""", """codeparrot/apps_metric"""]]






											def 				__SCREAMING_SNAKE_CASE(   self			):




																"""simple docstring"""



																return self._metrics






					monkeypatch.setattr("datasets.inspect.huggingface_hub"      ,      HfhMock()     )







@pytest.mark.parametrize(
    "func, args"      ,      [(load_metric, ("metrics/mse",)), (list_metrics, ()), (inspect_metric, ("metrics/mse", "tmp_path"))]     )
def 	_a      (						SCREAMING_SNAKE_CASE_							:				Tuple      ,      SCREAMING_SNAKE_CASE_							:				List[str]      ,      SCREAMING_SNAKE_CASE_							:				int      ,      SCREAMING_SNAKE_CASE_							:				Optional[int]      ,      SCREAMING_SNAKE_CASE_							:				Optional[int]     ):
					if "tmp_path" in args:
										__lowerCAmelCase				   =       tuple(arg if arg != "tmp_path" else tmp_path for arg in args     )
					with pytest.warns(SCREAMING_SNAKE_CASE_      ,      match="https://huggingface.co/docs/evaluate"     ):
										func(*SCREAMING_SNAKE_CASE_     )




