code: def download_url(url, download_dir, sha256=None):
      """Download and optionally verify a file.
  
      Returns the downloaded file path.
  
      If sha256 is not specified (default), the file is not verified.
  
      Raises HashMismatch if the file hash does not match the specified
      sha256 hash.
  
      If the file was already downloaded, returns its path after
      verifying it. If the file cannot be verified, raises HashMismatch
      without attempting download again. If the hash is valid but the
      download is not, the download must be deleted before trying
      again. This behavior is designed to preserve downloads at the cost
      of requiring that invalid files be explicitly deleted.
      """
  
      from urllib.parse import urlparse, unquote
      import urllib.request
  
      filename = unquote(urlparse(url).path.split("/")[-1])
  
      downloaded_path = _check_download_path(
          filename, download_dir, sha256
      )
      if not downloaded_path:
          orig_path = os.path.join(download_dir, filename)
          urllib.request.urlretrieve(url, orig_path)
          downloaded_path = _ensure_expected_download_path(
              orig_path, filename
          )
          if sha256:
              _verify_and_cache_hash(downloaded_path, sha256)
      return downloaded_path
  
imports: import logging
  import os
  import re
  import subprocess
  import sys
  from guild import util
label_desc: Use image node_id 7 for calling a global function with example usage: download_url(url, download_dir, sha256) and returns: downloaded_path