




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     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):

					@staticmethod
					def      lowercase_							(    __lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							parser.add_parser('login'			,	help='Log in using the same credentials as on huggingface.co' )
						login_parser.set_defaults(func=lambda __lowercase : LoginCommand(__lowercase ) )
						lowerCamelCase_							:		Union[str, Any]							       =							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 ) )
						lowerCamelCase_							:		List[Any]							       =							parser.add_parser('logout'			,	help='Log out' )
						logout_parser.set_defaults(func=lambda __lowercase : LogoutCommand(__lowercase ) )

						# new system: git-based repo system
						lowerCamelCase_							:		List[Any]							       =							parser.add_parser(
						    'repo'			,	help='Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.'			,	)
						lowerCamelCase_							:		List[Any]							       =							repo_parser.add_subparsers(
						    help='Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands' )
						lowerCamelCase_							:		Optional[Any]							       =							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     __SCREAMING_SNAKE_CASE							:
					_lowerCamelCase		  =			"""\u001b[1m"""
					_lowerCamelCase		  =			"""\u001b[31m"""
					_lowerCamelCase		  =			"""\u001b[90m"""
					_lowerCamelCase		  =			"""\u001b[0m"""

					@classmethod
					def      lowercase_							(    cls			,	__lowercase ):







						'''simple docstring'''




						return f"{cls._bold}{s}{cls._reset}"

					@classmethod
					def      lowercase_							(    cls			,	__lowercase ):







						'''simple docstring'''




						return f"{cls._bold}{cls._red}{s}{cls._reset}"





					@classmethod
					def      lowercase_							(    cls			,	__lowercase ):







						'''simple docstring'''




						return f"{cls._gray}{s}{cls._reset}"






def  snake_case (							A						,       A      )							->							str:




	'''simple docstring'''


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


class     __SCREAMING_SNAKE_CASE							:

					def __init__(    self			,	__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							args


class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):

					def      lowercase_							(    self ):







						'''simple docstring'''




						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     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):

					def      lowercase_							(    self ):







						'''simple docstring'''




						print(
						    ANSI.red(
						        'WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use '
						        '`huggingface-cli whoami` instead.' ) )
						lowerCamelCase_							:		List[Any]							       =							HfFolder.get_token()
						if token is None:
							print('Not logged in' )
							exit()
						try:
							lowerCamelCase_       ,      lowerCamelCase_							:		int							       =							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     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):

					def      lowercase_							(    self ):







						'''simple docstring'''




						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     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):

					def      lowercase_							(    self ):







						'''simple docstring'''




						print(
						    ANSI.red(
						        'WARNING! Managing repositories through transformers-cli is deprecated. '
						        'Please use `huggingface-cli` instead.' ) )
						lowerCamelCase_							:		Dict							       =							HfFolder.get_token()
						if token is None:
							print('Not logged in' )
							exit(1 )
						try:
							lowerCamelCase_							:		str							       =							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:
							lowerCamelCase_							:		Optional[Any]							       =							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('' )

						lowerCamelCase_       ,      lowerCamelCase_							:		Any							       =							whoami(__lowercase )
						lowerCamelCase_							:		Tuple							       =							self.args.organization if self.args.organization is not None else user
						lowerCamelCase_							:		Dict							       =							f"{namespace}/{self.args.name}"
						print(f"You are about to create {ANSI.bold(__lowercase )}" )

						if not self.args.yes:
							lowerCamelCase_							:		Any							       =							input('Proceed? [Y/n] ' ).lower()
							if not (choice == "" or choice == "y" or choice == "yes"):
								print('Abort' )
								exit()
						try:
							lowerCamelCase_							:		int							       =							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('' )






from typing import Callable






def  snake_case (							A      )							->							List[str]:




	'''simple docstring'''


	def wrapper(A      ):
		lowerCamelCase_							:		Dict							       =							function_with_docstring.__doc__
		return target_function

	return wrapper
