
"""simple docstring"""

import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE

class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):
     lowercase						       =						""
     lowercase						       =						(
         None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
     )
     lowercase						       =						None  # compression type in fsspec. ex: "gzip"
     lowercase						       =						None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz





     def __init__(     self     ,					__UpperCAmelCase = ""     ,					__UpperCAmelCase = None     ,					__UpperCAmelCase = None     ,					**__UpperCAmelCase				):

      '''simple docstring'''




      super().__init__(self     ,					**__UpperCAmelCase				)
      # always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
      __UpperCamelCase      =	fsspec.open(
          __UpperCAmelCase     ,					mode='rb'     ,					protocol=__UpperCAmelCase     ,					compression=self.compression     ,					client_kwargs={
              'requote_redirect_url': False,  # see https://github.com/huggingface/datasets/pull/5459
              'trust_env': True,  # Enable reading proxy env variables.
              **(target_options or {}).pop('client_kwargs'     ,					{}				),  # To avoid issues if it was already passed.
          }     ,					**(target_options or {})     ,					)
      __UpperCamelCase      =	os.path.basename(self.file.path.split('::'				)[0]				)
      __UpperCamelCase      =	(
          self.compressed_name[: self.compressed_name.rindex('.'				)]
          if '.' in self.compressed_name
          else self.compressed_name
      )
      __UpperCamelCase      =	None





     @classmethod
     def 						UpperCAmelCase (     cls     ,					__UpperCAmelCase				):

      '''simple docstring'''




      return super()._strip_protocol(__UpperCAmelCase				).lstrip('/'				)





     def 						UpperCAmelCase (     self				):

      '''simple docstring'''




      if self.dir_cache is None:
       __UpperCamelCase      =	{**self.file.fs.info(self.file.path				), 'name': self.uncompressed_name}
       __UpperCamelCase      =	{f['name']: f}





     def 						UpperCAmelCase (     self     ,					__UpperCAmelCase				):

      '''simple docstring'''




      return self.file.open().read()







     def 						UpperCAmelCase (     self     ,					__UpperCAmelCase     ,					__UpperCAmelCase = "rb"     ,					__UpperCAmelCase=None     ,					__UpperCAmelCase=True     ,					__UpperCAmelCase=None     ,					**__UpperCAmelCase     ,					):

      '''simple docstring'''




      __UpperCamelCase      =	self._strip_protocol(__UpperCAmelCase				)
      if mode != "rb":
       raise ValueError(F'Tried to read with mode {mode} on file {self.file.path} opened with mode \'rb\''				)
      return self.file.open()


class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):
     lowercase						       =						"bz2"
     lowercase						       =						"bz2"
     lowercase						       =						".bz2"


class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):
     lowercase						       =						"gzip"
     lowercase						       =						"gzip"
     lowercase						       =						".gz"


class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):
     lowercase						       =						"lz4"
     lowercase						       =						"lz4"
     lowercase						       =						".lz4"


class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):
     lowercase						       =						"xz"
     lowercase						       =						"xz"
     lowercase						       =						".xz"


class __lowerCAmelCase		(				__SCREAMING_SNAKE_CASE      ):
     lowercase						       =						"zstd"
     lowercase						       =						"zstd"
     lowercase						       =						".zst"





     def __init__(     self     ,					__UpperCAmelCase     ,					__UpperCAmelCase = "rb"     ,					__UpperCAmelCase = None     ,					__UpperCAmelCase = None     ,					__UpperCAmelCase = DEFAULT_BLOCK_SIZE     ,					**__UpperCAmelCase     ,					):

      '''simple docstring'''




      super().__init__(
          fo=__UpperCAmelCase     ,					mode=__UpperCAmelCase     ,					target_protocol=__UpperCAmelCase     ,					target_options=__UpperCAmelCase     ,					block_size=__UpperCAmelCase     ,					**__UpperCAmelCase     ,					)
      # We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
      #
      # File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
      #     out.close = close
      # AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
      #
      # see https://github.com/intake/filesystem_spec/issues/725
      __UpperCamelCase      =	self.file.__enter__

      class __lowerCAmelCase		:





           def __init__(     self     ,					__UpperCAmelCase				):

            '''simple docstring'''




            __UpperCamelCase      =	file_





           def __enter__(     self				):

            '''simple docstring'''




            self._file.__enter__()
            return self





           def __exit__(     self     ,					*__UpperCAmelCase     ,					**__UpperCAmelCase				):

            '''simple docstring'''




            self._file.__exit__(*__UpperCAmelCase     ,					**__UpperCAmelCase				)





           def __iter__(     self				):

            '''simple docstring'''




            return iter(self._file				)





           def 						UpperCAmelCase (     self				):

            '''simple docstring'''




            return next(self._file				)







           def __getattr__(     self     ,					__UpperCAmelCase				):

            '''simple docstring'''




            return getattr(self._file     ,					__UpperCAmelCase				)

      def fixed_enter(*__UpperCAmelCase     ,					**__UpperCAmelCase				):
       return WrappedFile(_enter(*__UpperCAmelCase     ,					**__UpperCAmelCase				)				)

      __UpperCamelCase      =	fixed_enter





"""simple docstring"""

from argparse import ArgumentParser

from .add_new_model import AddNewModelCommand
from .add_new_model_like import AddNewModelLikeCommand
from .convert import ConvertCommand
from .download import DownloadCommand
from .env import EnvironmentCommand
from .lfs import LfsCommands
from .pt_to_tf import PTtoTFCommand
from .run import RunCommand
from .serving import ServeCommand
from .user import UserCommands






def 							A						(    )				->     Union[str, Any]:
 __UpperCamelCase      =	ArgumentParser('Transformers CLI tool'    , usage='transformers-cli <command> [<args>]'		)
 __UpperCamelCase      =	parser.add_subparsers(help='transformers-cli command helpers'		)

 # Register commands
 ConvertCommand.register_subcommand(snake_case		)
 DownloadCommand.register_subcommand(snake_case		)
 EnvironmentCommand.register_subcommand(snake_case		)
 RunCommand.register_subcommand(snake_case		)
 ServeCommand.register_subcommand(snake_case		)
 UserCommands.register_subcommand(snake_case		)
 AddNewModelCommand.register_subcommand(snake_case		)
 AddNewModelLikeCommand.register_subcommand(snake_case		)
 LfsCommands.register_subcommand(snake_case		)
 PTtoTFCommand.register_subcommand(snake_case		)

 # Let's go
 __UpperCamelCase      =	parser.parse_args()

 if not hasattr(snake_case    , 'func'		):
  parser.print_help()
  exit(1		)

 # Run
 __UpperCamelCase      =	args.func(snake_case		)
 service.run()


if __name__ == "__main__":
      main()



