



"""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	(     _lowercase):




  def 						SCREAMING_SNAKE_CASE    (			self					:						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase						:    Optional[int]         =			SMALL_MODEL_IDENTIFIER
         _lowerCamelCase						:    Tuple         =			'''pt'''
         _lowerCamelCase						:    List[Any]         =			'''tf'''




  def 						SCREAMING_SNAKE_CASE    (			self					:						Any						, __lowerCAmelCase					:						List[Any]		):






         """simple docstring"""






         _lowerCamelCase						:    Any         =			AutoModel.from_pretrained(self.test_model		)
         model_pt.save_pretrained(__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						Any						, __lowerCAmelCase					:						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase						:    Tuple         =			TFAutoModel.from_pretrained(self.test_model						, from_pt=__lowerCAmelCase		)
         model_tf.save_pretrained(__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						str		):






         """simple docstring"""






         _lowerCamelCase						:    List[Any]         =			'''mock_framework'''

         # Framework provided - return whatever the user provides
         _lowerCamelCase						:    Any         =			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		)
                _lowerCamelCase						:    Optional[Any]         =			FeaturesManager.determine_framework(__lowerCAmelCase						, __lowerCAmelCase		)
                self.assertEqual(__lowerCAmelCase						, __lowerCAmelCase		)

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
                self._setup_tf_ckpt(__lowerCAmelCase		)
                _lowerCamelCase						:    Dict         =			FeaturesManager.determine_framework(__lowerCAmelCase						, __lowerCAmelCase		)
                self.assertEqual(__lowerCAmelCase						, __lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						Union[str, Any]		):






         """simple docstring"""






         with TemporaryDirectory() as local_pt_ckpt:
                self._setup_pt_ckpt(__lowerCAmelCase		)
                _lowerCamelCase						:    str         =			FeaturesManager.determine_framework(__lowerCAmelCase		)
                self.assertEqual(__lowerCAmelCase						, self.framework_pt		)

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
                self._setup_tf_ckpt(__lowerCAmelCase		)
                _lowerCamelCase						:    List[str]         =			FeaturesManager.determine_framework(__lowerCAmelCase		)
                self.assertEqual(__lowerCAmelCase						, self.framework_tf		)

         # Invalid local checkpoint
         with TemporaryDirectory() as local_invalid_ckpt:
                with self.assertRaises(__lowerCAmelCase		):
                       _lowerCamelCase						:    Any         =			FeaturesManager.determine_framework(__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						Any		):






         """simple docstring"""






         _lowerCamelCase						:    Optional[int]         =			MagicMock(return_value=__lowerCAmelCase		)
         with patch('''transformers.onnx.features.is_tf_available'''						, __lowerCAmelCase		):
                _lowerCamelCase						:    List[str]         =			FeaturesManager.determine_framework(self.test_model		)
                self.assertEqual(__lowerCAmelCase						, self.framework_pt		)

         # PyTorch not in environment -> use TensorFlow
         _lowerCamelCase						:    Union[str, Any]         =			MagicMock(return_value=__lowerCAmelCase		)
         with patch('''transformers.onnx.features.is_torch_available'''						, __lowerCAmelCase		):
                _lowerCamelCase						:    str         =			FeaturesManager.determine_framework(self.test_model		)
                self.assertEqual(__lowerCAmelCase						, self.framework_tf		)

         # Both in environment -> use PyTorch
         _lowerCamelCase						:    Optional[int]         =			MagicMock(return_value=__lowerCAmelCase		)
         _lowerCamelCase						:    int         =			MagicMock(return_value=__lowerCAmelCase		)
         with patch('''transformers.onnx.features.is_tf_available'''						, __lowerCAmelCase		), patch(
             '''transformers.onnx.features.is_torch_available'''						, __lowerCAmelCase		):
                _lowerCamelCase						:    Optional[int]         =			FeaturesManager.determine_framework(self.test_model		)
                self.assertEqual(__lowerCAmelCase						, self.framework_pt		)

         # Both not in environment -> raise error
         _lowerCamelCase						:    int         =			MagicMock(return_value=__lowerCAmelCase		)
         _lowerCamelCase						:    Union[str, Any]         =			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		):
                       _lowerCamelCase						:    List[str]         =			FeaturesManager.determine_framework(self.test_model		)







"""simple docstring"""






import argparse


lowerCAmelCase__      =    '''docs/source/_static/js/custom.js'''






def 	snake_case_  (				A_ :		List[str]						):


       '''simple docstring'''





       with open(A_,    encoding='''utf-8''',    newline='''\n'''						) as f:
              _lowerCamelCase						:    int         =			f.readlines()
       _lowerCamelCase						:    List[str]         =			0

       # First let's put the right version
       while not lines[index].startswith('''const stableVersion ='''						):
              index += 1
       _lowerCamelCase						:    List[Any]         =			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(A_,    '''w''',    encoding='''utf-8''',    newline='''\n'''						) as f:
              f.writelines(A_						)


if __name__ == "__main__":
   lowerCAmelCase__      =    argparse.ArgumentParser()
   parser.add_argument('''--version''', help='''Release version.''')
   lowerCAmelCase__      =    parser.parse_args()
   update_custom_js(args.version)


