class_docstr: Helper class to wrap the git and git-lfs commands.
  
  The aim is to facilitate interacting with huggingface.co hosted model or
  dataset repos, though not a lot here (if any) is actually specific to
  huggingface.co.
  
  <Tip warning={true}>
  
  [`Repository`] is deprecated in favor of the http-based alternatives implemented in
  [`HfApi`]. Given its large adoption in legacy code, the complete removal of
  [`Repository`] will only happen in release `v1.0`. For more details, please read
  https://huggingface.co/docs/huggingface_hub/concepts/git_vs_http.
  
  </Tip>
class_docstr_tok: ["Helper","class","to","wrap","the","git","and","git-lfs","commands",".","The","aim","is","to","facilitate","interacting","with","huggingface.co","hosted","model","or","dataset","repos",",","though","not","a","lot","here","(","if","any",")","is","actually","specific","to","huggingface.co",".","<","Tip","warning=","{","true","}",">","[","`","Repository","`","]","is","deprecated","in","favor","of","the","http-based","alternatives","implemented","in","[","`","HfApi","`","]",".","Given","its","large","adoption","in","legacy","code",",","the","complete","removal","of","[","`","Repository","`","]","will","only","happen","in","release","`","v1.0","`",".","For","more","details",",","please","read","https",":","\/\/huggingface.co\/docs\/huggingface_hub\/concepts\/git_vs_http",".","<","\/Tip",">"]
docstr: Instantiate a local clone of a git repo.
  
  If `clone_from` is set, the repo will be cloned from an existing remote repository.
  If the remote repo does not exist, a `EnvironmentError` exception will be thrown.
  Please create the remote repo first using [`create_repo`].
  
  `Repository` uses the local git credentials by default. If explicitly set, the `token`
  or the `git_user`/`git_email` pair will be used instead.
  
  Args:
      local_dir (`str` or `Path`):
          path (e.g. `'my_trained_model/'`) to the local directory, where
          the `Repository` will be initialized.
      clone_from (`str`, *optional*):
          Either a repository url or `repo_id`.
          Example:
          - `"https://huggingface.co/philschmid/playground-tests"`
          - `"philschmid/playground-tests"`
      repo_type (`str`, *optional*):
          To set when cloning a repo from a repo_id. Default is model.
      token (`bool` or `str`, *optional*):
          A valid authentication token (see https://huggingface.co/settings/token).
          If `None` or `True` and machine is logged in (through `huggingface-cli login`
          or [`~huggingface_hub.login`]), token will be retrieved from the cache.
          If `False`, token is not sent in the request header.
      git_user (`str`, *optional*):
          will override the `git config user.name` for committing and
          pushing files to the hub.
      git_email (`str`, *optional*):
          will override the `git config user.email` for committing and
          pushing files to the hub.
      revision (`str`, *optional*):
          Revision to checkout after initializing the repository. If the
          revision doesn't exist, a branch will be created with that
          revision name from the default branch's current HEAD.
      skip_lfs_files (`bool`, *optional*, defaults to `False`):
          whether to skip git-LFS files or not.
      client (`HfApi`, *optional*):
          Instance of [`HfApi`] to use when calling the HF Hub API. A new
          instance will be created if this is left to `None`.
  
  Raises:
      - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
        if the remote repository set in `clone_from` does not exist.
docstr_tok: ["Instantiate","a","local","clone","of","a","git","repo",".","If","`","clone_from","`","is","set",",","the","repo","will","be","cloned","from","an","existing","remote","repository",".","If","the","remote","repo","does","not","exist",",","a","`","EnvironmentError","`","exception","will","be","thrown",".","Please","create","the","remote","repo","first","using","[","`","create_repo","`","]",".","`","Repository","`","uses","the","local","git","credentials","by","default",".","If","explicitly","set",",","the","`","token","`","or","the","`","git_user","`","\/","`","git_email","`","pair","will","be","used","instead",".","Args",":","local_dir","(","`","str","`","or","`","Path","`",")",":","path","(","e.g",".","`","'my_trained_model\/","'","`",")","to","the","local","directory",",","where","the","`","Repository","`","will","be","initialized",".","clone_from","(","`","str","`",",","*","optional","*",")",":","Either","a","repository","url","or","`","repo_id","`",".","Example",":","-","`","``","https",":","\/\/huggingface.co\/philschmid\/playground-tests","''","`","-","`","``","philschmid\/playground-tests","''","`","repo_type","(","`","str","`",",","*","optional","*",")",":","To","set","when","cloning","a","repo","from","a","repo_id",".","Default","is","model",".","token","(","`","bool","`","or","`","str","`",",","*","optional","*",")",":","A","valid","authentication","token","(","see","https",":","\/\/huggingface.co\/settings\/token",")",".","If","`","None","`","or","`","True","`","and","machine","is","logged","in","(","through","`","huggingface-cli","login","`","or","[","`","~huggingface_hub.login","`","]",")",",","token","will","be","retrieved","from","the","cache",".","If","`","False","`",",","token","is","not","sent","in","the","request","header",".","git_user","(","`","str","`",",","*","optional","*",")",":","will","override","the","`","git","config","user.name","`","for","committing","and","pushing","files","to","the","hub",".","git_email","(","`","str","`",",","*","optional","*",")",":","will","override","the","`","git","config","user.email","`","for","committing","and","pushing","files","to","the","hub",".","revision","(","`","str","`",",","*","optional","*",")",":","Revision","to","checkout","after","initializing","the","repository",".","If","the","revision","does","n't","exist",",","a","branch","will","be","created","with","that","revision","name","from","the","default","branch","'s","current","HEAD",".","skip_lfs_files","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","whether","to","skip","git-LFS","files","or","not",".","client","(","`","HfApi","`",",","*","optional","*",")",":","Instance","of","[","`","HfApi","`","]","to","use","when","calling","the","HF","Hub","API",".","A","new","instance","will","be","created","if","this","is","left","to","`","None","`",".","Raises",":","-","[","`","EnvironmentError","`","]","(","https",":","\/\/docs.python.org\/3\/library\/exceptions.html","#","EnvironmentError",")","if","the","remote","repository","set","in","`","clone_from","`","does","not","exist","."]
code: def __init__(
      self,
      local_dir: Union[str, Path],
      clone_from: Optional[str] = None,
      repo_type: Optional[str] = None,
      token: Union[bool, str] = True,
      git_user: Optional[str] = None,
      git_email: Optional[str] = None,
      revision: Optional[str] = None,
      skip_lfs_files: bool = False,
      client: Optional[HfApi] = None,
  ):
      """
      Instantiate a local clone of a git repo.
  
      If `clone_from` is set, the repo will be cloned from an existing remote repository.
      If the remote repo does not exist, a `EnvironmentError` exception will be thrown.
      Please create the remote repo first using [`create_repo`].
  
      `Repository` uses the local git credentials by default. If explicitly set, the `token`
      or the `git_user`/`git_email` pair will be used instead.
  
      Args:
          local_dir (`str` or `Path`):
              path (e.g. `'my_trained_model/'`) to the local directory, where
              the `Repository` will be initialized.
          clone_from (`str`, *optional*):
              Either a repository url or `repo_id`.
              Example:
              - `"https://huggingface.co/philschmid/playground-tests"`
              - `"philschmid/playground-tests"`
          repo_type (`str`, *optional*):
              To set when cloning a repo from a repo_id. Default is model.
          token (`bool` or `str`, *optional*):
              A valid authentication token (see https://huggingface.co/settings/token).
              If `None` or `True` and machine is logged in (through `huggingface-cli login`
              or [`~huggingface_hub.login`]), token will be retrieved from the cache.
              If `False`, token is not sent in the request header.
          git_user (`str`, *optional*):
              will override the `git config user.name` for committing and
              pushing files to the hub.
          git_email (`str`, *optional*):
              will override the `git config user.email` for committing and
              pushing files to the hub.
          revision (`str`, *optional*):
              Revision to checkout after initializing the repository. If the
              revision doesn't exist, a branch will be created with that
              revision name from the default branch's current HEAD.
          skip_lfs_files (`bool`, *optional*, defaults to `False`):
              whether to skip git-LFS files or not.
          client (`HfApi`, *optional*):
              Instance of [`HfApi`] to use when calling the HF Hub API. A new
              instance will be created if this is left to `None`.
  
      Raises:
          - [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
            if the remote repository set in `clone_from` does not exist.
      """
      if isinstance(local_dir, Path):
          local_dir = str(local_dir)
      os.makedirs(local_dir, exist_ok=True)
      self.local_dir = os.path.join(os.getcwd(), local_dir)
      self._repo_type = repo_type
      self.command_queue = []
      self.skip_lfs_files = skip_lfs_files
      self.client = client if client is not None else HfApi()
  
      self.check_git_versions()
  
      if isinstance(token, str):
          self.huggingface_token: Optional[str] = token
      elif token is False:
          self.huggingface_token = None
      else:
          # if `True` -> explicit use of the cached token
          # if `None` -> implicit use of the cached token
          self.huggingface_token = get_token()
  
      if clone_from is not None:
          self.clone_from(repo_url=clone_from)
      else:
          if is_git_repo(self.local_dir):
              logger.debug("[Repository] is a valid git repo")
          else:
              raise ValueError(
                  "If not specifying `clone_from`, you need to pass Repository a valid git clone."
              )
  
      if self.huggingface_token is not None and (
          git_email is None or git_user is None
      ):
          user = self.client.whoami(self.huggingface_token)
  
          if git_email is None:
              git_email = user["email"]
  
          if git_user is None:
              git_user = user["fullname"]
  
      if git_user is not None or git_email is not None:
          self.git_config_username_and_email(git_user, git_email)
  
      self.lfs_enable_largefiles()
      self.git_credential_helper_store()
  
      if revision is not None:
          self.git_checkout(revision, create_branch_ok=True)
  
      # This ensures that all commands exit before exiting the Python runtime.
      # This will ensure all pushes register on the hub, even if other errors happen in subsequent operations.
      atexit.register(self.wait_for_commands)
  
imports: import atexit
  import os
  import re
  import subprocess
  import threading
  import time
  from contextlib import contextmanager
  from pathlib import Path
  from typing import Callable, Dict, Iterator, List, Optional, Tuple, TypedDict, Union
  from urllib.parse import urlparse
  from huggingface_hub.constants import REPO_TYPES_URL_PREFIXES, REPOCARD_NAME
  from huggingface_hub.repocard import metadata_load, metadata_save
  from .hf_api import HfApi, repo_type_and_id_from_hf_id
  from .lfs import LFS_MULTIPART_UPLOAD_COMMAND
  from .utils import SoftTemporaryDirectory, get_token, logging, run_subprocess, tqdm, validate_hf_hub_args
  from .utils._deprecation import _deprecate_method
label_desc: Use image node_id 1 to create a new Repository object  with example: obj = Repository(local_dir, clone_from, repo_type, token, git_user, git_email, revision, skip_lfs_files, client)