





'''simple docstring'''


import inspect
import re

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
lowerCAmelCase					:     Any												='''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
lowerCAmelCase					:     Tuple												=direct_transformers_import(PATH_TO_TRANSFORMERS)

lowerCAmelCase					:     int												=transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
lowerCAmelCase					:     int												=re.compile(r'''\[(.+?)\]\((https://huggingface\.co/.+?)\)''')


lowerCAmelCase					:     Optional[int]												={
    '''DecisionTransformerConfig''',
    '''EncoderDecoderConfig''',
    '''MusicgenConfig''',
    '''RagConfig''',
    '''SpeechEncoderDecoderConfig''',
    '''TimmBackboneConfig''',
    '''VisionEncoderDecoderConfig''',
    '''VisionTextDualEncoderConfig''',
    '''LlamaConfig''',
}
def 							UpperCAmelCase_  (						__lowerCamelCase					:					Any ):
   lowercase_			:str    			= None

   # source code of `config_class`
   lowercase_			:Dict    			= inspect.getsource(__lowerCamelCase )
   lowercase_			:Optional[Any]    			= _re_checkpoint.findall(__lowerCamelCase )

   # Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
   # For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
   for ckpt_name, ckpt_link in checkpoints:
      # allow the link to end with `/`
      if ckpt_link.endswith("/" ):
         lowercase_			:int    			= ckpt_link[:-1]

      # verify the checkpoint name corresponds to the checkpoint link
      lowercase_			:int    			= F'https://huggingface.co/{ckpt_name}'
      if ckpt_link == ckpt_link_from_name:
         lowercase_			:Dict    			= ckpt_name
         break

   return checkpoint
def 							UpperCAmelCase_  (						):
   lowercase_			:List[Any]    			= []

   for config_class in list(CONFIG_MAPPING.values() ):
      # Skip deprecated models
      if "models.deprecated" in config_class.__module__:
         continue
      lowercase_			:List[str]    			= get_checkpoint_from_config_class(__lowerCamelCase )

      lowercase_			:Union[str, Any]    			= config_class.__name__
      if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
         configs_without_checkpoint.append(__lowerCamelCase )

   if len(__lowerCamelCase ) > 0:
      lowercase_			:Dict    			= "\n".join(sorted(__lowerCamelCase ) )
      raise ValueError(F'The following configurations don\'t contain any valid checkpoint:\n{message}' )


if __name__ == "__main__":
 check_config_docstrings_have_checkpoints()









'''simple docstring'''


import pytest

from datasets import inspect_metric, list_metrics, load_metric
@pytest.fixture
def 							UpperCAmelCase_  (						__lowerCamelCase					:					List[str] ):
   monkeypatch.setattr("datasets.utils.deprecation_utils._emitted_deprecation_warnings"	,set() )
@pytest.fixture
def 							UpperCAmelCase_  (						__lowerCamelCase					:					Any ):
   class       a_   :





        def __init__( self		:					int	,      lowercase		:					int						):





           """simple docstring"""




           lowercase_			:Optional[Any]    			= metric_id







   class       a_   :
        __A      =			[MetricMock(_lowerCAmelCase							) for metric_id in ["accuracy", "mse", "precision", "codeparrot/apps_metric"]]





        def 							lowercase__      ( self		:					Union[str, Any]						):





           """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 							UpperCAmelCase_  (						__lowerCamelCase					:					Union[str, Any]	,__lowerCamelCase					:					int	,__lowerCamelCase					:					Optional[int]	,__lowerCamelCase					:					Union[str, Any]	,__lowerCamelCase					:					Tuple ):
   if "tmp_path" in args:
      lowercase_			:Union[str, Any]    			= tuple(arg if arg != "tmp_path" else tmp_path for arg in args )
   with pytest.warns(__lowerCamelCase	,match="https://huggingface.co/docs/evaluate" ):
      func(*__lowerCamelCase )


