



import subprocess
from argparse import ArgumentParser
from typing import List, Union

from huggingface_hub.hf_api import HfFolder, create_repo, whoami
from requests.exceptions import HTTPError

from . import BaseTransformersCLICommand







class 							a_  (		_snake_case				):

						@staticmethod
						def 	__a       (    _lowercase	:ArgumentParser)		->					Dict:
												UpperCAmelCase_     							=     parser.add_parser('''login'''   ,						help='''Log in using the same credentials as on huggingface.co''')
												login_parser.set_defaults(func=lambda _lowercase: LoginCommand(_lowercase))
												UpperCAmelCase_     							=     parser.add_parser('''whoami'''   ,						help='''Find out which huggingface.co account you are logged in as.''')
												whoami_parser.set_defaults(func=lambda _lowercase: WhoamiCommand(_lowercase))
												UpperCAmelCase_     							=     parser.add_parser('''logout'''   ,						help='''Log out''')
												logout_parser.set_defaults(func=lambda _lowercase: LogoutCommand(_lowercase))

												# new system: git-based repo system
												UpperCAmelCase_     							=     parser.add_parser(
												    '''repo'''   ,						help='''Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.'''   ,						)
												UpperCAmelCase_     							=     repo_parser.add_subparsers(
												    help='''Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands''')
												UpperCAmelCase_     							=     repo_subparsers.add_parser(
												    '''create'''   ,						help='''Deprecated: use `huggingface-cli` instead. Create a new repo on huggingface.co''')
												repo_create_parser.add_argument(
												    '''name'''   ,						type=_lowercase   ,						help='''Name for your model\'s repo. Will be namespaced under your username to build the model id.'''   ,						)
												repo_create_parser.add_argument('''--organization'''   ,						type=_lowercase   ,						help='''Optional: organization namespace.''')
												repo_create_parser.add_argument('''-y'''   ,						'''--yes'''   ,						action='''store_true'''   ,						help='''Optional: answer Yes to the prompt''')
												repo_create_parser.set_defaults(func=lambda _lowercase: RepoCreateCommand(_lowercase))







class 							a_  :
						UpperCamelCase__      :						Any				       ="\u001b[1m"
						UpperCamelCase__      :						Optional[Any]				       ="\u001b[31m"
						UpperCamelCase__      :						Union[str, Any]				       ="\u001b[90m"
						UpperCamelCase__      :						Union[str, Any]				       ="\u001b[0m"

						@classmethod
						def 	__a       (    cls	:Any   ,						_lowercase	:Optional[int])		->					Tuple:
												return f"{cls._bold}{s}{cls._reset}"

						@classmethod
						def 	__a       (    cls	:str   ,						_lowercase	:List[Any])		->					int:
												return f"{cls._bold}{cls._red}{s}{cls._reset}"




						@classmethod
						def 	__a       (    cls	:Union[str, Any]   ,						_lowercase	:Optional[int])		->					List[Any]:
												return f"{cls._gray}{s}{cls._reset}"







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase	)       ->       str:



						'''simple docstring'''






						UpperCAmelCase_     							=     [max(len(str(__UpperCAmelCase	)	) for x in col	) for col in zip(*__UpperCAmelCase							,					__UpperCAmelCase	)]
						UpperCAmelCase_     							=     ('''{{:{}}} ''' * len(__UpperCAmelCase	)).format(*__UpperCAmelCase	)
						UpperCAmelCase_     							=     []
						lines.append(row_format.format(*__UpperCAmelCase	)	)
						lines.append(row_format.format(*['''-''' * w for w in col_widths]	)	)
						for row in rows:
												lines.append(row_format.format(*__UpperCAmelCase	)	)
						return "\n".join(__UpperCAmelCase	)







class 							a_  :

						def __init__(    self	:Dict   ,						_lowercase	:Dict)		->					List[Any]:
												UpperCAmelCase_     							=     args







class 							a_  (		_snake_case				):

						def 	__a       (    self	:List[str])		->					Optional[int]:
												print(
												    ANSI.red(
												        '''ERROR! `huggingface-cli login` uses an outdated login mechanism '''
												        '''that is not compatible with the Hugging Face Hub backend anymore. '''
												        '''Please use `huggingface-cli login instead.'''))







