code: def init(
      config: Config,
      directory: str,
      template: str = "generic",
      package: bool = False,
  ) -> None:
      """Initialize a new scripts directory.
  
      :param config: a :class:`.Config` object.
  
      :param directory: string path of the target directory
  
      :param template: string name of the migration environment template to
       use.
  
      :param package: when True, write ``__init__.py`` files into the
       environment location as well as the versions/ location.
  
      """
  
      if os.access(directory, os.F_OK) and os.listdir(directory):
          raise util.CommandError(
              "Directory %s already exists and is not empty" % directory
          )
  
      template_dir = os.path.join(
          config.get_template_directory(), template
      )
      if not os.access(template_dir, os.F_OK):
          raise util.CommandError("No such template %r" % template)
  
      if not os.access(directory, os.F_OK):
          with util.status(
              f"Creating directory {os.path.abspath(directory)!r}",
              **config.messaging_opts,
          ):
              os.makedirs(directory)
  
      versions = os.path.join(directory, "versions")
      with util.status(
          f"Creating directory {os.path.abspath(versions)!r}",
          **config.messaging_opts,
      ):
          os.makedirs(versions)
  
      script = ScriptDirectory(directory)
  
      config_file: str | None = None
      for file_ in os.listdir(template_dir):
          file_path = os.path.join(template_dir, file_)
          if file_ == "alembic.ini.mako":
              assert config.config_file_name is not None
              config_file = os.path.abspath(config.config_file_name)
              if os.access(config_file, os.F_OK):
                  util.msg(
                      f"File {config_file!r} already exists, skipping",
                      **config.messaging_opts,
                  )
              else:
                  script._generate_template(
                      file_path, config_file, script_location=directory
                  )
          elif os.path.isfile(file_path):
              output_file = os.path.join(directory, file_)
              script._copy_file(file_path, output_file)
  
      if package:
          for path in [
              os.path.join(os.path.abspath(directory), "__init__.py"),
              os.path.join(os.path.abspath(versions), "__init__.py"),
          ]:
              with util.status(
                  f"Adding {path!r}", **config.messaging_opts
              ):
                  with open(path, "w"):
                      pass
  
      assert config_file is not None
      util.msg(
          "Please edit configuration/connection/logging "
          f"settings in {config_file!r} before proceeding.",
          **config.messaging_opts,
      )
  
imports: from __future__ import annotations
  import os
  from typing import List
  from typing import Optional
  from typing import TYPE_CHECKING
  from typing import Union
  from .None import autogenerate
  from .None import util
  from .runtime.environment import EnvironmentContext
  from .script import ScriptDirectory
label_desc: Use image node_id 2 for calling a global function with example usage: init(config, directory, template, package) without return types