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





       '''simple docstring'''



       @staticmethod
       def    __A			( _SCREAMING_SNAKE_CASE					)						->	Tuple:
           A_      =  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(_SCREAMING_SNAKE_CASE					)					)
           A_      =  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(_SCREAMING_SNAKE_CASE					)					)
           A_      =  parser.add_parser('''logout'''       ,	help='''Log out'''					)
           logout_parser.set_defaults(func=lambda _SCREAMING_SNAKE_CASE					: LogoutCommand(_SCREAMING_SNAKE_CASE					)					)

           # new system: git-based repo system
           A_      =  parser.add_parser(
               '''repo'''       ,	help='''Deprecated: use `huggingface-cli` instead. Commands to interact with your huggingface.co repos.'''       ,	)
           A_      =  repo_parser.add_subparsers(
               help='''Deprecated: use `huggingface-cli` instead. huggingface.co repos related commands'''					)
           A_      =  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=_SCREAMING_SNAKE_CASE       ,	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=_SCREAMING_SNAKE_CASE       ,	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(_SCREAMING_SNAKE_CASE					)					)




class       __UpperCAmelCase							:





       '''simple docstring'''



       __lowercase   :   Any  					=							'\u001b[1m'
       __lowercase   :   List[str]  					=							'\u001b[31m'
       __lowercase   :   Tuple  					=							'\u001b[90m'
       __lowercase   :   Optional[Any]  					=							'\u001b[0m'

       @classmethod
       def    __A			( cls       ,	_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           return F'''{cls._bold}{s}{cls._reset}'''

       @classmethod
       def    __A			( cls       ,	_SCREAMING_SNAKE_CASE					)						->	Dict:
           return F'''{cls._bold}{cls._red}{s}{cls._reset}'''

       @classmethod
       def    __A			( cls       ,	_SCREAMING_SNAKE_CASE					)						->	str:
           return F'''{cls._gray}{s}{cls._reset}'''





def 	_UpperCAmelCase       (				_UpperCamelCase       :      List[List[Union[str, int]]],  _UpperCamelCase       :      List[str]  )      -> str:
    A_      =  [max(len(str(_UpperCamelCase  )  ) for x in col  ) for col in zip(*_UpperCamelCase,  _UpperCamelCase  )]
    A_      =  ('''{{:{}}} ''' * len(_UpperCamelCase  )).format(*_UpperCamelCase  )
    A_      =  []
    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							:





       '''simple docstring'''



       def __init__( self       ,	_SCREAMING_SNAKE_CASE					)						->	Optional[Any]:
           A_      =  args




class       __UpperCAmelCase							(							_UpperCamelCase	):





       '''simple docstring'''



       def    __A			( self					)						->	Union[str, Any]:
           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							(							_UpperCamelCase	):





       '''simple docstring'''



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




class       __UpperCAmelCase							(							_UpperCamelCase	):





       '''simple docstring'''



       def    __A			( self					)						->	Any:
           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							(							_UpperCamelCase	):





       '''simple docstring'''



       def    __A			( self					)						->	Optional[Any]:
           print(
               ANSI.red(
                   '''WARNING! Managing repositories through transformers-cli is deprecated. '''
                   '''Please use `huggingface-cli` instead.'''					)					)
           A_      =  HfFolder.get_token()
           if token is None:
               print('''Not logged in'''					)
               exit(1					)
           try:
               A_      =  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_      =  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_      =  whoami(_SCREAMING_SNAKE_CASE					)
           A_      =  self.args.organization if self.args.organization is not None else user
           A_      =  F'''{namespace}/{self.args.name}'''
           print(F'''You are about to create {ANSI.bold(_SCREAMING_SNAKE_CASE					)}'''					)

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







'''simple docstring'''




import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


__snake_case  : Dict		       =    500_000

__snake_case       ,       __snake_case  : List[str]		       =    os.path.split(__file__)
__snake_case  : Optional[Any]		       =    os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))





@get_duration
def 	_UpperCAmelCase       (				_UpperCamelCase       :      datasets.Dataset  )      -> Union[str, Any]:
    A_      =  dataset.select(range(0,  len(_UpperCamelCase  ),  2  )  )





@get_duration
def 	_UpperCAmelCase       (				_UpperCamelCase       :      datasets.Dataset  )      -> str:
    A_      =  dataset.sort('''numbers'''  )





@get_duration
def 	_UpperCAmelCase       (				_UpperCamelCase       :      datasets.Dataset  )      -> str:
    A_      =  dataset.shuffle()





@get_duration
def 	_UpperCAmelCase       (				_UpperCamelCase       :      datasets.Dataset  )      -> Optional[Any]:
    A_      =  dataset.train_test_split(0.1  )





@get_duration
def 	_UpperCAmelCase       (				_UpperCamelCase       :      datasets.Dataset,  _UpperCamelCase       :      Optional[int]=10  )      -> Dict:
    for shard_id in range(_UpperCamelCase  ):
        A_      =  dataset.shard(_UpperCamelCase,  _UpperCamelCase  )





def 	_UpperCAmelCase       (				)      -> Any:
    A_      =  {'''num examples''': SPEED_TEST_N_EXAMPLES}
    A_      =  (select, sort, shuffle, train_test_split, shard)
    with tempfile.TemporaryDirectory() as tmp_dir:
        print('''generating dataset'''  )
        A_      =  datasets.Features({'''text''': datasets.Value('''string'''  ), '''numbers''': datasets.Value('''float32'''  )}  )
        A_      =  generate_example_dataset(
            os.path.join(_UpperCamelCase,  '''dataset.arrow'''  ),  _UpperCamelCase,  num_examples=_UpperCamelCase  )
        print('''Functions'''  )
        for func in functions:
            print(func.__name__  )
            A_      =  func(_UpperCamelCase  )

    with open(_UpperCamelCase,  '''wb'''  ) as f:
        f.write(json.dumps(_UpperCamelCase  ).encode('''utf-8'''  )  )


if __name__ == "__main__":  # useful to run the profiler
  benchmark_indices_mapping()