class 							a_  (		_snake_case				):

						def 	__a       (    self	:Union[str, Any])		->					Optional[int]:
												print(
												    ANSI.red(
												        '''WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use '''
												        '''`huggingface-cli whoami` instead.'''))
												UpperCAmelCase_     							=     HfFolder.get_token()
												if token is None:
																		print('''Not logged in''')
																		exit()
												try:
																		UpperCAmelCase_							,      UpperCAmelCase_     							=     whoami(_lowercase)
																		print(_lowercase)
																		if orgs:
																								print(ANSI.bold('''orgs: ''')   ,						''','''.join(_lowercase))
												except HTTPError as e:
																		print(_lowercase)
																		print(ANSI.red(e.response.text))
																		exit(1)







class 							a_  (		_snake_case				):

						def 	__a       (    self	:str)		->					Tuple:
												print(
												    ANSI.red(
												        '''ERROR! `transformers-cli logout` uses an outdated logout mechanism '''
												        '''that is not compatible with the Hugging Face Hub backend anymore. '''
												        '''Please use `huggingface-cli logout instead.'''))







class 							a_  (		_snake_case				):

						def 	__a       (    self	:str)		->					Union[str, Any]:
												print(
												    ANSI.red(
												        '''WARNING! Managing repositories through transformers-cli is deprecated. '''
												        '''Please use `huggingface-cli` instead.'''))
												UpperCAmelCase_     							=     HfFolder.get_token()
												if token is None:
																		print('''Not logged in''')
																		exit(1)
												try:
																		UpperCAmelCase_     							=     subprocess.check_output(['''git''', '''--version''']).decode('''utf-8''')
																		print(ANSI.gray(stdout.strip()))
												except FileNotFoundError:
																		print('''Looks like you do not have git installed, please install.''')

												try:
																		UpperCAmelCase_     							=     subprocess.check_output(['''git-lfs''', '''--version''']).decode('''utf-8''')
																		print(ANSI.gray(stdout.strip()))
												except FileNotFoundError:
																		print(
																		    ANSI.red(
																		        '''Looks like you do not have git-lfs installed, please install.'''
																		        ''' You can install from https://git-lfs.github.com/.'''
																		        ''' Then run `git lfs install` (you only have to do this once).'''))
												print('''''')

												UpperCAmelCase_							,      UpperCAmelCase_     							=     whoami(_lowercase)
												UpperCAmelCase_     							=     self.args.organization if self.args.organization is not None else user
												UpperCAmelCase_     							=     f"{namespace}/{self.args.name}"
												print(f"You are about to create {ANSI.bold(_lowercase)}")

												if not self.args.yes:
																		UpperCAmelCase_     							=     input('''Proceed? [Y/n] ''').lower()
																		if not (choice == "" or choice == "y" or choice == "yes"):
																								print('''Abort''')
																								exit()
												try:
																		UpperCAmelCase_     							=     create_repo(_lowercase   ,						name=self.args.name   ,						organization=self.args.organization)
												except HTTPError as e:
																		print(_lowercase)
																		print(ANSI.red(e.response.text))
																		exit(1)
												print('''\nYour repo now lives at:''')
												print(f"  {ANSI.bold(_lowercase)}")
												print('''\nYou can clone it locally with the command below, and commit/push as usual.''')
												print(f"\n  git clone {url}")
												print('''''')










def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5) + 32							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) + 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5) + 491.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) - 32) * 5 / 9							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(((float(__UpperCAmelCase	) - 32) * 5 / 9) + 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) + 459.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) - 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(((float(__UpperCAmelCase	) - 273.15) * 9 / 5) + 32							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) - 491.67) * 5 / 9							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) - 459.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 5 / 9)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 1.25 + 273.15)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 2.25 + 32)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 1.25)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 2.25 + 32 + 459.67)							,					__UpperCAmelCase	)


if __name__ == "__main__":
							import doctest

							doctest.testmod()





