




import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


a__		     =     logging.getLogger()


@unittest.skip('Temporarily disable the doc tests.'   )
@require_torch
@require_tf
@slow
class    SCREAMING_SNAKE_CASE_				(       unittest.TestCase   ):



	"""simple docstring"""


	def 					lowerCamelCase__     (					self		:						List[str]					,     lowerCAmelCase		:						Path					,     lowerCAmelCase		:						Union[str, None] = None					,     lowerCAmelCase		:						Union[List[str], None] = None					,     lowerCAmelCase		:						Union[str, List[str], None] = None					,     lowerCAmelCase		:						bool = True					,     )	->       str:







						"""simple docstring"""







						__UpperCamelCase					:	str             =      [file for file in os.listdir(lowerCAmelCase	) if os.path.isfile(os.path.join(lowerCAmelCase					,     lowerCAmelCase	)	)]

						if identifier is not None:
											__UpperCamelCase					:	Dict             =      [file for file in files if identifier in file]

						if n_identifier is not None:
											if isinstance(lowerCAmelCase					,     lowerCAmelCase	):
																for n_ in n_identifier:
																					__UpperCamelCase					:	List[Any]             =      [file for file in files if n_ not in file]
											else:
																__UpperCamelCase					:	List[str]             =      [file for file in files if n_identifier not in file]

						__UpperCamelCase					:	List[str]             =      ignore_files or []
						ignore_files.append("""__init__.py"""	)
						__UpperCamelCase					:	Any             =      [file for file in files if file not in ignore_files]

						for file in files:
											# Open all files
											print("""Testing"""					,     lowerCAmelCase	)

											if only_modules:
																__UpperCamelCase					:	Tuple             =      file.split("""."""	)[0]
																try:
																					__UpperCamelCase					:	int             =      getattr(lowerCAmelCase					,     lowerCAmelCase	)
																					__UpperCamelCase					:	List[Any]             =      doctest.DocTestSuite(lowerCAmelCase	)
																					__UpperCamelCase					:	List[str]             =      unittest.TextTestRunner().run(lowerCAmelCase	)
																					self.assertIs(len(result.failures	)					,     0	)
																except AttributeError:
																					logger.info(F'''{module_identifier} is not a module.'''	)
											else:
																__UpperCamelCase					:	Dict             =      doctest.testfile(str("""..""" / directory / file	)					,     optionflags=doctest.ELLIPSIS	)
																self.assertIs(result.failed					,     0	)






	def 					lowerCamelCase__     (					self		:						Dict	)	->       List[Any]:







						"""simple docstring"""







						__UpperCamelCase					:	str             =      Path("""src/transformers"""	)
						__UpperCamelCase					:	Any             =      """modeling"""
						__UpperCamelCase					:	List[str]             =      [
						    """modeling_ctrl.py""",
						    """modeling_tf_ctrl.py""",
						]
						self.analyze_directory(lowerCAmelCase					,     identifier=lowerCAmelCase					,     ignore_files=lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						Optional[int]	)	->       Tuple:







						"""simple docstring"""







						__UpperCamelCase					:	int             =      Path("""src/transformers"""	)
						__UpperCamelCase					:	Tuple             =      """tokenization"""
						self.analyze_directory(lowerCAmelCase					,     identifier=lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						Union[str, Any]	)	->       Any:







						"""simple docstring"""







						__UpperCamelCase					:	List[Any]             =      Path("""src/transformers"""	)
						__UpperCamelCase					:	str             =      """configuration"""
						self.analyze_directory(lowerCAmelCase					,     identifier=lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						Optional[int]	)	->       Optional[int]:







						"""simple docstring"""







						__UpperCamelCase					:	int             =      Path("""src/transformers"""	)
						__UpperCamelCase					:	Optional[Any]             =      ["""configuration""", """modeling""", """tokenization"""]
						self.analyze_directory(lowerCAmelCase					,     n_identifier=lowerCAmelCase	)






	def 					lowerCamelCase__     (					self		:						List[Any]	)	->       List[str]:







						"""simple docstring"""







						__UpperCamelCase					:	str             =      Path("""docs/source"""	)
						__UpperCamelCase					:	Tuple             =      ["""favicon.ico"""]
						self.analyze_directory(lowerCAmelCase					,     ignore_files=lowerCAmelCase					,     only_modules=lowerCAmelCase	)












