code: def shellcmd(
      img_path,
      cmd,
      args="",
      quiet=False,
      envvars=None,
      shell_executable=None,
      container_workdir=None,
      is_python_script=False,
  ):
      """Execute shell command inside singularity container given optional args
      and environment variables to be passed."""
  
      if envvars:
          envvars = " ".join(
              f"SINGULARITYENV_{k}={v}" for k, v in envvars.items()
          )
      else:
          envvars = ""
  
      if shell_executable is None:
          shell_executable = "sh"
      else:
          # Ensure to just use the name of the executable, not a path,
          # because we cannot be sure where it is located in the container.
          shell_executable = os.path.split(shell_executable)[-1]
  
      if is_python_script:
          # mount host snakemake module into container
          args += " ".join(
              f" --bind {repr(searchpath)}:{repr(mountpoint)}"
              for searchpath, mountpoint in zip(
                  get_snakemake_searchpaths(),
                  get_snakemake_searchpath_mountpoints(),
              )
          )
  
      if container_workdir:
          args += f" --pwd {repr(container_workdir)}"
  
      cmd = "{} singularity {} exec --home {} {} {} {} -c '{}'".format(
          envvars,
          "--quiet --silent" if quiet else "",
          repr(os.getcwd()),
          args,
          img_path,
          shell_executable,
          cmd.replace("'", r"'\''"),
      )
      logger.debug(cmd)
      return cmd
  
imports: from pathlib import Path
  import subprocess
  import shutil
  import os
  import hashlib
  from snakemake.common import get_snakemake_searchpaths, is_local_file, parse_uri
  from snakemake.exceptions import WorkflowError
  from snakemake.logging import logger
  from snakemake_interface_common.utils import lazy_property
label_desc: Use image node_id 2 for calling a global function with example usage: shellcmd(img_path, cmd, args, quiet, envvars, shell_executable, container_workdir, is_python_script) and returns: cmd