





"""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    _lowerCAmelCase  (	a			):
       """simple docstring"""




       def 	snake_case		(       self ):



         '''simple docstring'''

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






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				AutoModel.from_pretrained(self.test_model )
         model_pt.save_pretrained(__UpperCAmelCase )






       def 	snake_case		(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Dict											=				TFAutoModel.from_pretrained(self.test_model       ,					from_pt=__UpperCAmelCase )
         model_tf.save_pretrained(__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Tuple											=				'mock_framework'

         # Framework provided - return whatever the user provides
         lowerCAmelCase__     :Dict											=				FeaturesManager.determine_framework(self.test_model       ,					__UpperCAmelCase )
         self.assertEqual(__UpperCAmelCase       ,					__UpperCAmelCase )

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

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
           self._setup_tf_ckpt(__UpperCAmelCase )
           lowerCAmelCase__     :List[Any]											=				FeaturesManager.determine_framework(__UpperCAmelCase       ,					__UpperCAmelCase )
           self.assertEqual(__UpperCAmelCase       ,					__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         with TemporaryDirectory() as local_pt_ckpt:
           self._setup_pt_ckpt(__UpperCAmelCase )
           lowerCAmelCase__     :List[Any]											=				FeaturesManager.determine_framework(__UpperCAmelCase )
           self.assertEqual(__UpperCAmelCase       ,					self.framework_pt )

         # TensorFlow checkpoint
         with TemporaryDirectory() as local_tf_ckpt:
           self._setup_tf_ckpt(__UpperCAmelCase )
           lowerCAmelCase__     :List[Any]											=				FeaturesManager.determine_framework(__UpperCAmelCase )
           self.assertEqual(__UpperCAmelCase       ,					self.framework_tf )

         # Invalid local checkpoint
         with TemporaryDirectory() as local_invalid_ckpt:
           with self.assertRaises(__UpperCAmelCase ):
             lowerCAmelCase__     :Union[str, Any]											=				FeaturesManager.determine_framework(__UpperCAmelCase )






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Dict											=				MagicMock(return_value=__UpperCAmelCase )
         with patch('transformers.onnx.features.is_tf_available'       ,					__UpperCAmelCase ):
           lowerCAmelCase__     :List[Any]											=				FeaturesManager.determine_framework(self.test_model )
           self.assertEqual(__UpperCAmelCase       ,					self.framework_pt )

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

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

         # Both not in environment -> raise error
         lowerCAmelCase__     :Optional[Any]											=				MagicMock(return_value=__UpperCAmelCase )
         lowerCAmelCase__     :Tuple											=				MagicMock(return_value=__UpperCAmelCase )
         with patch('transformers.onnx.features.is_tf_available'       ,					__UpperCAmelCase ), patch(
             'transformers.onnx.features.is_torch_available'       ,					__UpperCAmelCase ):
           with self.assertRaises(__UpperCAmelCase ):
             lowerCAmelCase__     :Union[str, Any]											=				FeaturesManager.determine_framework(self.test_model )


'''simple docstring'''
import os
from collections.abc import Iterator




def    _UpperCamelCase						(       SCREAMING_SNAKE_CASE__ = "."			)  ->							Iterator[str]:


		'''simple docstring'''


		for dir_path, dir_names, filenames in os.walk(SCREAMING_SNAKE_CASE__			):
				snake_case  :       Optional[Any]     			=						[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    _UpperCamelCase						(       SCREAMING_SNAKE_CASE__			)  ->							List[str]:


		'''simple docstring'''


		return F'{i * "  "}*' if i else "\n##"




def    _UpperCamelCase						(       SCREAMING_SNAKE_CASE__ ,       SCREAMING_SNAKE_CASE__			)  ->							str:


		'''simple docstring'''


		snake_case  :       Union[str, Any]     			=						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    _UpperCamelCase						(       SCREAMING_SNAKE_CASE__ = "."			)  ->							None:


		'''simple docstring'''


		snake_case  :       List[Any]     			=						''''''
		for filepath in sorted(good_file_paths(SCREAMING_SNAKE_CASE__			)			):
				snake_case			,snake_case  :       Optional[Any]     			=						os.path.split(SCREAMING_SNAKE_CASE__			)
				if filepath != old_path:
						snake_case  :       Dict     			=						print_path(SCREAMING_SNAKE_CASE__ ,       SCREAMING_SNAKE_CASE__			)
				snake_case  :       int     			=						(filepath.count(os.sep			) + 1) if filepath else 0
				snake_case  :       int     			=						F'{filepath}/{filename}'.replace(''' ''' ,       '''%20'''			)
				snake_case  :       int     			=						os.path.splitext(filename.replace('''_''' ,       ''' '''			).title()			)[0]
				print(F'{md_prefix(SCREAMING_SNAKE_CASE__			)} [{filename}]({url})'			)


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


