


"""simple docstring"""

import importlib
import inspect
import os
import re


# 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
UpperCAmelCase__  							="src/transformers"


# This is to make sure the transformers module imported is the one in the repo.
UpperCAmelCase__  							=importlib.util.spec_from_file_location(
    "transformers",
    os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
    submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
UpperCAmelCase__  							=spec.loader.load_module()

UpperCAmelCase__  							=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)`
UpperCAmelCase__  							=re.compile("\[(.+?)\]\((https://huggingface\.co/.+?)\)")


UpperCAmelCase__  							={
    "CLIPConfigMixin",
    "DecisionTransformerConfigMixin",
    "EncoderDecoderConfigMixin",
    "RagConfigMixin",
    "SpeechEncoderDecoderConfigMixin",
    "VisionEncoderDecoderConfigMixin",
    "VisionTextDualEncoderConfigMixin",
}


def lowerCAmelCase_      (				):






 """simple docstring"""







 __lowercase									=	[]

 for config_class in list(CONFIG_MAPPING.values() ):
  __lowercase									=	False

  # source code of `config_class`
  __lowercase									=	inspect.getsource(UpperCamelCase__ )
  __lowercase									=	_re_checkpoint.findall(UpperCamelCase__ )

  for checkpoint in checkpoints:
   # Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
   # For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
   __lowercase							,		__lowercase									=	checkpoint

   # verify the checkpoint name corresponds to the checkpoint link
   __lowercase									=	f'''https://huggingface.co/{ckpt_name}'''
   if ckpt_link == ckpt_link_from_name:
    __lowercase									=	True
    break

  __lowercase									=	config_class.__name__
  if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
   configs_without_checkpoint.append(UpperCamelCase__ )

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


if __name__ == "__main__":
    check_config_docstrings_have_checkpoints()




"""simple docstring"""

from typing import List

from .keymap import KEYMAP, get_character


def lowerCAmelCase_      (				UpperCamelCase__	: str ):






 """simple docstring"""







 def decorator(UpperCamelCase__	: Tuple ):
  __lowercase									=	getattr(UpperCamelCase__				,   """handle_key"""				,   [] )
  handle += [key]
  setattr(UpperCamelCase__				,   """handle_key"""				,   UpperCamelCase__ )
  return func

 return decorator


def lowerCAmelCase_      (				*UpperCamelCase__	: List[str] ):






 """simple docstring"""







 def decorator(UpperCamelCase__	: Tuple ):
  __lowercase									=	getattr(UpperCamelCase__				,   """handle_key"""				,   [] )
  handle += keys
  setattr(UpperCamelCase__				,   """handle_key"""				,   UpperCamelCase__ )
  return func

 return decorator





class    lowerCamelCase__						(		_a    ):
      def __new__(		cls	:	str      ,       A_	:	Optional[Any]      ,       A_	:	Union[str, Any]      ,       A_	:	int							):






       '''simple docstring'''


       __lowercase									=	super().__new__(cls      ,       A_      ,       A_      ,       A_							)
       if not hasattr(A_      ,       """key_handler"""							):
        setattr(A_      ,       """key_handler"""      ,       {}							)
       setattr(A_      ,       """handle_input"""      ,       KeyHandler.handle_input							)

       for value in attrs.values():
        __lowercase									=	getattr(A_      ,       """handle_key"""      ,       []							)
        for key in handled_keys:
         __lowercase									=	value
       return new_cls






      @staticmethod
      def SCREAMING_SNAKE_CASE_	(		cls	:	Dict							):






       '''simple docstring'''


       __lowercase									=	get_character()
       if char != KEYMAP["undefined"]:
        __lowercase									=	ord(A_							)
       __lowercase									=	cls.key_handler.get(A_							)
       if handler:
        __lowercase									=	char
        return handler(cls							)
       else:
        return None






def lowerCAmelCase_      (				cls	: int ):






 """simple docstring"""







 return KeyHandler(cls.__name__				,   cls.__bases__				,   cls.__dict__.copy() )
