


'''simple docstring'''



import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
__lowercase	:						Tuple       =	sys.version_info >= (3, 10)






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   int=None						,      _SCREAMING_SNAKE_CASE      :   Optional[Any]=None   ):
					return field(default_factory=lambda: default						,      metadata=_SCREAMING_SNAKE_CASE   )





@dataclass
class 							__UpperCamelCase				:
	A_				=    42
	A_				=    42
	A_				=    42
	A_				=    42





@dataclass
class 							__UpperCamelCase				:
	A_				=    42
	A_				=    field(default="toto"		,      metadata={"help": "help message"}					)





@dataclass
class 							__UpperCamelCase				:
	A_				=    False
	A_				=    True
	A_				=    None





class 							__UpperCamelCase				(		lowerCAmelCase_					):
	A_				=    "titi"
	A_				=    "toto"





class 							__UpperCamelCase				(		lowerCAmelCase_					):
	A_				=    "titi"
	A_				=    "toto"
	A_				=    42





@dataclass
class 							__UpperCamelCase				:
	A_				=    "toto"




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Any					    =  BasicEnum(self.foo							)





@dataclass
class 							__UpperCamelCase				:
	A_				=    "toto"




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  MixedTypeEnum(self.foo							)





@dataclass
class 							__UpperCamelCase				:
	A_				=    None
	A_				=    field(default=lowerCAmelCase_		,      metadata={"help": "help message"}					)
	A_				=    None
	A_				=    list_field(default=[]					)
	A_				=    list_field(default=[]					)





@dataclass
class 							__UpperCamelCase				:
	A_				=    list_field(default=[]					)
	A_				=    list_field(default=[1, 2, 3]					)
	A_				=    list_field(default=["Hallo", "Bonjour", "Hello"]					)
	A_				=    list_field(default=[0.1, 0.2, 0.3]					)





@dataclass
class 							__UpperCamelCase				:
	A_				=    field()
	A_				=    field()
	A_				=    field()




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[str]					    =  BasicEnum(self.required_enum							)





@dataclass
class 							__UpperCamelCase				:
	A_				=    42
	A_				=    field()
	A_				=    None
	A_				=    field(default="toto"		,      metadata={"help": "help message"}					)
	A_				=    list_field(default=["Hallo", "Bonjour", "Hello"]					)


if is_python_no_less_than_3_10:





	@dataclass
	class 							__UpperCamelCase				:
		A_				=    False
		A_				=    True
		A_				=    None





	@dataclass
	class 							__UpperCamelCase				:
		A_				=    None
		A_				=    field(default=lowerCAmelCase_		,      metadata={"help": "help message"}					)
		A_				=    None
		A_				=    list_field(default=[]					)
		A_				=    list_field(default=[]					)





