






"""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  UpperCamelCase    (			snake_case_   ):


 @staticmethod
 def _lowercase			(  UpperCAmelCase__	:		ArgumentParser							)      -> Optional[Any]:
   _a						: Optional[int]    =			parser.add_parser("""login"""							,		help="""Log in using the same credentials as on huggingface.co"""							)
   login_parser.set_defaults(func=lambda UpperCAmelCase__							: LoginCommand(UpperCAmelCase__							)							)
   _a						: str    =			parser.add_parser("""whoami"""							,		help="""Find out which huggingface.co account you are logged in as."""							)
   whoami_parser.set_defaults(func=lambda UpperCAmelCase__							: WhoamiCommand(UpperCAmelCase__							)							)
   _a						: Optional[int]    =			parser.add_parser("""logout"""							,		help="""Log out"""							)
   logout_parser.set_defaults(func=lambda UpperCAmelCase__							: LogoutCommand(UpperCAmelCase__							)							)

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







class  UpperCamelCase    :
 UpperCamelCase      : List[str]    =      '''\u001b[1m'''
 UpperCamelCase      : Tuple    =      '''\u001b[31m'''
 UpperCamelCase      : Tuple    =      '''\u001b[90m'''
 UpperCamelCase      : Optional[int]    =      '''\u001b[0m'''


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


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







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







def     lowerCAmelCase__  (  UpperCamelCase__  ,     UpperCamelCase__       ):



  '''simple docstring'''
  _a						: List[Any]    =			[max(len(str(UpperCamelCase__       )       ) for x in col       ) for col in zip(*UpperCamelCase__  ,     UpperCamelCase__       )]
  _a						: Dict    =			("""{{:{}}} """ * len(UpperCamelCase__       )).format(*UpperCamelCase__       )
  _a						: List[Any]    =			[]
  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  UpperCamelCase    :


 def __init__(  self	:		Tuple							,		UpperCAmelCase__	:		int							)      -> Tuple:
   _a						: Dict    =			args







class  UpperCamelCase    (			snake_case_   ):


 def _lowercase			(  self	:		List[str]							)      -> List[str]:
   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  UpperCamelCase    (			snake_case_   ):


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







class  UpperCamelCase    (			snake_case_   ):


 def _lowercase			(  self	:		List[str]							)      -> List[str]:
   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  UpperCamelCase    (			snake_case_   ):


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

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

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









"""simple docstring"""




# this script builds a small sample spm file tests/fixtures/test_sentencepiece_no_bos.model, with features needed by pegasus

# 1. pip install sentencepiece
#
# 2. wget https://raw.githubusercontent.com/google/sentencepiece/master/data/botchan.txt

# 3. build
import sentencepiece as spm

# pegasus:
# 1. no bos
# 2. eos_id is 1
# 3. unk_id is 2
# build a sample spm file accordingly
spm.SentencePieceTrainer.train(
    '--input=botchan.txt --model_prefix=test_sentencepiece_no_bos --bos_id=-1 --unk_id=2  --eos_id=1  --vocab_size=1000'
)

# 4. now update the fixture
# mv test_sentencepiece_no_bos.model ../../tests/fixtures/

