

"""simple docstring"""




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     (      __lowerCamelCase   ):

  @staticmethod
  def 				__lowercase    (					A						:     ArgumentParser      ):






   '''simple docstring'''
   UpperCAmelCase__   :					Tuple   				=   parser.add_parser("""login"""   ,help="""Log in using the same credentials as on huggingface.co"""      )
   login_parser.set_defaults(func=lambda A      : LoginCommand(A      )      )
   UpperCAmelCase__   :					Any   				=   parser.add_parser("""whoami"""   ,help="""Find out which huggingface.co account you are logged in as."""      )
   whoami_parser.set_defaults(func=lambda A      : WhoamiCommand(A      )      )
   UpperCAmelCase__   :					Union[str, Any]   				=   parser.add_parser("""logout"""   ,help="""Log out"""      )
   logout_parser.set_defaults(func=lambda A      : LogoutCommand(A      )      )

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







class        __lowercase     :
  snake_case_			    =    """\u001b[1m"""
  snake_case_			    =    """\u001b[31m"""
  snake_case_			    =    """\u001b[90m"""
  snake_case_			    =    """\u001b[0m"""

  @classmethod
  def 				__lowercase    (					cls						:     Tuple   ,A						:     Optional[int]      ):






   '''simple docstring'''
   return f"{cls._bold}{s}{cls._reset}"

  @classmethod
  def 				__lowercase    (					cls						:     Dict   ,A						:     List[Any]      ):






   '''simple docstring'''
   return f"{cls._bold}{cls._red}{s}{cls._reset}"




  @classmethod
  def 				__lowercase    (					cls						:     Dict   ,A						:     Union[str, Any]      ):






   '''simple docstring'''
   return f"{cls._gray}{s}{cls._reset}"







def 					lowerCAmelCase  (   __UpperCamelCase							,      __UpperCamelCase ):
 '''simple docstring'''





 UpperCAmelCase__   :					List[Any]   				=   [max(len(str(__UpperCamelCase ) ) for x in col ) for col in zip(*__UpperCamelCase							,      __UpperCamelCase )]
 UpperCAmelCase__   :					int   				=   ("""{{:{}}} """ * len(__UpperCamelCase )).format(*__UpperCamelCase )
 UpperCAmelCase__   :					List[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						:     Tuple   ,A						:     Tuple      ):






   '''simple docstring'''
   UpperCAmelCase__   :					List[str]   				=   args







class        __lowercase     (      __lowerCamelCase   ):

  def 				__lowercase    (					self						:     int      ):






   '''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     (      __lowerCamelCase   ):

  def 				__lowercase    (					self						:     List[Any]      ):






   '''simple docstring'''
   print(
       ANSI.red(
           """WARNING! `transformers-cli whoami` is deprecated and will be removed in v5. Please use """
           """`huggingface-cli whoami` instead."""      )      )
   UpperCAmelCase__   :					Dict   				=   HfFolder.get_token()
   if token is None:
    print("""Not logged in"""      )
    exit()
   try:
    UpperCAmelCase__				, UpperCAmelCase__   :					Dict   				=   whoami(A      )
    print(A      )
    if orgs:
     print(ANSI.bold("""orgs: """      )   ,""",""".join(A      )      )
   except HTTPError as e:
    print(A      )
    print(ANSI.red(e.response.text      )      )
    exit(1      )







class        __lowercase     (      __lowerCamelCase   ):

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






   '''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     (      __lowerCamelCase   ):

  def 				__lowercase    (					self						:     Optional[int]      ):






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

   UpperCAmelCase__				, UpperCAmelCase__   :					List[str]   				=   whoami(A      )
   UpperCAmelCase__   :					Dict   				=   self.args.organization if self.args.organization is not None else user
   UpperCAmelCase__   :					Tuple   				=   f"{namespace}/{self.args.name}"
   print(f"You are about to create {ANSI.bold(A      )}"      )

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








"""simple docstring"""




def 					lowerCAmelCase  (   __UpperCamelCase ):
 '''simple docstring'''





 UpperCAmelCase__   :					Union[str, Any]   				=   1
 UpperCAmelCase__   :					Union[str, Any]   				=   0
 UpperCAmelCase__   :					List[str]   				=   1
 UpperCAmelCase__   :					Any   				=   1
 UpperCAmelCase__   :					Optional[int]   				=   3
 UpperCAmelCase__   :					Any   				=   3
 UpperCAmelCase__   :					Optional[Any]   				=   limit
 UpperCAmelCase__   :					Dict   				=   0

 UpperCAmelCase__   :					int   				=   """"""
 while counter != decimal + 1:
  if 4 * q + r - t < n * t:
   result += str(__UpperCamelCase )
   if counter == 0:
    result += "."

   if decimal == counter:
    break

   counter += 1
   UpperCAmelCase__   :					Union[str, Any]   				=   10 * (r - n * t)
   UpperCAmelCase__   :					int   				=   ((10 * (3 * q + r)) // t) - 10 * n
   q *= 10
   UpperCAmelCase__   :					str   				=   nr
  else:
   UpperCAmelCase__   :					List[str]   				=   (2 * q + r) * l
   UpperCAmelCase__   :					Union[str, Any]   				=   (q * (7 * k) + 2 + (r * l)) // (t * l)
   q *= k
   t *= l
   l += 2
   k += 1
   UpperCAmelCase__   :					Optional[Any]   				=   nn
   UpperCAmelCase__   :					str   				=   nr
 return result
def 					lowerCAmelCase  (   ):
 '''simple docstring'''





 print(F"{calculate_pi(50 ) = }" )
 import doctest

 doctest.testmod()


if __name__ == "__main__":
      main()





