original_docstring: Downloads the file from the given source and saves it in the given
      destination path.
  
       Arguments
      ---------
      source : path or url
          Path of the source file. If the source is an URL, it downloads it from
          the web.
      dest : path
          Destination path.
      unpack : bool
          If True, it unpacks the data in the dest folder.
      replace_existing : bool
          If True, replaces the existing files.
      
docstring: Downloads the file from the given source and saves it in the given
  destination path.
  
  Arguments
  
  source : path or url
  Path of the source file. If the source is an URL, it downloads it from
  the web.
  dest : path
  Destination path.
  unpack : bool
  If True, it unpacks the data in the dest folder.
  replace_existing : bool
  If True, replaces the existing files.
docstring_tokens: Downloads the file from the given source and saves it in the given destination path . Arguments source : path or url Path of the source file . If the source is an URL it downloads it from the web . dest : path Destination path . unpack : bool If True it unpacks the data in the dest folder . replace_existing : bool If True replaces the existing files .
code: def download_file(
      source, dest, unpack=False, dest_unpack=None, replace_existing=False
  ):
      """Downloads the file from the given source and saves it in the given
      destination path.
  
       Arguments
      ---------
      source : path or url
          Path of the source file. If the source is an URL, it downloads it from
          the web.
      dest : path
          Destination path.
      unpack : bool
          If True, it unpacks the data in the dest folder.
      replace_existing : bool
          If True, replaces the existing files.
      """
      try:
          if if_main_process():
  
              class DownloadProgressBar(tqdm.tqdm):
                  def update_to(self, b=1, bsize=1, tsize=None):
                      if tsize is not None:
                          self.total = tsize
                      self.update(b * bsize - self.n)
  
              # Create the destination directory if it doesn't exist
              dest_dir = pathlib.Path(dest).resolve().parent
              dest_dir.mkdir(parents=True, exist_ok=True)
              if "http" not in source:
                  shutil.copyfile(source, dest)
  
              elif not os.path.isfile(dest) or (
                  os.path.isfile(dest) and replace_existing
              ):
                  print(f"Downloading {source} to {dest}")
                  with DownloadProgressBar(
                      unit="B",
                      unit_scale=True,
                      miniters=1,
                      desc=source.split("/")[-1],
                  ) as t:
                      urllib.request.urlretrieve(
                          source, filename=dest, reporthook=t.update_to
                      )
              else:
                  print(f"{dest} exists. Skipping download")
  
              # Unpack if necessary
              if unpack:
                  if dest_unpack is None:
                      dest_unpack = os.path.dirname(dest)
                  print(f"Extracting {dest} to {dest_unpack}")
                  shutil.unpack_archive(dest, dest_unpack)
      finally:
          ddp_barrier()
code_tokens: def download_file ( source , dest , unpack = False , dest_unpack = None , replace_existing = False ) : try : if if_main_process ( ) : class DownloadProgressBar ( tqdm . tqdm ) : def update_to ( self , b = 1 , bsize = 1 , tsize = None ) : if tsize is not None : self . total = tsize self . update ( b * bsize - self . n ) dest_dir = pathlib . Path ( dest ) . resolve ( ) . parent dest_dir . mkdir ( parents = True , exist_ok = True ) if "http" not in source : shutil . copyfile ( source , dest ) elif not os . path . isfile ( dest ) or ( os . path . isfile ( dest ) and replace_existing ) : print ( f"Downloading {source} to {dest}" ) with DownloadProgressBar ( unit = "B" , unit_scale = True , miniters = 1 , desc = source . split ( "/" ) [ - 1 ] , ) as t : urllib . request . urlretrieve ( source , filename = dest , reporthook = t . update_to ) else : print ( f"{dest} exists. Skipping download" ) if unpack : if dest_unpack is None : dest_unpack = os . path . dirname ( dest ) print ( f"Extracting {dest} to {dest_unpack}" ) shutil . unpack_archive ( dest , dest_unpack ) finally : ddp_barrier ( )
short_docstring: Downloads the file from the given source and saves it in the given
  destination path.
short_docstring_tokens: Downloads the file from the given source and saves it in the given destination path .
comment: """Downloads the file from the given source and saves it in the given
      destination path.
  
       Arguments
      ---------
      source : path or url
          Path of the source file. If the source is an URL, it downloads it from
          the web.
      dest : path
          Destination path.
      unpack : bool
          If True, it unpacks the data in the dest folder.
      replace_existing : bool
          If True, replaces the existing files.
      """$SEP$# Create the destination directory if it doesn't exist$SEP$# Unpack if necessary