# flake8: noqa
# Lint as: python3

from typing import Dict, List, Optional, Type

from .. import config
from ..utils import logging
from .formatting import (
    ArrowFormatter,
    CustomFormatter,
    Formatter,
    PandasFormatter,
    PythonFormatter,
    TensorFormatter,
    format_table,
    query_table,
)
from .np_formatter import NumpyFormatter


a__		     =     logging.get_logger(__name__)

a__		     =     {}
a__		     =     {}
a__		     =     {}





def 				A__ (snake_case   :		type		,	snake_case   :		Optional[str]		,	snake_case   :		Optional[List[str]] = None		,	)     ->						str:
					__UpperCamelCase					:	int             =      aliases if aliases is not None else []
					if format_type in _FORMAT_TYPES:
										logger.warning(
										    F'''Overwriting format type \'{format_type}\' ({_FORMAT_TYPES[format_type].__name__} -> {formatter_cls.__name__})'''				)
					__UpperCamelCase					:	Optional[Any]             =      formatter_cls
					for alias in set(aliases + [format_type]				):
										if alias in _FORMAT_TYPES_ALIASES:
															logger.warning(
															    F'''Overwriting format type alias \'{alias}\' ({_FORMAT_TYPES_ALIASES[alias]} -> {format_type})'''				)
										__UpperCamelCase					:	Optional[int]             =      format_type





def 				A__ (snake_case   :		Exception		,	snake_case   :		Optional[str]		,	snake_case   :		Optional[List[str]] = None				)     ->						Tuple:
					__UpperCamelCase					:	List[Any]             =      aliases if aliases is not None else []
					for alias in set(aliases + [format_type]				):
										__UpperCamelCase					:	Optional[int]             =      unavailable_error


# Here we define all the available formatting functions that can be used by `Dataset.set_format`
_register_formatter(PythonFormatter, None, aliases=['''python'''])
_register_formatter(ArrowFormatter, '''arrow''', aliases=['''pa''', '''pyarrow'''])
_register_formatter(NumpyFormatter, '''numpy''', aliases=['''np'''])
_register_formatter(PandasFormatter, '''pandas''', aliases=['''pd'''])
_register_formatter(CustomFormatter, '''custom''')

if config.TORCH_AVAILABLE:
	from .torch_formatter import TorchFormatter

	_register_formatter(TorchFormatter, '''torch''', aliases=['''pt''', '''pytorch'''])
else:
	a__		     =     ValueError('''PyTorch needs to be installed to be able to return PyTorch tensors.''')
	_register_unavailable_formatter(_torch_error, '''torch''', aliases=['''pt''', '''pytorch'''])

if config.TF_AVAILABLE:
	from .tf_formatter import TFFormatter

	_register_formatter(TFFormatter, '''tensorflow''', aliases=['''tf'''])
else:
	a__		     =     ValueError('''Tensorflow needs to be installed to be able to return Tensorflow tensors.''')
	_register_unavailable_formatter(_tf_error, '''tensorflow''', aliases=['''tf'''])

if config.JAX_AVAILABLE:
	from .jax_formatter import JaxFormatter

	_register_formatter(JaxFormatter, '''jax''', aliases=[])
else:
	a__		     =     ValueError('''JAX needs to be installed to be able to return JAX arrays.''')
	_register_unavailable_formatter(_jax_error, '''jax''', aliases=[])





def 				A__ (snake_case   :		Optional[str]				)     ->						Optional[str]:
					if format_type in _FORMAT_TYPES_ALIASES:
										return _FORMAT_TYPES_ALIASES[format_type]
					else:
										return format_type







def 				A__ (snake_case   :		Optional[str]		,	**snake_case   :		List[str]				)     ->						Formatter:
					__UpperCamelCase					:	int             =      get_format_type_from_alias(snake_case				)
					if format_type in _FORMAT_TYPES:
										return _FORMAT_TYPES[format_type](**snake_case				)
					if format_type in _FORMAT_TYPES_ALIASES_UNAVAILABLE:
										raise _FORMAT_TYPES_ALIASES_UNAVAILABLE[format_type]
					else:
										raise ValueError(
										    F'''Return type should be None or selected in {list(type for type in _FORMAT_TYPES.keys() if type != None				)}, but got \'{format_type}\''''				)






