code: def tarball_context(url, target_dir=None, runner=None, pushd=pushd):
      """
      Get a tarball, extract it, change to that directory, yield, then
      clean up.
      `runner` is the function to invoke commands.
      `pushd` is a context manager for changing the directory.
      """
      if target_dir is None:
          target_dir = (
              os.path.basename(url)
              .replace(".tar.gz", "")
              .replace(".tgz", "")
          )
      if runner is None:
          runner = functools.partial(subprocess.check_call, shell=True)
      else:
          warnings.warn(
              "runner parameter is deprecated", DeprecationWarning
          )
      # In the tar command, use --strip-components=1 to strip the first path and
      #  then
      #  use -C to cause the files to be extracted to {target_dir}. This ensures
      #  that we always know where the files were extracted.
      runner("mkdir {target_dir}".format(**vars()))
      try:
          getter = "wget {url} -O -"
          extract = (
              "tar x{compression} --strip-components=1 -C {target_dir}"
          )
          cmd = " | ".join((getter, extract))
          runner(
              cmd.format(compression=infer_compression(url), **vars())
          )
          with pushd(target_dir):
              yield target_dir
      finally:
          runner("rm -Rf {target_dir}".format(**vars()))
  
imports: import os
  import subprocess
  import contextlib
  import functools
  import tempfile
  import shutil
  import operator
  import warnings
label_desc: Use image node_id 2 for calling a global function with example usage: tarball_context(url, target_dir, runner, pushd) without return types