


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
snake_case_						:			Optional[int]													=							sys.version_info >= (3, 10)







def 						lowerCamelCase(   a__=None	,a__=None):
				return field(default_factory=lambda: default	,metadata=a__)

@dataclass
class 						A__							:
						UpperCAmelCase             =						42
						UpperCAmelCase             =						42
						UpperCAmelCase             =						42
						UpperCAmelCase             =						42

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

@dataclass
class 						A__							:
						UpperCAmelCase             =						False
						UpperCAmelCase             =						True
						UpperCAmelCase             =						None

class 						A__							(		UpperCamelCase__  ):
						UpperCAmelCase             =						"titi"
						UpperCAmelCase             =						"toto"

class 						A__							(		UpperCamelCase__  ):
						UpperCAmelCase             =						"titi"
						UpperCAmelCase             =						"toto"
						UpperCAmelCase             =						42

@dataclass
class 						A__							:
						UpperCAmelCase             =						"toto"




						def 							__UpperCamelCase				(       self					:      Optional[Any]  )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =BasicEnum(self.foo  )

@dataclass
class 						A__							:
						UpperCAmelCase             =						"toto"




						def 							__UpperCamelCase				(       self					:      int  )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =MixedTypeEnum(self.foo  )

@dataclass
class 						A__							:
						UpperCAmelCase             =						None
						UpperCAmelCase             =						field(default=UpperCamelCase__   ,     metadata={"help": "help message"}  )
						UpperCAmelCase             =						None
						UpperCAmelCase             =						list_field(default=[]  )
						UpperCAmelCase             =						list_field(default=[]  )

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

