code: def patch_script_directory(graph):
      
      temporary_dir = mkdtemp()
      from_config_original = getattr(ScriptDirectory, "from_config")
      run_env_original = getattr(ScriptDirectory, "run_env")
  
      # use a temporary directory for the revision template
      with open(join(temporary_dir, "script.py.mako"), "w") as file_:
          file_.write(make_script_py_mako())
          file_.flush()
  
      # monkey patch our script directory and migration logic
      setattr(ScriptDirectory, "from_config", classmethod(make_script_directory))
      setattr(ScriptDirectory, "run_env", run_online_migration)
      setattr(ScriptDirectory, "graph", graph)
      try:
          yield temporary_dir
      finally:
          # cleanup
          delattr(ScriptDirectory, "graph")
          setattr(ScriptDirectory, "run_env", run_env_original)
          setattr(ScriptDirectory, "from_config", from_config_original)
          rmtree(temporary_dir)
docs: Monkey patch the `ScriptDirectory` class, working around configuration assumptions.
  
      Changes include:
        - Using a generated, temporary directory (with a generated, temporary `script.py.mako`)
          instead of the assumed script directory.
        - Using our `make_script_directory` function instead of the default `ScriptDirectory.from_config`.
        - Using our `run_online_migration` function instead of the default `ScriptDirectory.run_env`.
        - Injecting the current object graph.