

"""simple docstring"""



import json
import os
import subprocess
import sys
import warnings
from argparse import ArgumentParser
from contextlib import AbstractContextManager
from typing import Dict, List, Optional

import requests

from ..utils import logging
from . import BaseTransformersCLICommand


SCREAMING_SNAKE_CASE_       :						List[str]					=    logging.get_logger(__name__)  # pylint: disable=invalid-name


SCREAMING_SNAKE_CASE_       :						List[str]					=    'lfs-multipart-upload'



class        a    (							_lowerCamelCase					):



    """simple docstring"""



    @staticmethod
    def 					UpperCamelCase						(  UpperCamelCase:			ArgumentParser							):






         """simple docstring"""


         A__				      =	parser.add_parser(
             """lfs-enable-largefiles"""     ,    help=(
                 """Deprecated: use `huggingface-cli` instead. Configure your repository to enable upload of files > 5GB."""
             )     ,    )
         enable_parser.add_argument("""path"""     ,    type=UpperCamelCase     ,    help="""Local path to repository you want to configure."""							)
         enable_parser.set_defaults(func=lambda UpperCamelCase							: LfsEnableCommand(UpperCamelCase							)							)

         A__				      =	parser.add_parser(
             UpperCamelCase     ,    help=(
                 """Deprecated: use `huggingface-cli` instead. """
                 """Command will get called by git-lfs, do not call it directly."""
             )     ,    )
         upload_parser.set_defaults(func=lambda UpperCamelCase							: LfsUploadCommand(UpperCamelCase							)							)



class        a    :



    """simple docstring"""



    def __init__(  self:			str     ,    UpperCamelCase:			int							):






         """simple docstring"""


         A__				      =	args





    def 					UpperCamelCase						(  self:			List[Any]							):






         """simple docstring"""


         warnings.warn(
             """Managing repositories through transformers-cli is deprecated. Please use `huggingface-cli` instead."""							)
         A__				      =	os.path.abspath(self.args.path							)
         if not os.path.isdir(UpperCamelCase							):
              print("""This does not look like a valid git repo."""							)
              exit(1							)
         subprocess.run(
             """git config lfs.customtransfer.multipart.path transformers-cli""".split()     ,    check=UpperCamelCase     ,    cwd=UpperCamelCase							)
         subprocess.run(
             f"""git config lfs.customtransfer.multipart.args {LFS_MULTIPART_UPLOAD_COMMAND}""".split()     ,    check=UpperCamelCase     ,    cwd=UpperCamelCase     ,    )
         print("""Local repo set up for largefiles"""							)





def 			_snake_case  (     UpperCAmelCase_	:       Dict      ):
     A__				      =	json.dumps(UpperCAmelCase_      ) + """\n"""
     sys.stdout.write(UpperCAmelCase_      )
     sys.stdout.flush()





def 			_snake_case  (     ):
     A__				      =	json.loads(sys.stdin.readline().strip()      )

     if "terminate" in (msg.get("""type"""      ), msg.get("""event"""      )):
          # terminate message received
          return None

     if msg.get("""event"""      ) not in ("download", "upload"):
          logger.critical("""Received unexpected message"""      )
          sys.exit(1      )

     return msg



class        a    (							_lowerCamelCase					):



    """simple docstring"""



    def __init__(  self:			Dict     ,    UpperCamelCase:			str     ,    UpperCamelCase:			int     ,    UpperCamelCase:			int							):






         """simple docstring"""


         A__				      =	filepath
         A__				      =	seek_from
         A__				      =	read_limit
         A__				      =	0

    def __enter__(  self:			Any							):






         """simple docstring"""


         A__				      =	open(self.filepath     ,    """rb"""							)
         self.f.seek(self.seek_from							)
         return self

    def __len__(  self:			Optional[Any]							):






         """simple docstring"""


         A__				      =	os.fstat(self.f.fileno()							).st_size
         return min(self.read_limit     ,    total_length - self.seek_from							)

    def 					UpperCamelCase						(  self:			int     ,    UpperCamelCase:			List[Any]=-1							):






         """simple docstring"""


         if self.n_seen >= self.read_limit:
              return b""
         A__				      =	self.read_limit - self.n_seen
         A__				      =	self.f.read(remaining_amount if n < 0 else min(UpperCamelCase     ,    UpperCamelCase							)							)
         self.n_seen += len(UpperCamelCase							)
         return data

    def __iter__(  self:			Tuple							):






         """simple docstring"""


         yield self.read(n=4 * 10_24 * 10_24							)





    def __exit__(  self:			Optional[int]     ,    *UpperCamelCase:			Any							):






         """simple docstring"""


         self.f.close()



