"""simple docstring"""






from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch
@require_torch
@require_tf
class 				snake_case       ( __UpperCAmelCase				):




					"""simple docstring"""

					def 		__lowerCAmelCase						(				self   :	Optional[int]			):
									UpperCAmelCase__             =							SMALL_MODEL_IDENTIFIER
									UpperCAmelCase__             =							'pt'
									UpperCAmelCase__             =							'tf'







					def 		__lowerCAmelCase						(				self   :	str    ,lowerCamelCase__   :	int			):
									UpperCAmelCase__             =							AutoModel.from_pretrained(self.test_model			)
									model_pt.save_pretrained(lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	int    ,lowerCamelCase__   :	Any			):
									UpperCAmelCase__             =							TFAutoModel.from_pretrained(self.test_model    ,from_pt=lowerCamelCase__			)
									model_tf.save_pretrained(lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Tuple			):
									UpperCAmelCase__             =							'mock_framework'

									# Framework provided - return whatever the user provides
									UpperCAmelCase__             =							FeaturesManager.determine_framework(self.test_model    ,lowerCamelCase__			)
									self.assertEqual(lowerCamelCase__    ,lowerCamelCase__			)

									# Local checkpoint and framework provided - return provided framework
									# PyTorch checkpoint
									with TemporaryDirectory() as local_pt_ckpt:
													self._setup_pt_ckpt(lowerCamelCase__			)
													UpperCAmelCase__             =							FeaturesManager.determine_framework(lowerCamelCase__    ,lowerCamelCase__			)
													self.assertEqual(lowerCamelCase__    ,lowerCamelCase__			)

									# TensorFlow checkpoint
									with TemporaryDirectory() as local_tf_ckpt:
													self._setup_tf_ckpt(lowerCamelCase__			)
													UpperCAmelCase__             =							FeaturesManager.determine_framework(lowerCamelCase__    ,lowerCamelCase__			)
													self.assertEqual(lowerCamelCase__    ,lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	int			):
									# PyTorch checkpoint
									with TemporaryDirectory() as local_pt_ckpt:
													self._setup_pt_ckpt(lowerCamelCase__			)
													UpperCAmelCase__             =							FeaturesManager.determine_framework(lowerCamelCase__			)
													self.assertEqual(lowerCamelCase__    ,self.framework_pt			)

									# TensorFlow checkpoint
									with TemporaryDirectory() as local_tf_ckpt:
													self._setup_tf_ckpt(lowerCamelCase__			)
													UpperCAmelCase__             =							FeaturesManager.determine_framework(lowerCamelCase__			)
													self.assertEqual(lowerCamelCase__    ,self.framework_tf			)

									# Invalid local checkpoint
									with TemporaryDirectory() as local_invalid_ckpt:
													with self.assertRaises(lowerCamelCase__			):
																	UpperCAmelCase__             =							FeaturesManager.determine_framework(lowerCamelCase__			)







					def 		__lowerCAmelCase						(				self   :	Any			):
									UpperCAmelCase__             =							MagicMock(return_value=lowerCamelCase__			)
									with patch('transformers.onnx.features.is_tf_available'    ,lowerCamelCase__			):
													UpperCAmelCase__             =							FeaturesManager.determine_framework(self.test_model			)
													self.assertEqual(lowerCamelCase__    ,self.framework_pt			)

									# PyTorch not in environment -> use TensorFlow
									UpperCAmelCase__             =							MagicMock(return_value=lowerCamelCase__			)
									with patch('transformers.onnx.features.is_torch_available'    ,lowerCamelCase__			):
													UpperCAmelCase__             =							FeaturesManager.determine_framework(self.test_model			)
													self.assertEqual(lowerCamelCase__    ,self.framework_tf			)

									# Both in environment -> use PyTorch
									UpperCAmelCase__             =							MagicMock(return_value=lowerCamelCase__			)
									UpperCAmelCase__             =							MagicMock(return_value=lowerCamelCase__			)
									with patch('transformers.onnx.features.is_tf_available'    ,lowerCamelCase__			), patch(
									    'transformers.onnx.features.is_torch_available'    ,lowerCamelCase__			):
													UpperCAmelCase__             =							FeaturesManager.determine_framework(self.test_model			)
													self.assertEqual(lowerCamelCase__    ,self.framework_pt			)

									# Both not in environment -> raise error
									UpperCAmelCase__             =							MagicMock(return_value=lowerCamelCase__			)
									UpperCAmelCase__             =							MagicMock(return_value=lowerCamelCase__			)
									with patch('transformers.onnx.features.is_tf_available'    ,lowerCamelCase__			), patch(
									    'transformers.onnx.features.is_torch_available'    ,lowerCamelCase__			):
													with self.assertRaises(lowerCamelCase__			):
																	UpperCAmelCase__             =							FeaturesManager.determine_framework(self.test_model			)




"""simple docstring"""






import argparse


lowerCAmelCase__  :  List[str]						     =	'docs/source/_static/js/custom.js'



def   a_						(					lowerCamelCase       ):
				with open(lowerCamelCase					,			encoding='utf-8'					,			newline='\n'       ) as f:
								UpperCAmelCase__             =							f.readlines()
				UpperCAmelCase__             =							0

				# First let's put the right version
				while not lines[index].startswith('const stableVersion ='       ):
								index += 1
				UpperCAmelCase__             =							f'''const stableVersion = "v{version}"\n'''

				# Then update the dictionary
				while not lines[index].startswith('const versionMapping = {'       ):
								index += 1

				# We go until the end
				while not lines[index].startswith('}'       ):
								index += 1
				# We add the new version at the end
				lines[index - 1] += f'''    "v{version}": "v{version}",\n'''

				with open(lowerCamelCase					,			'w'					,			encoding='utf-8'					,			newline='\n'       ) as f:
								f.writelines(lowerCamelCase       )


if __name__ == "__main__":
						lowerCAmelCase__  :  List[Any]						     =	argparse.ArgumentParser()
						parser.add_argument('--version', help='Release version.')
						lowerCAmelCase__  :  Optional[int]						     =	parser.parse_args()
						update_custom_js(args.version)



