code: def staging_env(create=True, template="generic", sourceless=False):
      cfg = _testing_config()
      if create:
          path = os.path.join(_get_staging_directory(), "scripts")
          assert not os.path.exists(path), (
              "staging directory %s already exists; poor cleanup?"
              % path
          )
  
          command.init(cfg, path, template=template)
          if sourceless:
              try:
                  # do an import so that a .pyc/.pyo is generated.
                  util.load_python_file(path, "env.py")
              except AttributeError:
                  # we don't have the migration context set up yet
                  # so running the .env py throws this exception.
                  # theoretically we could be using py_compiler here to
                  # generate .pyc/.pyo without importing but not really
                  # worth it.
                  pass
              assert sourceless in (
                  "pep3147_envonly",
                  "simple",
                  "pep3147_everything",
              ), sourceless
              make_sourceless(
                  os.path.join(path, "env.py"),
                  "pep3147" if "pep3147" in sourceless else "simple",
              )
  
      sc = script.ScriptDirectory.from_config(cfg)
      return sc
  
imports: import importlib.machinery
  import os
  import shutil
  import textwrap
  from sqlalchemy.testing import config
  from sqlalchemy.testing import provision
  from .None import util
  from ..None import command
  from ..None import script
  from ..None import util
  from ..script import Script
  from ..script import ScriptDirectory
label_desc: Use image node_id 2 for calling a global function with example usage: staging_env(create, template, sourceless) and returns: sc