



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_						=       sys.version_info >= (3, 10)



def __lowerCAmelCase	(       SCREAMING_SNAKE_CASE_=None  ,					SCREAMING_SNAKE_CASE_=None					):
			return field(default_factory=lambda: default  ,					metadata=SCREAMING_SNAKE_CASE_					)
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   int
				UpperCamelCase__			:   float
				UpperCamelCase__			:   str
				UpperCamelCase__			:   bool
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   int       						=4_2
				UpperCamelCase__			:   str       						=field(default="""toto"""      ,		metadata={"""help""": """help message"""})
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   bool       						=False
				UpperCamelCase__			:   bool       						=True
				UpperCamelCase__			:   Optional[bool]       						=None
class 			_snake_case     (   lowercase__):
				UpperCamelCase__			:   int       						="""titi"""
				UpperCamelCase__			:   List[Any]       						="""toto"""
class 			_snake_case     (   lowercase__):
				UpperCamelCase__			:   Dict       						="""titi"""
				UpperCamelCase__			:   Any       						="""toto"""
				UpperCamelCase__			:   Optional[int]       						=4_2
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   BasicEnum       						="toto"




				def 							A__ (  self   :  Union[str, Any]  ):
							lowercase__   					=			BasicEnum(self.foo  )
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   MixedTypeEnum       						="toto"




				def 							A__ (  self   :  int  ):
							lowercase__   					=			MixedTypeEnum(self.foo  )
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   Optional[int]       						=None
				UpperCamelCase__			:   Optional[float]       						=field(default=lowercase__      ,		metadata={"""help""": """help message"""})
				UpperCamelCase__			:   Optional[str]       						=None
				UpperCamelCase__			:   Optional[List[str]]       						=list_field(default=[])
				UpperCamelCase__			:   Optional[List[int]]       						=list_field(default=[])
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   List[int]       						=list_field(default=[])
				UpperCamelCase__			:   List[int]       						=list_field(default=[1, 2, 3])
				UpperCamelCase__			:   List[str]       						=list_field(default=["""Hallo""", """Bonjour""", """Hello"""])
				UpperCamelCase__			:   List[float]       						=list_field(default=[0.1, 0.2, 0.3])
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   List[int]       						=field()
				UpperCamelCase__			:   str       						=field()
				UpperCamelCase__			:   BasicEnum       						=field()




				def 							A__ (  self   :  Optional[int]  ):
							lowercase__   					=			BasicEnum(self.required_enum  )
@dataclass
class 			_snake_case     :
				UpperCamelCase__			:   int
				UpperCamelCase__			:   "BasicEnum"       						=field()
				UpperCamelCase__			:   "Optional[bool]"       						=None
				UpperCamelCase__			:   "str"       						=field(default="""toto"""      ,		metadata={"""help""": """help message"""})
				UpperCamelCase__			:   "List[str]"       						=list_field(default=["""Hallo""", """Bonjour""", """Hello"""])


if is_python_no_less_than_3_10:
							@dataclass
							class 			_snake_case     :
											UpperCamelCase__			:   bool       						=False
											UpperCamelCase__			:   bool       						=True
											UpperCamelCase__			:   bool | None       						=None
							@dataclass
							class 			_snake_case     :
											UpperCamelCase__			:   int | None       						=None
											UpperCamelCase__			:   float | None       						=field(default=lowercase__      ,		metadata={"""help""": """help message"""})
											UpperCamelCase__			:   str | None       						=None
											UpperCamelCase__			:   list[str] | None       						=list_field(default=[])
											UpperCamelCase__			:   list[int] | None       						=list_field(default=[])




