code: def execute_script(self, fname, edit=None):
      import nbformat
  
      fname_out = self.log.get("notebook", None)
      if fname_out is None or edit:
          output_parameter = ""
      else:
          fname_out = os.path.join(os.getcwd(), fname_out)
          output_parameter = "--output {fname_out:q}"
  
      with tempfile.TemporaryDirectory() as tmp:
          if edit is not None:
              assert not edit.draft_only
              logger.info("Opening notebook for editing.")
              cmd = (
                  "jupyter notebook --browser ':' --no-browser --log-level ERROR --ip {edit.ip} --port {edit.port} "
                  "--NotebookApp.quit_button=True {{fname:q}}".format(
                      edit=edit
                  )
              )
          else:
              cmd = (
                  "jupyter-nbconvert --log-level ERROR --execute {output_parameter} "
                  "--to notebook --ExecutePreprocessor.timeout=-1 {{fname:q}}".format(
                      output_parameter=output_parameter
                  )
              )
  
          if ON_WINDOWS:
              fname = fname.replace("\\", "/")
              fname_out = (
                  fname_out.replace("\\", "/")
                  if fname_out
                  else fname_out
              )
  
          self._execute_cmd(
              cmd,
              fname_out=fname_out,
              fname=fname,
              additional_envvars={"IPYTHONDIR": tmp},
          )
  
          if edit:
              logger.info("Saving modified notebook.")
              nb = nbformat.read(fname, as_version=4)
  
              self.remove_preamble_cell(nb)
  
              # clean up all outputs
              for cell in nb["cells"]:
                  if "outputs" in cell:
                      cell["outputs"] = []
                  if "execution_count" in cell:
                      cell["execution_count"] = None
  
              nbformat.write(nb, self.local_path)
  
imports: from abc import abstractmethod
  import os
  from pathlib import Path
  import tempfile
  import re
  from snakemake.exceptions import WorkflowError
  from snakemake.script import get_source, ScriptBase, PythonScript, RScript
  from snakemake.logging import logger
  from snakemake.common import is_local_file
  from snakemake.common import ON_WINDOWS
  from snakemake.sourcecache import SourceCache, infer_source_file
  from snakemake.utils import format
label_desc: Use image node_id 4 for calling the JupyterNotebook obj's underlying member method code with example usage: obj.execute_script(fname, edit) without return types