class        a    :



    """simple docstring"""



    def __init__(  self:			Optional[int]     ,    UpperCamelCase:			List[str]							):






         """simple docstring"""


         A__				      =	args





    def 					UpperCamelCase						(  self:			int							):






         """simple docstring"""


         A__				      =	json.loads(sys.stdin.readline().strip()							)
         if not (init_msg.get("""event"""							) == "init" and init_msg.get("""operation"""							) == "upload"):
              write_msg({"""error""": {"""code""": 32, """message""": """Wrong lfs init operation"""}}							)
              sys.exit(1							)

         # The transfer process should use the information it needs from the
         # initiation structure, and also perform any one-off setup tasks it
         # needs to do. It should then respond on stdout with a simple empty
         # confirmation structure, as follows:
         write_msg({}							)

         # After the initiation exchange, git-lfs will send any number of
         # transfer requests to the stdin of the transfer process, in a serial sequence.
         while True:
              A__				      =	read_msg()
              if msg is None:
                   # When all transfers have been processed, git-lfs will send
                   # a terminate event to the stdin of the transfer process.
                   # On receiving this message the transfer process should
                   # clean up and terminate. No response is expected.
                   sys.exit(0							)

              A__				      =	msg["""oid"""]
              A__				      =	msg["""path"""]
              A__				      =	msg["""action"""]["""href"""]
              A__				      =	msg["""action"""]["""header"""]
              A__				      =	int(header.pop("""chunk_size"""							)							)
              A__				      =	list(header.values()							)

              A__				      =	[]
              for i, presigned_url in enumerate(UpperCamelCase							):
                   with FileSlice(UpperCamelCase     ,    seek_from=i * chunk_size     ,    read_limit=UpperCamelCase							) as data:
                        A__				      =	requests.put(UpperCamelCase     ,    data=UpperCamelCase							)
                        r.raise_for_status()
                        parts.append(
                            {
                                """etag""": r.headers.get("""etag"""							),
                                """partNumber""": i + 1,
                            }							)
                        # In order to support progress reporting while data is uploading / downloading,
                        # the transfer process should post messages to stdout
                        write_msg(
                            {
                                """event""": """progress""",
                                """oid""": oid,
                                """bytesSoFar""": (i + 1) * chunk_size,
                                """bytesSinceLast""": chunk_size,
                            }							)
                        # Not precise but that's ok.

              A__				      =	requests.post(
                  UpperCamelCase     ,    json={
                      """oid""": oid,
                      """parts""": parts,
                  }     ,    )
              r.raise_for_status()

              write_msg({"""event""": """complete""", """oid""": oid}							)









"""simple docstring"""



import os

from ...utils import logging
from .utils import DataProcessor, InputExample


SCREAMING_SNAKE_CASE_       :						Dict					=    logging.get_logger(__name__)



class        a    (							_lowerCamelCase					):



    """simple docstring"""



    def __init__(  self:			Tuple     ,    UpperCamelCase:			Optional[Any]     ,    UpperCamelCase:			Optional[int]=None							):






         """simple docstring"""


         A__				      =	language
         A__				      =	train_language

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






         """simple docstring"""


         A__				      =	self.language if self.train_language is None else self.train_language
         A__				      =	self._read_tsv(os.path.join(UpperCamelCase     ,    f"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""							)							)
         A__				      =	[]
         for i, line in enumerate(UpperCamelCase							):
              if i == 0:
                   continue
              A__				      =	f"""train-{i}"""
              A__				      =	line[0]
              A__				      =	line[1]
              A__				      =	"""contradiction""" if line[2] == """contradictory""" else line[2]
              if not isinstance(UpperCamelCase     ,    UpperCamelCase							):
                   raise ValueError(f"""Training input {text_a} is not a string"""							)
              if not isinstance(UpperCamelCase     ,    UpperCamelCase							):
                   raise ValueError(f"""Training input {text_b} is not a string"""							)
              if not isinstance(UpperCamelCase     ,    UpperCamelCase							):
                   raise ValueError(f"""Training label {label} is not a string"""							)
              examples.append(InputExample(guid=UpperCamelCase     ,    text_a=UpperCamelCase     ,    text_b=UpperCamelCase     ,    label=UpperCamelCase							)							)
         return examples

    def 					UpperCamelCase						(  self:			Dict     ,    UpperCamelCase:			Union[str, Any]							):






         """simple docstring"""


         A__				      =	self._read_tsv(os.path.join(UpperCamelCase     ,    """XNLI-1.0/xnli.test.tsv"""							)							)
         A__				      =	[]
         for i, line in enumerate(UpperCamelCase							):
              if i == 0:
                   continue
              A__				      =	line[0]
              if language != self.language:
                   continue
              A__				      =	f"""test-{i}"""
              A__				      =	line[6]
              A__				      =	line[7]
              A__				      =	line[1]
              if not isinstance(UpperCamelCase     ,    UpperCamelCase							):
                   raise ValueError(f"""Training input {text_a} is not a string"""							)
              if not isinstance(UpperCamelCase     ,    UpperCamelCase							):
                   raise ValueError(f"""Training input {text_b} is not a string"""							)
              if not isinstance(UpperCamelCase     ,    UpperCamelCase							):
                   raise ValueError(f"""Training label {label} is not a string"""							)
              examples.append(InputExample(guid=UpperCamelCase     ,    text_a=UpperCamelCase     ,    text_b=UpperCamelCase     ,    label=UpperCamelCase							)							)
         return examples





    def 					UpperCamelCase						(  self:			Tuple							):






         """simple docstring"""


         return ["contradiction", "entailment", "neutral"]

SCREAMING_SNAKE_CASE_       :						int					=    {
    'xnli': XnliProcessor,
}

SCREAMING_SNAKE_CASE_       :						List[Any]					=    {
    'xnli': 'classification',
}

SCREAMING_SNAKE_CASE_       :						str					=    {
    'xnli': 3,
}






