
'''simple docstring'''



import os

import pytest

from datasets import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
)


_lowercase       =		pytest.mark.integration


@pytest.mark.parametrize("""path"""			,     ["""paws""", """csv"""]		)
def A				(__lowerCamelCase				:str			,     __lowerCamelCase				:Tuple		):
						inspect_dataset(__A			,     __A		)
						_lowerCAmelCase  						=			path + """.py"""
						assert script_name in os.listdir(__A		)
						assert "__pycache__" not in os.listdir(__A		)


@pytest.mark.filterwarnings("""ignore:inspect_metric is deprecated:FutureWarning"""		)
@pytest.mark.filterwarnings("""ignore:metric_module_factory is deprecated:FutureWarning"""		)
@pytest.mark.parametrize("""path"""			,     ["""accuracy"""]		)
def A				(__lowerCamelCase				:int			,     __lowerCamelCase				:Dict		):
						inspect_metric(__A			,     __A		)
						_lowerCAmelCase  						=			path + """.py"""
						assert script_name in os.listdir(__A		)
						assert "__pycache__" not in os.listdir(__A		)


@pytest.mark.parametrize(
    """path, config_name, expected_splits"""			,     [
        ("""squad""", """plain_text""", ["""train""", """validation"""]),
        ("""dalle-mini/wit""", """dalle-mini--wit""", ["""train"""]),
        ("""paws""", """labeled_final""", ["""train""", """test""", """validation"""]),
    ]			,     )
def A				(__lowerCamelCase				:Any			,     __lowerCamelCase				:Optional[Any]			,     __lowerCamelCase				:Optional[int]		):
						_lowerCAmelCase  						=			get_dataset_config_info(__A			,     config_name=__A		)
						assert info.config_name == config_name
						assert list(info.splits.keys()		) == expected_splits


@pytest.mark.parametrize(
    """path, config_name, expected_exception"""			,     [
        ("""paws""", None, ValueError),
    ]			,     )
def A				(__lowerCamelCase				:int			,     __lowerCamelCase				:Union[str, Any]			,     __lowerCamelCase				:Optional[Any]		):


						with pytest.raises(__A		):
												get_dataset_config_info(__A			,     config_name=__A		)


@pytest.mark.parametrize(
    """path, expected"""			,     [
        ("""squad""", """plain_text"""),
        ("""acronym_identification""", """default"""),
        ("""lhoestq/squad""", """plain_text"""),
        ("""lhoestq/test""", """default"""),
        ("""lhoestq/demo1""", """lhoestq--demo1"""),
        ("""dalle-mini/wit""", """dalle-mini--wit"""),
    ]			,     )
def A				(__lowerCamelCase				:int			,     __lowerCamelCase				:Optional[int]		):
						_lowerCAmelCase  						=			get_dataset_config_names(__A		)
						assert expected in config_names


@pytest.mark.parametrize(
    """path, expected_configs, expected_splits_in_first_config"""			,     [
        ("""squad""", ["""plain_text"""], ["""train""", """validation"""]),
        ("""dalle-mini/wit""", ["""dalle-mini--wit"""], ["""train"""]),
        ("""paws""", ["""labeled_final""", """labeled_swap""", """unlabeled_final"""], ["""train""", """test""", """validation"""]),
    ]			,     )
def A				(__lowerCamelCase				:List[str]			,     __lowerCamelCase				:Any			,     __lowerCamelCase				:List[Any]		):
						_lowerCAmelCase  						=			get_dataset_infos(__A		)
						assert list(infos.keys()		) == expected_configs
						_lowerCAmelCase  						=			expected_configs[0]
						assert expected_config in infos
						_lowerCAmelCase  						=			infos[expected_config]
						assert info.config_name == expected_config
						assert list(info.splits.keys()		) == expected_splits_in_first_config


@pytest.mark.parametrize(
    """path, expected_config, expected_splits"""			,     [
        ("""squad""", """plain_text""", ["""train""", """validation"""]),
        ("""dalle-mini/wit""", """dalle-mini--wit""", ["""train"""]),
        ("""paws""", """labeled_final""", ["""train""", """test""", """validation"""]),
    ]			,     )
def A				(__lowerCamelCase				:Any			,     __lowerCamelCase				:Optional[Any]			,     __lowerCamelCase				:int		):
						_lowerCAmelCase  						=			get_dataset_infos(__A		)
						assert expected_config in infos
						_lowerCAmelCase  						=			infos[expected_config]
						assert info.config_name == expected_config
						assert list(info.splits.keys()		) == expected_splits





@pytest.mark.parametrize(
    """path, config_name, expected_exception"""			,     [
        ("""paws""", None, ValueError),
    ]			,     )
def A				(__lowerCamelCase				:Union[str, Any]			,     __lowerCamelCase				:Tuple			,     __lowerCamelCase				:List[Any]		):


						with pytest.raises(__A		):
												get_dataset_split_names(__A			,     config_name=__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
_lowercase    =		"""src/transformers"""


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

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


_lowercase    =		{
    """DecisionTransformerConfig""",
    """EncoderDecoderConfig""",
    """MusicgenConfig""",
    """RagConfig""",
    """SpeechEncoderDecoderConfig""",
    """TimmBackboneConfig""",
    """VisionEncoderDecoderConfig""",
    """VisionTextDualEncoderConfig""",
    """LlamaConfig""",
}


def A				(__lowerCamelCase				:str		):
						_lowerCAmelCase  						=			None

						# source code of `config_class`
						_lowerCAmelCase  						=			inspect.getsource(__lowerCamelCase		)
						_lowerCAmelCase  						=			_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("""/"""		):
																		_lowerCAmelCase  						=			ckpt_link[:-1]

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

						return checkpoint


def A				():
						_lowerCAmelCase  						=			[]

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

												_lowerCAmelCase  						=			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:
												_lowerCAmelCase  						=			"""\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()
