code: def _tar_path_python(
      source_path: str, target_file: str, compression: bool = False
  ) -> None:
      """Create tar from directory using `python`
  
      Parameters
      ----------
      source_path: str
          Source directory or file
      target_file
          Target tar file
      compression: bool, default False
          Enable compression, which is disabled by default.
  
      """
      file_mode = "w:gz" if compression else "w:"
  
      with tarfile.open(target_file, file_mode) as tar:
          if os.path.isdir(source_path):
              tar.add(str(source_path), arcname=".")
          elif os.path.isfile(source_path):
              file_info = tarfile.TarInfo(
                  os.path.basename(str(source_path))
              )
              with open(source_path) as fo:
                  tar.addfile(file_info, fo)
  
file_path: pytorch-lightning/src/lightning/app/source_code/tar.py
imports: import math
  import os
  import subprocess
  import tarfile
  from dataclasses import dataclass
  from typing import Optional, Tuple
  import click
label_desc: Use image node_id 4 for calling a global function with example usage: _tar_path_python(source_path, target_file, compression) without return types