class 			_snake_case     (   unittest.TestCase):




				def 							A__ (  self   :  Optional[int],   __lowercase   :  argparse.ArgumentParser,   __lowercase   :  argparse.ArgumentParser  ):
							self.assertEqual(len(a._actions  ),   len(b._actions  )  )
							for x, y in zip(a._actions,   b._actions  ):
										lowercase__   					=			{k: v for k, v in vars(__lowercase  ).items() if k != "container"}
										lowercase__   					=			{k: v for k, v in vars(__lowercase  ).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",   __lowercase  ) and yy.get("choices",   __lowercase  ):
													for expected_choice in yy["choices"] + xx["choices"]:
																self.assertEqual(xx["type"](__lowercase  ),   yy["type"](__lowercase  )  )
													del xx["type"], yy["type"]

										self.assertEqual(__lowercase,   __lowercase  )




				def 							A__ (  self   :  int  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument("--foo",   type=__lowercase,   required=__lowercase  )
							expected.add_argument("--bar",   type=__lowercase,   required=__lowercase  )
							expected.add_argument("--baz",   type=__lowercase,   required=__lowercase  )
							expected.add_argument("--flag",   type=__lowercase,   default=__lowercase,   const=__lowercase,   nargs="?"  )
							self.argparsersEqual(__lowercase,   __lowercase  )

							lowercase__   					=			["--foo", "1", "--baz", "quux", "--bar", "0.5"]
							((lowercase__)					,    )   					=			parser.parse_args_into_dataclasses(__lowercase,   look_for_args_file=__lowercase  )
							self.assertFalse(example.flag  )




				def 							A__ (  self   :  List[Any]  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument("--foo",   default=42,   type=__lowercase  )
							expected.add_argument("--baz",   default="toto",   type=__lowercase,   help="help message"  )
							self.argparsersEqual(__lowercase,   __lowercase  )




				def 							A__ (  self   :  List[Any]  ):
							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument("--foo",   type=__lowercase,   default=__lowercase,   const=__lowercase,   nargs="?"  )
							expected.add_argument("--baz",   type=__lowercase,   default=__lowercase,   const=__lowercase,   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=__lowercase,   dest="baz"  )
							expected.add_argument("--opt",   type=__lowercase,   default=__lowercase  )

							lowercase__   					=			[WithDefaultBoolExample]
							if is_python_no_less_than_3_10:
										dataclass_types.append(__lowercase  )

							for dataclass_type in dataclass_types:
										lowercase__   					=			HfArgumentParser(__lowercase  )
										self.argparsersEqual(__lowercase,   __lowercase  )

										lowercase__   					=			parser.parse_args([]  )
										self.assertEqual(__lowercase,   Namespace(foo=__lowercase,   baz=__lowercase,   opt=__lowercase  )  )

										lowercase__   					=			parser.parse_args(["--foo", "--no_baz"]  )
										self.assertEqual(__lowercase,   Namespace(foo=__lowercase,   baz=__lowercase,   opt=__lowercase  )  )

										lowercase__   					=			parser.parse_args(["--foo", "--baz"]  )
										self.assertEqual(__lowercase,   Namespace(foo=__lowercase,   baz=__lowercase,   opt=__lowercase  )  )

										lowercase__   					=			parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]  )
										self.assertEqual(__lowercase,   Namespace(foo=__lowercase,   baz=__lowercase,   opt=__lowercase  )  )

										lowercase__   					=			parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]  )
										self.assertEqual(__lowercase,   Namespace(foo=__lowercase,   baz=__lowercase,   opt=__lowercase  )  )




				def 							A__ (  self   :  List[Any]  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument(
							    "--foo",   default="toto",   choices=["titi", "toto", 42],   type=make_choice_type_function(["titi", "toto", 42]  ),   )
							self.argparsersEqual(__lowercase,   __lowercase  )

							lowercase__   					=			parser.parse_args([]  )
							self.assertEqual(args.foo,   "toto"  )
							lowercase__   					=			parser.parse_args_into_dataclasses([]  )[0]
							self.assertEqual(enum_ex.foo,   MixedTypeEnum.toto  )

							lowercase__   					=			parser.parse_args(["--foo", "titi"]  )
							self.assertEqual(args.foo,   "titi"  )
							lowercase__   					=			parser.parse_args_into_dataclasses(["--foo", "titi"]  )[0]
							self.assertEqual(enum_ex.foo,   MixedTypeEnum.titi  )

							lowercase__   					=			parser.parse_args(["--foo", "42"]  )
							self.assertEqual(args.foo,   42  )
							lowercase__   					=			parser.parse_args_into_dataclasses(["--foo", "42"]  )[0]
							self.assertEqual(enum_ex.foo,   MixedTypeEnum.fourtytwo  )




				def 							A__ (  self   :  int  ):
							@dataclass
							class 			_snake_case     :
											UpperCamelCase__			:   Literal["titi", "toto", 4_2]       						="toto"
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument(
							    "--foo",   default="toto",   choices=("titi", "toto", 42),   type=make_choice_type_function(["titi", "toto", 42]  ),   )
							self.argparsersEqual(__lowercase,   __lowercase  )

							lowercase__   					=			parser.parse_args([]  )
							self.assertEqual(args.foo,   "toto"  )

							lowercase__   					=			parser.parse_args(["--foo", "titi"]  )
							self.assertEqual(args.foo,   "titi"  )

							lowercase__   					=			parser.parse_args(["--foo", "42"]  )
							self.assertEqual(args.foo,   42  )




				def 							A__ (  self   :  List[Any]  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

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

							self.argparsersEqual(__lowercase,   __lowercase  )

							lowercase__   					=			parser.parse_args([]  )
							self.assertEqual(
							    __lowercase,   Namespace(foo_int=[],   bar_int=[1, 2, 3],   foo_str=["Hallo", "Bonjour", "Hello"],   foo_float=[0.1, 0.2, 0.3]  ),   )

							lowercase__   					=			parser.parse_args("--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7".split()  )
							self.assertEqual(__lowercase,   Namespace(foo_int=[1],   bar_int=[2, 3],   foo_str=["a", "b", "c"],   foo_float=[0.1, 0.7]  )  )




				def 							A__ (  self   :  str  ):
							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument("--foo",   default=__lowercase,   type=__lowercase  )
							expected.add_argument("--bar",   default=__lowercase,   type=__lowercase,   help="help message"  )
							expected.add_argument("--baz",   default=__lowercase,   type=__lowercase  )
							expected.add_argument("--ces",   nargs="+",   default=[],   type=__lowercase  )
							expected.add_argument("--des",   nargs="+",   default=[],   type=__lowercase  )

							lowercase__   					=			[OptionalExample]
							if is_python_no_less_than_3_10:
										dataclass_types.append(__lowercase  )

							for dataclass_type in dataclass_types:
										lowercase__   					=			HfArgumentParser(__lowercase  )

										self.argparsersEqual(__lowercase,   __lowercase  )

										lowercase__   					=			parser.parse_args([]  )
										self.assertEqual(__lowercase,   Namespace(foo=__lowercase,   bar=__lowercase,   baz=__lowercase,   ces=[],   des=[]  )  )

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




				def 							A__ (  self   :  Tuple  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			argparse.ArgumentParser()
							expected.add_argument("--required_list",   nargs="+",   type=__lowercase,   required=__lowercase  )
							expected.add_argument("--required_str",   type=__lowercase,   required=__lowercase  )
							expected.add_argument(
							    "--required_enum",   type=make_choice_type_function(["titi", "toto"]  ),   choices=["titi", "toto"],   required=__lowercase,   )
							self.argparsersEqual(__lowercase,   __lowercase  )




				def 							A__ (  self   :  Dict  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

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




				def 							A__ (  self   :  Any  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			{
							    "foo": 12,
							    "bar": 3.14,
							    "baz": "42",
							    "flag": True,
							}

							lowercase__   					=			parser.parse_dict(__lowercase  )[0]
							lowercase__   					=			BasicExample(**__lowercase  )
							self.assertEqual(__lowercase,   __lowercase  )




				def 							A__ (  self   :  Optional[Any]  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			{
							    "foo": 12,
							    "bar": 3.14,
							    "baz": "42",
							    "flag": True,
							    "extra": 42,
							}

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




				def 							A__ (  self   :  Optional[Any]  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

							lowercase__   					=			{
							    "foo": 12,
							    "bar": 3.14,
							    "baz": "42",
							    "flag": True,
							}
							with tempfile.TemporaryDirectory() as tmp_dir:
										lowercase__   					=			os.path.join(__lowercase,   "temp_json"  )
										os.mkdir(__lowercase  )
										with open(temp_local_path + ".json",   "w+"  ) as f:
													json.dump(__lowercase,   __lowercase  )
										lowercase__   					=			parser.parse_yaml_file(Path(temp_local_path + ".json"  )  )[0]

							lowercase__   					=			BasicExample(**__lowercase  )
							self.assertEqual(__lowercase,   __lowercase  )




				def 							A__ (  self   :  Tuple  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )

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




				def 							A__ (  self   :  str  ):
							lowercase__   					=			HfArgumentParser(__lowercase  )
							self.assertIsNotNone(__lowercase  )









import os
from collections.abc import Iterator



def __lowerCAmelCase	(       SCREAMING_SNAKE_CASE_ = "."					):
			for dir_path, dir_names, filenames in os.walk(SCREAMING_SNAKE_CASE_					):
						lowercase__   					=			[d for d in dir_names if d != "scripts" and d[0] not in "._"]
						for filename in filenames:
									if filename == "__init__.py":
												continue
									if os.path.splitext(SCREAMING_SNAKE_CASE_					)[1] in (".py", ".ipynb"):
												yield os.path.join(SCREAMING_SNAKE_CASE_  ,					SCREAMING_SNAKE_CASE_					).lstrip("./"					)



def __lowerCAmelCase	(       SCREAMING_SNAKE_CASE_					):
			return f'''{i * "  "}*''' if i else "\n##"



def __lowerCAmelCase	(       SCREAMING_SNAKE_CASE_  ,					SCREAMING_SNAKE_CASE_					):
			lowercase__   					=			old_path.split(os.sep					)
			for i, new_part in enumerate(new_path.split(os.sep					)					):
						if (i + 1 > len(SCREAMING_SNAKE_CASE_					) or old_parts[i] != new_part) and new_part:
									print(f'''{md_prefix(SCREAMING_SNAKE_CASE_					)} {new_part.replace("_"  ,					" "					).title()}'''					)
			return new_path



def __lowerCAmelCase	(       SCREAMING_SNAKE_CASE_ = "."					):
			lowercase__   					=			""
			for filepath in sorted(good_file_paths(SCREAMING_SNAKE_CASE_					)					):
						lowercase__					,    lowercase__   					=			os.path.split(SCREAMING_SNAKE_CASE_					)
						if filepath != old_path:
									lowercase__   					=			print_path(SCREAMING_SNAKE_CASE_  ,					SCREAMING_SNAKE_CASE_					)
						lowercase__   					=			(filepath.count(os.sep					) + 1) if filepath else 0
						lowercase__   					=			f'''{filepath}/{filename}'''.replace(" "  ,					"%20"					)
						lowercase__   					=			os.path.splitext(filename.replace("_"  ,					" "					).title()					)[0]
						print(f'''{md_prefix(SCREAMING_SNAKE_CASE_					)} [{filename}]({url})'''					)


if __name__ == "__main__":
							print_directory_md(""".""")




