
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 						lowercase       (  _a					):
					@staticmethod
					def lowercase_			(		SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







								lowerCAmelCase__ :    Union[str, Any]				      =			parser.add_parser('''login''' ,	help='''Log in using the same credentials as on huggingface.co'''    )
								login_parser.set_defaults(func=lambda SCREAMING_SNAKE_CASE__    : LoginCommand(lowerCamelCase__    )    )
								lowerCAmelCase__ :    List[str]				      =			parser.add_parser('''whoami''' ,	help='''Find out which huggingface.co account you are logged in as.'''    )
								whoami_parser.set_defaults(func=lambda SCREAMING_SNAKE_CASE__    : WhoamiCommand(lowerCamelCase__    )    )
								lowerCAmelCase__ :    Optional[int]				      =			parser.add_parser('''logout''' ,	help='''Log out'''    )
								logout_parser.set_defaults(func=lambda SCREAMING_SNAKE_CASE__    : LogoutCommand(lowerCamelCase__    )    )

								# new system: git-based repo system
								lowerCAmelCase__ :    List[str]				      =			parser.add_parser(
								    '''repo''' ,	help='''Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.''' ,	)
								lowerCAmelCase__ :    int				      =			repo_parser.add_subparsers(
								    help='''Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands'''    )
								lowerCAmelCase__ :    List[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=lowerCamelCase__ ,	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=lowerCamelCase__ ,	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 SCREAMING_SNAKE_CASE__    : RepoCreateCommand(lowerCamelCase__    )    )





class 						lowercase       :
					__a					=    """\u001b[1m"""
					__a					=    """\u001b[31m"""
					__a					=    """\u001b[90m"""
					__a					=    """\u001b[0m"""
					@classmethod
					def lowercase_			(		cls ,	SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







								return f'''{cls._bold}{s}{cls._reset}'''
					@classmethod
					def lowercase_			(		cls ,	SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







								return f'''{cls._bold}{cls._red}{s}{cls._reset}'''
					@classmethod
					def lowercase_			(		cls ,	SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







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





def      _a     (   __UpperCamelCase       :  List[str]	,__UpperCamelCase       :  List[Any]    ):
			lowerCAmelCase__ :    int				      =			[max(len(str(__UpperCamelCase    )    ) for x in col    ) for col in zip(*__UpperCamelCase	,__UpperCamelCase    )]
			lowerCAmelCase__ :    List[str]				      =			("{{:{}}} " * len(__UpperCamelCase    )).format(*__UpperCamelCase    )
			lowerCAmelCase__ :    str				      =			[]
			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 						lowercase       :
					def __init__(		self ,	SCREAMING_SNAKE_CASE__    ):
								"""simple docstring"""







								lowerCAmelCase__ :    str				      =			args





class 						lowercase       (  _a					):
					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 						lowercase       (  _a					):
					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__ :    Tuple				      =			HfFolder.get_token()
								if token is None:
											print('''Not logged in'''    )
											exit()
								try:
											lowerCAmelCase__ :    Dict				      =			whoami(lowerCamelCase__    )
											print(lowerCamelCase__    )
											if orgs:
														print(ANSI.bold('''orgs: '''    ) ,	''','''.join(lowerCamelCase__    )    )
								except HTTPError as e:
											print(lowerCamelCase__    )
											print(ANSI.red(e.response.text    )    )
											exit(1    )





class 						lowercase       (  _a					):
					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 						lowercase       (  _a					):
					def lowercase_			(		self    ):
								"""simple docstring"""







								print(
								    ANSI.red(
								        '''WARNING! Managing repositories through transformers-cli is deprecated. '''
								        '''Please use `huggingface-cli` instead.'''    )    )
								lowerCAmelCase__ :    Union[str, Any]				      =			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__ :    List[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__ :    str				      =			whoami(lowerCamelCase__    )
								lowerCAmelCase__ :    Optional[Any]				      =			self.args.organization if self.args.organization is not None else user
								lowerCAmelCase__ :    Union[str, Any]				      =			f'''{namespace}/{self.args.name}'''
								print(f'''You are about to create {ANSI.bold(lowerCamelCase__    )}'''    )

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





from math import radians as angle_to_radians
from math import sin

# Acceleration Constant on Earth (unit m/s^2)
A__       :   str   						=					9.8_0665



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):

			# Ensure valid instance
			if not isinstance(__UpperCamelCase	,(int, float)    ):
						raise TypeError('''Invalid velocity. Should be a positive number.'''    )

			if not isinstance(__UpperCamelCase	,(int, float)    ):
						raise TypeError('''Invalid angle. Range is 1-90 degrees.'''    )

			# Ensure valid angle
			if angle > 90 or angle < 1:
						raise ValueError('''Invalid angle. Range is 1-90 degrees.'''    )

			# Ensure valid velocity
			if init_velocity < 0:
						raise ValueError('''Invalid velocity. Should be a positive number.'''    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    Union[str, Any]				      =			angle_to_radians(2 * angle    )
			return round(init_velocity**2 * sin(__UpperCamelCase    ) / g	,2    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    List[str]				      =			angle_to_radians(__UpperCamelCase    )
			return round(init_velocity**2 * sin(__UpperCamelCase    ) ** 2 / (2 * g)	,2    )



def      _a     (   __UpperCamelCase       :  float	,__UpperCamelCase       :  float    ):
			check_args(__UpperCamelCase	,__UpperCamelCase    )
			lowerCAmelCase__ :    Dict				      =			angle_to_radians(__UpperCamelCase    )
			return round(2 * init_velocity * sin(__UpperCamelCase    ) / g	,2    )



def      _a     (   ):
			lowerCAmelCase__      ,				lowerCAmelCase__ :    List[Any]				      =			25, 20
			assert horizontal_distance(__UpperCamelCase	,__UpperCamelCase    ) == 40.97
			assert max_height(__UpperCamelCase	,__UpperCamelCase    ) == 3.73
			assert total_time(__UpperCamelCase	,__UpperCamelCase    ) == 1.74


if __name__ == "__main__":
							from doctest import testmod

							testmod()

							# Get input from user
							A__       :   List[Any]   						=					float(input("""Initial Velocity: """).strip())

							# Get input from user
							A__       :   Optional[Any]   						=					float(input("""angle: """).strip())

							# Print results
							print()
							print("""Results: """)
							print(f"""Horizontal Distance: {horizontal_distance(init_vel, angle)!s} [m]""")
							print(f"""Maximum Height: {max_height(init_vel, angle)!s} [m]""")
							print(f"""Total Time: {total_time(init_vel, angle)!s} [s]""")