@dataclass
class 						A__							:
						UpperCAmelCase             =						field()
						UpperCAmelCase             =						field()
						UpperCAmelCase             =						field()




						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     Optional[Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =BasicEnum(self.required_enum  )

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


if is_python_no_less_than_3_10:

			@dataclass
			class 						A__							:
									UpperCAmelCase             =						False
									UpperCAmelCase             =						True
									UpperCAmelCase             =						None

			@dataclass
			class 						A__							:
									UpperCAmelCase             =						None
									UpperCAmelCase             =						field(default=UpperCamelCase__   ,     metadata={"help": "help message"}  )
									UpperCAmelCase             =						None
									UpperCAmelCase             =						list_field(default=[]  )
									UpperCAmelCase             =						list_field(default=[]  )


class 						A__							(		unittest.TestCase  ):




						def 							__UpperCamelCase				(       self					:      Optional[int]				,    _a					:      argparse.ArgumentParser				,    _a					:      argparse.ArgumentParser  )							->     Dict:


										"""simple docstring"""





										self.assertEqual(len(a._actions  )				,    len(b._actions  )  )
										for x, y in zip(a._actions				,    b._actions  ):
														_SCREAMING_SNAKE_CASE			  ={k: v for k, v in vars(_a  ).items() if k != '''container'''}
														_SCREAMING_SNAKE_CASE			  ={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					:      Dict  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  =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  )

										_SCREAMING_SNAKE_CASE			  =['''--foo''', '''1''', '''--baz''', '''quux''', '''--bar''', '''0.5''']
										((_SCREAMING_SNAKE_CASE				)  ,								)			  =parser.parse_args_into_dataclasses(_a				,    look_for_args_file=_a  )
										self.assertFalse(example.flag  )




						def 							__UpperCamelCase				(       self					:      Optional[Any]  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  =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					:      List[str]  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =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  )

										_SCREAMING_SNAKE_CASE			  =[WithDefaultBoolExample]
										if is_python_no_less_than_3_10:
														dataclass_types.append(_a  )

										for dataclass_type in dataclass_types:
														_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )
														self.argparsersEqual(_a				,    _a  )

														_SCREAMING_SNAKE_CASE			  =parser.parse_args([]  )
														self.assertEqual(_a				,    Namespace(foo=_a				,    baz=_a				,    opt=_a  )  )

														_SCREAMING_SNAKE_CASE			  =parser.parse_args(['''--foo''', '''--no_baz''']  )
														self.assertEqual(_a				,    Namespace(foo=_a				,    baz=_a				,    opt=_a  )  )

														_SCREAMING_SNAKE_CASE			  =parser.parse_args(['''--foo''', '''--baz''']  )
														self.assertEqual(_a				,    Namespace(foo=_a				,    baz=_a				,    opt=_a  )  )

														_SCREAMING_SNAKE_CASE			  =parser.parse_args(['''--foo''', '''True''', '''--baz''', '''True''', '''--opt''', '''True''']  )
														self.assertEqual(_a				,    Namespace(foo=_a				,    baz=_a				,    opt=_a  )  )

														_SCREAMING_SNAKE_CASE			  =parser.parse_args(['''--foo''', '''False''', '''--baz''', '''False''', '''--opt''', '''False''']  )
														self.assertEqual(_a				,    Namespace(foo=_a				,    baz=_a				,    opt=_a  )  )




						def 							__UpperCamelCase				(       self					:      Any  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

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

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

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

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




						def 							__UpperCamelCase				(       self					:      Tuple  )							->     Any:


										"""simple docstring"""





										@dataclass
										class 						A__							:
																UpperCAmelCase             =						"toto"
										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

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

										_SCREAMING_SNAKE_CASE			  =parser.parse_args([]  )
										self.assertEqual(args.foo				,    '''toto'''  )

										_SCREAMING_SNAKE_CASE			  =parser.parse_args(['''--foo''', '''titi''']  )
										self.assertEqual(args.foo				,    '''titi'''  )

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




						def 							__UpperCamelCase				(       self					:      Optional[Any]  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  =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  )

										_SCREAMING_SNAKE_CASE			  =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]  )				,    )

										_SCREAMING_SNAKE_CASE			  =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					:      Optional[int]  )							->     str:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =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  )

										_SCREAMING_SNAKE_CASE			  =[OptionalExample]
										if is_python_no_less_than_3_10:
														dataclass_types.append(_a  )

										for dataclass_type in dataclass_types:
														_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

														self.argparsersEqual(_a				,    _a  )

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

														_SCREAMING_SNAKE_CASE			  =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					:      Optional[int]  )							->     int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  =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					:      List[Any]  )							->     Union[str, Any]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  =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					:      List[str]  )							->     Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  ={
										    '''foo''': 12,
										    '''bar''': 3.14,
										    '''baz''': '''42''',
										    '''flag''': True,
										}

										_SCREAMING_SNAKE_CASE			  =parser.parse_dict(_a  )[0]
										_SCREAMING_SNAKE_CASE			  =BasicExample(**_a  )
										self.assertEqual(_a				,    _a  )




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


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

										_SCREAMING_SNAKE_CASE			  ={
										    '''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					:      Union[str, Any]  )							->     Tuple:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

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

										_SCREAMING_SNAKE_CASE			  =BasicExample(**_a  )
										self.assertEqual(_a				,    _a  )




						def 							__UpperCamelCase				(       self					:      Dict  )							->     List[str]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )

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




						def 							__UpperCamelCase				(       self					:      Dict  )							->     Dict:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =HfArgumentParser(_a  )
										self.assertIsNotNone(_a  )



import json
import os
import shutil
import warnings
from argparse import ArgumentParser, Namespace
from pathlib import Path
from typing import List

from ..utils import logging
from . import BaseTransformersCLICommand


try:
							from cookiecutter.main import cookiecutter

							snake_case_						:			str													=							True
except ImportError:
							snake_case_						:			Optional[Any]													=							False

snake_case_						:			int													=							logging.get_logger(__name__)  # pylint: disable=invalid-name







def 						lowerCamelCase(   a__):
				return AddNewModelCommand(args.testing	,args.testing_file	,path=args.path)


class 						A__							(		UpperCamelCase__  ):




						@staticmethod
						def 							__UpperCamelCase				(       _a					:      ArgumentParser  )							->     int:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =parser.add_parser('''add-new-model'''  )
										add_new_model_parser.add_argument('''--testing'''				,    action='''store_true'''				,    help='''If in testing mode.'''  )
										add_new_model_parser.add_argument('''--testing_file'''				,    type=_a				,    help='''Configuration file on which to run.'''  )
										add_new_model_parser.add_argument(
										    '''--path'''				,    type=_a				,    help='''Path to cookiecutter. Should only be used for testing purposes.'''  )
										add_new_model_parser.set_defaults(func=_a  )




						def __init__(       self					:      List[str]				,    _a					:      bool				,    _a					:      str				,    _a					:      Any=None				,    *_a					:      Union[str, Any]  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =testing
										_SCREAMING_SNAKE_CASE			  =testing_file
										_SCREAMING_SNAKE_CASE			  =path




						def 							__UpperCamelCase				(       self					:      List[Any]  )							->     int:


										"""simple docstring"""





										warnings.warn(
										    '''The command `transformers-cli add-new-model` is deprecated and will be removed in v5 of Transformers. '''
										    '''It is not actively maintained anymore, so might give a result that won\'t pass all tests and quality '''
										    '''checks, you should use `transformers-cli add-new-model-like` instead.'''  )
										if not _has_cookiecutter:
														raise ImportError(
														    '''Model creation dependencies are required to use the `add_new_model` command. Install them by running '''
														    '''the following at the root of your `transformers` clone:\n\n\t$ pip install -e .[modelcreation]\n'''  )
										# Ensure that there is no other `cookiecutter-template-xxx` directory in the current working directory
										_SCREAMING_SNAKE_CASE			  =[directory for directory in os.listdir() if '''cookiecutter-template-''' == directory[:22]]
										if len(_a  ) > 0:
														raise ValueError(
														    '''Several directories starting with `cookiecutter-template-` in current working directory. '''
														    '''Please clean your directory by removing all folders starting with `cookiecutter-template-` or '''
														    '''change your working directory.'''  )

										_SCREAMING_SNAKE_CASE			  =(
										    Path(_a  ).parent.parent.parent.parent if self._path is None else Path(self._path  ).parent.parent
										)
										_SCREAMING_SNAKE_CASE			  =path_to_transformer_root / '''templates''' / '''adding_a_new_model'''

										# Execute cookiecutter
										if not self._testing:
														cookiecutter(str(_a  )  )
										else:
														with open(self._testing_file				,    '''r'''  ) as configuration_file:
																		_SCREAMING_SNAKE_CASE			  =json.load(_a  )

														cookiecutter(
														    str(path_to_cookiecutter if self._path is None else self._path  )				,    no_input=_a				,    extra_context=_a				,    )

										_SCREAMING_SNAKE_CASE			  =[directory for directory in os.listdir() if '''cookiecutter-template-''' in directory[:22]][0]

										# Retrieve configuration
										with open(directory + '''/configuration.json'''				,    '''r'''  ) as configuration_file:
														_SCREAMING_SNAKE_CASE			  =json.load(_a  )

										_SCREAMING_SNAKE_CASE			  =configuration['''lowercase_modelname''']
										_SCREAMING_SNAKE_CASE			  =configuration['''generate_tensorflow_pytorch_and_flax''']
										os.remove(f"{directory}/configuration.json"  )

										_SCREAMING_SNAKE_CASE			  ='''PyTorch''' in generate_tensorflow_pytorch_and_flax
										_SCREAMING_SNAKE_CASE			  ='''TensorFlow''' in generate_tensorflow_pytorch_and_flax
										_SCREAMING_SNAKE_CASE			  ='''Flax''' in generate_tensorflow_pytorch_and_flax

										_SCREAMING_SNAKE_CASE			  =f"{path_to_transformer_root}/src/transformers/models/{lowercase_model_name}"
										os.makedirs(_a				,    exist_ok=_a  )
										os.makedirs(f"{path_to_transformer_root}/tests/models/{lowercase_model_name}"				,    exist_ok=_a  )

										# Tests require submodules as they have parent imports
										with open(f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/__init__.py"				,    '''w'''  ):
														pass

										shutil.move(
										    f"{directory}/__init__.py"				,    f"{model_dir}/__init__.py"				,    )
										shutil.move(
										    f"{directory}/configuration_{lowercase_model_name}.py"				,    f"{model_dir}/configuration_{lowercase_model_name}.py"				,    )

										def remove_copy_lines(_a					:      int  ):
														with open(_a				,    '''r'''  ) as f:
																		_SCREAMING_SNAKE_CASE			  =f.readlines()
														with open(_a				,    '''w'''  ) as f:
																		for line in lines:
																						if "# Copied from transformers." not in line:
																										f.write(_a  )

										if output_pytorch:
														if not self._testing:
																		remove_copy_lines(f"{directory}/modeling_{lowercase_model_name}.py"  )

														shutil.move(
														    f"{directory}/modeling_{lowercase_model_name}.py"				,    f"{model_dir}/modeling_{lowercase_model_name}.py"				,    )

														shutil.move(
														    f"{directory}/test_modeling_{lowercase_model_name}.py"				,    f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/test_modeling_{lowercase_model_name}.py"				,    )
										else:
														os.remove(f"{directory}/modeling_{lowercase_model_name}.py"  )
														os.remove(f"{directory}/test_modeling_{lowercase_model_name}.py"  )

										if output_tensorflow:
														if not self._testing:
																		remove_copy_lines(f"{directory}/modeling_tf_{lowercase_model_name}.py"  )

														shutil.move(
														    f"{directory}/modeling_tf_{lowercase_model_name}.py"				,    f"{model_dir}/modeling_tf_{lowercase_model_name}.py"				,    )

														shutil.move(
														    f"{directory}/test_modeling_tf_{lowercase_model_name}.py"				,    f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/test_modeling_tf_{lowercase_model_name}.py"				,    )
										else:
														os.remove(f"{directory}/modeling_tf_{lowercase_model_name}.py"  )
														os.remove(f"{directory}/test_modeling_tf_{lowercase_model_name}.py"  )

										if output_flax:
														if not self._testing:
																		remove_copy_lines(f"{directory}/modeling_flax_{lowercase_model_name}.py"  )

														shutil.move(
														    f"{directory}/modeling_flax_{lowercase_model_name}.py"				,    f"{model_dir}/modeling_flax_{lowercase_model_name}.py"				,    )

														shutil.move(
														    f"{directory}/test_modeling_flax_{lowercase_model_name}.py"				,    f"{path_to_transformer_root}/tests/models/{lowercase_model_name}/test_modeling_flax_{lowercase_model_name}.py"				,    )
										else:
														os.remove(f"{directory}/modeling_flax_{lowercase_model_name}.py"  )
														os.remove(f"{directory}/test_modeling_flax_{lowercase_model_name}.py"  )

										shutil.move(
										    f"{directory}/{lowercase_model_name}.md"				,    f"{path_to_transformer_root}/docs/source/en/model_doc/{lowercase_model_name}.md"				,    )

										shutil.move(
										    f"{directory}/tokenization_{lowercase_model_name}.py"				,    f"{model_dir}/tokenization_{lowercase_model_name}.py"				,    )

										shutil.move(
										    f"{directory}/tokenization_fast_{lowercase_model_name}.py"				,    f"{model_dir}/tokenization_{lowercase_model_name}_fast.py"				,    )

										from os import fdopen, remove
										from shutil import copymode, move
										from tempfile import mkstemp

										def replace(_a					:      str				,    _a					:      str				,    _a					:      List[str]  ):
														# Create temp file
														_SCREAMING_SNAKE_CASE  ,				_SCREAMING_SNAKE_CASE			  =mkstemp()
														_SCREAMING_SNAKE_CASE			  =False
														with fdopen(_a				,    '''w'''  ) as new_file:
																		with open(_a  ) as old_file:
																						for line in old_file:
																										new_file.write(_a  )
																										if line_to_copy_below in line:
																														_SCREAMING_SNAKE_CASE			  =True
																														for line_to_copy in lines_to_copy:
																																		new_file.write(_a  )

														if not line_found:
																		raise ValueError(f"Line {line_to_copy_below} was not found in file."  )

														# Copy the file permissions from the old file to the new file
														copymode(_a				,    _a  )
														# Remove original file
														remove(_a  )
														# Move new file
														move(_a				,    _a  )

										def skip_units(_a					:      str  ):
														return (
														    ("generating PyTorch" in line and not output_pytorch)
														    or ("generating TensorFlow" in line and not output_tensorflow)
														    or ("generating Flax" in line and not output_flax)
														)

										def replace_in_files(_a					:      Any  ):
														with open(_a  ) as datafile:
																		_SCREAMING_SNAKE_CASE			  =[]
																		_SCREAMING_SNAKE_CASE			  =False
																		_SCREAMING_SNAKE_CASE			  =False
																		for line in datafile:
																						if "# To replace in: " in line and "##" not in line:
																										_SCREAMING_SNAKE_CASE			  =line.split('''"'''  )[1]
																										_SCREAMING_SNAKE_CASE			  =skip_units(_a  )
																						elif "# Below: " in line and "##" not in line:
																										_SCREAMING_SNAKE_CASE			  =line.split('''"'''  )[1]
																										_SCREAMING_SNAKE_CASE			  =skip_units(_a  )
																						elif "# End." in line and "##" not in line:
																										if not skip_file and not skip_snippet:
																														replace(_a				,    _a				,    _a  )

																										_SCREAMING_SNAKE_CASE			  =[]
																						elif "# Replace with" in line and "##" not in line:
																										_SCREAMING_SNAKE_CASE			  =[]
																						elif "##" not in line:
																										lines_to_copy.append(_a  )

														remove(_a  )

										replace_in_files(f"{directory}/to_replace_{lowercase_model_name}.py"  )
										os.rmdir(_a  )