
"""simple docstring"""





import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


__SCREAMING_SNAKE_CASE					:						Tuple				= {
    '''<''': operator.lt,
    '''<=''': operator.le,
    '''==''': operator.eq,
    '''!=''': operator.ne,
    '''>=''': operator.ge,
    '''>''': operator.gt,
}
def 							A_     (__a				,   __a				,   __a				,   __a				,   __a				,   __a				):

					'''simple docstring'''





					if got_ver is None or want_ver is None:
										raise ValueError(
										    f'Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider'
										    f' reinstalling {pkg}.'				)
					if not ops[op](version.parse(__a				)				,   version.parse(__a				)				):
										raise ImportError(
										    f'{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}'				)
def 							A_     (__a				,   __a = None				):

					'''simple docstring'''





					A_				 =						f'\n{hint}' if hint is not None else ""

					# non-versioned check
					if re.match(R"^[\w_\-\d]+$"				,   __a				):
										A_ ,    A_ ,    A_				 =						requirement, None, None
					else:
										A_				 =						re.findall(R"^([^!=<>\s]+)([\s!=<>]{1,2}.+)"				,   __a				)
										if not match:
															raise ValueError(
															    "requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but"
															    f' got {requirement}'				)
										A_ ,    A_				 =						match[0]
										A_				 =						want_full.split(","				)  # there could be multiple requirements
										A_				 =						{}
										for w in want_range:
															A_				 =						re.findall(R"^([\s!=<>]{1,2})(.+)"				,   __a				)
															if not match:
																				raise ValueError(
																				    "requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,"
																				    f' but got {requirement}'				)
															A_ ,    A_				 =						match[0]
															A_				 =						want_ver
															if op not in ops:
																				raise ValueError(f'{requirement}: need one of {list(ops.keys()				)}, but got {op}'				)

    # special case
					if pkg == "python":
										A_				 =						".".join([str(__a				) for x in sys.version_info[:3]]				)
										for op, want_ver in wanted.items():
															_compare_versions(__a				,   __a				,   __a				,   __a				,   __a				,   __a				)
										return

					# check if any version is installed
					try:
										A_				 =						importlib.metadata.version(__a				)
					except importlib.metadata.PackageNotFoundError:
										raise importlib.metadata.PackageNotFoundError(
										    f'The \'{requirement}\' distribution was not found and is required by this application. {hint}'				)

					# check that the right version is installed if version number or a range was provided
					if want_ver is not None:
										for op, want_ver in wanted.items():
															_compare_versions(__a				,   __a				,   __a				,   __a				,   __a				,   __a				)




def 							A_     (__a				):

					'''simple docstring'''





					A_				 =						"Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main"
					return require_version(__a				,   __a				)






"""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
UpperCamelCase_					:						Optional[Any]				= '''src/transformers'''


# This is to make sure the transformers module imported is the one in the repo.
UpperCamelCase_					:						Union[str, Any]				= direct_transformers_import(PATH_TO_TRANSFORMERS)

UpperCamelCase_					:						List[Any]				= 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_					:						str				= re.compile(R'''\[(.+?)\]\((https://huggingface\.co/.+?)\)''')


UpperCamelCase_					:						Dict				= {
    '''DecisionTransformerConfig''',
    '''EncoderDecoderConfig''',
    '''MusicgenConfig''',
    '''RagConfig''',
    '''SpeechEncoderDecoderConfig''',
    '''TimmBackboneConfig''',
    '''VisionEncoderDecoderConfig''',
    '''VisionTextDualEncoderConfig''',
    '''LlamaConfig''',
}
def 							A_     (__a				):

					'''simple docstring'''





					A_				 =						None

					# source code of `config_class`
					A_				 =						inspect.getsource(__a				)
					A_				 =						_re_checkpoint.findall(__a				)

					# 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("/"				):
															A_				 =						ckpt_link[:-1]

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

					return checkpoint
def 							A_     ():

					'''simple docstring'''





					A_				 =						[]

					for config_class in list(CONFIG_MAPPING.values()				):
										# Skip deprecated models
										if "models.deprecated" in config_class.__module__:
															continue
										A_				 =						get_checkpoint_from_config_class(__a				)

										A_				 =						config_class.__name__
										if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
															configs_without_checkpoint.append(__a				)

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


if __name__ == "__main__":
		check_config_docstrings_have_checkpoints()