class 							__UpperCamelCase				(		unittest.TestCase					):




	def       __UpperCAmelCase							(   self						,				__a						,				__a							):

						'''simple docstring'''





						self.assertEqual(len(a._actions							)						,				len(b._actions							)							)
						for x, y in zip(a._actions						,				b._actions							):
											__a			:       Dict					    =  {k: v for k, v in vars(__a							).items() if k != 'container'}
											__a			:       Tuple					    =  {k: v for k, v in vars(__a							).items() if k != 'container'}

											# Choices with mixed type have custom function as "type"
											# So we need to compare results directly for equality
											if xx.get('choices'						,				__a							) and yy.get('choices'						,				__a							):
																for expected_choice in yy["choices"] + xx["choices"]:
																					self.assertEqual(xx['type'](__a							)						,				yy['type'](__a							)							)
																del xx["type"], yy["type"]

											self.assertEqual(__a						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[Any]					    =  HfArgumentParser(__a							)

						__a			:       List[str]					    =  argparse.ArgumentParser()
						expected.add_argument('--foo'						,				type=__a						,				required=__a							)
						expected.add_argument('--bar'						,				type=__a						,				required=__a							)
						expected.add_argument('--baz'						,				type=__a						,				required=__a							)
						expected.add_argument('--flag'						,				type=__a						,				default=__a						,				const=__a						,				nargs='?'							)
						self.argparsersEqual(__a						,				__a							)

						__a			:       Optional[int]					    =  ['--foo', '1', '--baz', 'quux', '--bar', '0.5']
						((__a)    ,				)			:       Any					    =  parser.parse_args_into_dataclasses(__a						,				look_for_args_file=__a							)
						self.assertFalse(example.flag							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       str					    =  HfArgumentParser(__a							)

						__a			:       Union[str, Any]					    =  argparse.ArgumentParser()
						expected.add_argument('--foo'						,				default=42						,				type=__a							)
						expected.add_argument('--baz'						,				default='toto'						,				type=__a						,				help='help message'							)
						self.argparsersEqual(__a						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  argparse.ArgumentParser()
						expected.add_argument('--foo'						,				type=__a						,				default=__a						,				const=__a						,				nargs='?'							)
						expected.add_argument('--baz'						,				type=__a						,				default=__a						,				const=__a						,				nargs='?'							)
						# A boolean no_* argument always has to come after its "default: True" regular counter-part
						# and its default must be set to False
						expected.add_argument('--no_baz'						,				action='store_false'						,				default=__a						,				dest='baz'							)
						expected.add_argument('--opt'						,				type=__a						,				default=__a							)

						__a			:       str					    =  [WithDefaultBoolExample]
						if is_python_no_less_than_3_10:
											dataclass_types.append(__a							)

						for dataclass_type in dataclass_types:
											__a			:       Dict					    =  HfArgumentParser(__a							)
											self.argparsersEqual(__a						,				__a							)

											__a			:       List[Any]					    =  parser.parse_args([]							)
											self.assertEqual(__a						,				Namespace(foo=__a						,				baz=__a						,				opt=__a							)							)

											__a			:       Tuple					    =  parser.parse_args(['--foo', '--no_baz']							)
											self.assertEqual(__a						,				Namespace(foo=__a						,				baz=__a						,				opt=__a							)							)

											__a			:       List[Any]					    =  parser.parse_args(['--foo', '--baz']							)
											self.assertEqual(__a						,				Namespace(foo=__a						,				baz=__a						,				opt=__a							)							)

											__a			:       int					    =  parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']							)
											self.assertEqual(__a						,				Namespace(foo=__a						,				baz=__a						,				opt=__a							)							)

											__a			:       Optional[int]					    =  parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']							)
											self.assertEqual(__a						,				Namespace(foo=__a						,				baz=__a						,				opt=__a							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Tuple					    =  HfArgumentParser(__a							)

						__a			:       str					    =  argparse.ArgumentParser()
						expected.add_argument(
						    '--foo'						,				default='toto'						,				choices=['titi', 'toto', 42]						,				type=make_choice_type_function(['titi', 'toto', 42]							)						,				)
						self.argparsersEqual(__a						,				__a							)

						__a			:       Union[str, Any]					    =  parser.parse_args([]							)
						self.assertEqual(args.foo						,				'toto'							)
						__a			:       Tuple					    =  parser.parse_args_into_dataclasses([]							)[0]
						self.assertEqual(enum_ex.foo						,				MixedTypeEnum.toto							)

						__a			:       List[str]					    =  parser.parse_args(['--foo', 'titi']							)
						self.assertEqual(args.foo						,				'titi'							)
						__a			:       Tuple					    =  parser.parse_args_into_dataclasses(['--foo', 'titi']							)[0]
						self.assertEqual(enum_ex.foo						,				MixedTypeEnum.titi							)

						__a			:       Optional[int]					    =  parser.parse_args(['--foo', '42']							)
						self.assertEqual(args.foo						,				42							)
						__a			:       Any					    =  parser.parse_args_into_dataclasses(['--foo', '42']							)[0]
						self.assertEqual(enum_ex.foo						,				MixedTypeEnum.fourtytwo							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						@dataclass
						class 							__UpperCamelCase				:
							A_				=    "toto"



						__a			:       Dict					    =  HfArgumentParser(__a							)

						__a			:       List[str]					    =  argparse.ArgumentParser()
						expected.add_argument(
						    '--foo'						,				default='toto'						,				choices=('titi', 'toto', 42)						,				type=make_choice_type_function(['titi', 'toto', 42]							)						,				)
						self.argparsersEqual(__a						,				__a							)

						__a			:       str					    =  parser.parse_args([]							)
						self.assertEqual(args.foo						,				'toto'							)

						__a			:       Optional[int]					    =  parser.parse_args(['--foo', 'titi']							)
						self.assertEqual(args.foo						,				'titi'							)

						__a			:       Any					    =  parser.parse_args(['--foo', '42']							)
						self.assertEqual(args.foo						,				42							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[Any]					    =  HfArgumentParser(__a							)

						__a			:       Any					    =  argparse.ArgumentParser()
						expected.add_argument('--foo_int'						,				nargs='+'						,				default=[]						,				type=__a							)
						expected.add_argument('--bar_int'						,				nargs='+'						,				default=[1, 2, 3]						,				type=__a							)
						expected.add_argument('--foo_str'						,				nargs='+'						,				default=['Hallo', 'Bonjour', 'Hello']						,				type=__a							)
						expected.add_argument('--foo_float'						,				nargs='+'						,				default=[0.1, 0.2, 0.3]						,				type=__a							)

						self.argparsersEqual(__a						,				__a							)

						__a			:       Union[str, Any]					    =  parser.parse_args([]							)
						self.assertEqual(
						    __a						,				Namespace(foo_int=[]						,				bar_int=[1, 2, 3]						,				foo_str=['Hallo', 'Bonjour', 'Hello']						,				foo_float=[0.1, 0.2, 0.3]							)						,				)

						__a			:       Tuple					    =  parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split()							)
						self.assertEqual(__a						,				Namespace(foo_int=[1]						,				bar_int=[2, 3]						,				foo_str=['a', 'b', 'c']						,				foo_float=[0.1, 0.7]							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       int					    =  argparse.ArgumentParser()
						expected.add_argument('--foo'						,				default=__a						,				type=__a							)
						expected.add_argument('--bar'						,				default=__a						,				type=__a						,				help='help message'							)
						expected.add_argument('--baz'						,				default=__a						,				type=__a							)
						expected.add_argument('--ces'						,				nargs='+'						,				default=[]						,				type=__a							)
						expected.add_argument('--des'						,				nargs='+'						,				default=[]						,				type=__a							)

						__a			:       Any					    =  [OptionalExample]
						if is_python_no_less_than_3_10:
											dataclass_types.append(__a							)

						for dataclass_type in dataclass_types:
											__a			:       Tuple					    =  HfArgumentParser(__a							)

											self.argparsersEqual(__a						,				__a							)

											__a			:       Tuple					    =  parser.parse_args([]							)
											self.assertEqual(__a						,				Namespace(foo=__a						,				bar=__a						,				baz=__a						,				ces=[]						,				des=[]							)							)

											__a			:       Tuple					    =  parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split()							)
											self.assertEqual(__a						,				Namespace(foo=12						,				bar=3.14						,				baz='42'						,				ces=['a', 'b', 'c']						,				des=[1, 2, 3]							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Optional[int]					    =  HfArgumentParser(__a							)

						__a			:       str					    =  argparse.ArgumentParser()
						expected.add_argument('--required_list'						,				nargs='+'						,				type=__a						,				required=__a							)
						expected.add_argument('--required_str'						,				type=__a						,				required=__a							)
						expected.add_argument(
						    '--required_enum'						,				type=make_choice_type_function(['titi', 'toto']							)						,				choices=['titi', 'toto']						,				required=__a						,				)
						self.argparsersEqual(__a						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       str					    =  HfArgumentParser(__a							)

						__a			:       Optional[Any]					    =  argparse.ArgumentParser()
						expected.add_argument('--foo'						,				type=__a						,				required=__a							)
						expected.add_argument(
						    '--required_enum'						,				type=make_choice_type_function(['titi', 'toto']							)						,				choices=['titi', 'toto']						,				required=__a						,				)
						expected.add_argument('--opt'						,				type=__a						,				default=__a							)
						expected.add_argument('--baz'						,				default='toto'						,				type=__a						,				help='help message'							)
						expected.add_argument('--foo_str'						,				nargs='+'						,				default=['Hallo', 'Bonjour', 'Hello']						,				type=__a							)
						self.argparsersEqual(__a						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Union[str, Any]					    =  HfArgumentParser(__a							)

						__a			:       Optional[Any]					    =  {
						    'foo': 12,
						    'bar': 3.14,
						    'baz': '42',
						    'flag': True,
						}

						__a			:       Optional[Any]					    =  parser.parse_dict(__a							)[0]
						__a			:       str					    =  BasicExample(**__a							)
						self.assertEqual(__a						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  HfArgumentParser(__a							)

						__a			:       str					    =  {
						    'foo': 12,
						    'bar': 3.14,
						    'baz': '42',
						    'flag': True,
						    'extra': 42,
						}

						self.assertRaises(__a						,				parser.parse_dict						,				__a						,				allow_extra_keys=__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  HfArgumentParser(__a							)

						__a			:       Optional[int]					    =  {
						    'foo': 12,
						    'bar': 3.14,
						    'baz': '42',
						    'flag': True,
						}
						with tempfile.TemporaryDirectory() as tmp_dir:
											__a			:       List[str]					    =  os.path.join(__a						,				'temp_json'							)
											os.mkdir(__a							)
											with open(temp_local_path + '.json'						,				'w+'							) as f:
																json.dump(__a						,				__a							)
											__a			:       Tuple					    =  parser.parse_yaml_file(Path(temp_local_path + '.json'							)							)[0]

						__a			:       str					    =  BasicExample(**__a							)
						self.assertEqual(__a						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[str]					    =  HfArgumentParser(__a							)

						__a			:       Union[str, Any]					    =  {
						    'foo': 12,
						    'bar': 3.14,
						    'baz': '42',
						    'flag': True,
						}
						with tempfile.TemporaryDirectory() as tmp_dir:
											__a			:       List[str]					    =  os.path.join(__a						,				'temp_yaml'							)
											os.mkdir(__a							)
											with open(temp_local_path + '.yaml'						,				'w+'							) as f:
																yaml.dump(__a						,				__a							)
											__a			:       List[str]					    =  parser.parse_yaml_file(Path(temp_local_path + '.yaml'							)							)[0]
						__a			:       Dict					    =  BasicExample(**__a							)
						self.assertEqual(__a						,				__a							)





	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Tuple					    =  HfArgumentParser(__a							)
						self.assertIsNotNone(__a							)






import argparse
from collections import defaultdict

import yaml


A_       : List[str]         =			'docs/source/en/_toctree.yml'

def 						UpperCamelCase					(lowercase_: Optional[int]					)     ->      List[str]:
	A__							:    Dict        =		defaultdict(lowercase_					)
	A__							:    Optional[int]        =		[]
	A__							:    Union[str, Any]        =		[]
	for doc in doc_list:
		if "local" in doc:
			counts[doc["local"]] += 1

		if doc["title"].lower() == "overview":
			overview_doc.append({"""local""": doc["""local"""], """title""": doc["""title"""]}					)
		else:
			new_doc_list.append(lowercase_					)

	A__							:    Optional[int]        =		new_doc_list
	A__							:    Optional[int]        =		[key for key, value in counts.items() if value > 1]

	A__							:    Optional[Any]        =		[]
	for duplicate_key in duplicates:
		A__							:    List[Any]        =		list({doc["""title"""] for doc in doc_list if doc["""local"""] == duplicate_key}					)
		if len(lowercase_					) > 1:
			raise ValueError(
			    f"""{duplicate_key} is present several times in the documentation table of content at """
			    """`docs/source/en/_toctree.yml` with different *Title* values. Choose one of those and remove the """
			    """others."""					)
		# Only add this once
		new_doc.append({"""local""": duplicate_key, """title""": titles[0]}					)

	# Add none duplicate-keys
	new_doc.extend([doc for doc in doc_list if """local""" not in counts or counts[doc["""local"""]] == 1]					)
	A__							:    Dict        =		sorted(lowercase_    ,      key=lambda lowercase_					: s["title"].lower()					)

	# "overview" gets special treatment and is always first
	if len(lowercase_					) > 1:
		raise ValueError("""{doc_list} has two 'overview' docs which is not allowed."""					)

	overview_doc.extend(lowercase_					)

	# Sort
	return overview_doc

def 						UpperCamelCase					(lowercase_: Tuple=False					)     ->      List[Any]:
	with open(lowercase_    ,      encoding="""utf-8"""					) as f:
		A__							:    Dict        =		yaml.safe_load(f.read()					)

	# Get to the API doc
	A__							:    List[Any]        =		0
	while content[api_idx]["title"] != "API":
		api_idx += 1
	A__							:    Union[str, Any]        =		content[api_idx]["""sections"""]

	# Then to the model doc
	A__							:    Dict        =		0
	while api_doc[scheduler_idx]["title"] != "Schedulers":
		scheduler_idx += 1

	A__							:    List[Any]        =		api_doc[scheduler_idx]["""sections"""]
	A__							:    Union[str, Any]        =		clean_doc_toc(lowercase_					)

	A__							:    Optional[int]        =		False
	if new_scheduler_doc != scheduler_doc:
		A__							:    List[Any]        =		True
		if overwrite:
			A__							:    Optional[int]        =		new_scheduler_doc

	if diff:
		if overwrite:
			A__							:    Tuple        =		api_doc
			with open(lowercase_    ,      """w"""    ,      encoding="""utf-8"""					) as f:
				f.write(yaml.dump(lowercase_    ,      allow_unicode=lowercase_					)					)
		else:
			raise ValueError(
			    """The model doc part of the table of content is not properly sorted, run `make style` to fix this."""					)

def 						UpperCamelCase					(lowercase_: Dict=False					)     ->      Optional[Any]:
	with open(lowercase_    ,      encoding="""utf-8"""					) as f:
		A__							:    int        =		yaml.safe_load(f.read()					)

	# Get to the API doc
	A__							:    Optional[Any]        =		0
	while content[api_idx]["title"] != "API":
		api_idx += 1
	A__							:    List[str]        =		content[api_idx]["""sections"""]

	# Then to the model doc
	A__							:    List[Any]        =		0
	while api_doc[pipeline_idx]["title"] != "Pipelines":
		pipeline_idx += 1

	A__							:    Dict        =		False
	A__							:    Tuple        =		api_doc[pipeline_idx]["""sections"""]
	A__							:    Tuple        =		[]

	# sort sub pipeline docs
	for pipeline_doc in pipeline_docs:
		if "section" in pipeline_doc:
			A__							:    List[Any]        =		pipeline_doc["""section"""]
			A__							:    Dict        =		clean_doc_toc(lowercase_					)
			if overwrite:
				A__							:    Optional[Any]        =		new_sub_pipeline_doc
		new_pipeline_docs.append(lowercase_					)

	# sort overall pipeline doc
	A__							:    Optional[int]        =		clean_doc_toc(lowercase_					)

	if new_pipeline_docs != pipeline_docs:
		A__							:    int        =		True
		if overwrite:
			A__							:    List[Any]        =		new_pipeline_docs

	if diff:
		if overwrite:
			A__							:    Union[str, Any]        =		api_doc
			with open(lowercase_    ,      """w"""    ,      encoding="""utf-8"""					) as f:
				f.write(yaml.dump(lowercase_    ,      allow_unicode=lowercase_					)					)
		else:
			raise ValueError(
			    """The model doc part of the table of content is not properly sorted, run `make style` to fix this."""					)


if __name__ == "__main__":
	A_       : str         =			argparse.ArgumentParser()
	parser.add_argument('--fix_and_overwrite', action='store_true', help='Whether to fix inconsistencies.')
	A_       : str         =			parser.parse_args()

	check_scheduler_doc(args.fix_and_overwrite)
	check_pipeline_doc(args.fix_and_overwrite)



