class_docstr: This class exists to allow virtual environment creation to be
  customized. The constructor parameters determine the builder's
  behaviour when called upon to create a virtual environment.
  
  By default, the builder makes the system (global) site-packages dir
  *un*available to the created environment.
  
  If invoked using the Python -m option, the default is to use copying
  on Windows platforms but symlinks elsewhere. If instantiated some
  other way, the default is to *not* use symlinks.
  
  :param system_site_packages: If True, the system (global) site-packages
                               dir is available to created environments.
  :param clear: If True, delete the contents of the environment directory if
                it already exists, before environment creation.
  :param symlinks: If True, attempt to symlink rather than copy files into
                   virtual environment.
  :param upgrade: If True, upgrade an existing virtual environment.
  :param with_pip: If True, ensure pip is installed in the virtual
                   environment
  :param prompt: Alternative terminal prefix for the environment.
  :param upgrade_deps: Update the base venv modules to the latest on PyPI
class_docstr_tok: ["This","class","exists","to","allow","virtual","environment","creation","to","be","customized",".","The","constructor","parameters","determine","the","builder's","behaviour","when","called","upon","to","create","a","virtual","environment",".","By","default",",","the","builder","makes","the","system","(","global",")","site-packages","dir","*","un","*","available","to","the","created","environment",".","If","invoked","using","the","Python","-m","option",",","the","default","is","to","use","copying","on","Windows","platforms","but","symlinks","elsewhere",".","If","instantiated","some","other","way",",","the","default","is","to","*","not","*","use","symlinks",".",":","param","system_site_packages",":","If","True",",","the","system","(","global",")","site-packages","dir","is","available","to","created","environments",".",":","param","clear",":","If","True",",","delete","the","contents","of","the","environment","directory","if","it","already","exists",",","before","environment","creation",".",":","param","symlinks",":","If","True",",","attempt","to","symlink","rather","than","copy","files","into","virtual","environment",".",":","param","upgrade",":","If","True",",","upgrade","an","existing","virtual","environment",".",":","param","with_pip",":","If","True",",","ensure","pip","is","installed","in","the","virtual","environment",":","param","prompt",":","Alternative","terminal","prefix","for","the","environment",".",":","param","upgrade_deps",":","Update","the","base","venv","modules","to","the","latest","on","PyPI"]
docstr: Create the directories for the environment.
  
  Returns a context object which holds paths in the environment,
  for use by subsequent logic.
docstr_tok: ["Create","the","directories","for","the","environment",".","Returns","a","context","object","which","holds","paths","in","the","environment",",","for","use","by","subsequent","logic","."]
code: def ensure_directories(self, env_dir):
      """
      Create the directories for the environment.
  
      Returns a context object which holds paths in the environment,
      for use by subsequent logic.
      """
  
      def create_if_needed(d):
          if not os.path.exists(d):
              os.makedirs(d)
          elif os.path.islink(d) or os.path.isfile(d):
              raise ValueError("Unable to create directory %r" % d)
  
      if os.pathsep in os.fspath(env_dir):
          raise ValueError(
              f"Refusing to create a venv in {env_dir} because "
              f"it contains the PATH separator {os.pathsep}."
          )
      if os.path.exists(env_dir) and self.clear:
          self.clear_directory(env_dir)
      context = types.SimpleNamespace()
      context.env_dir = env_dir
      context.env_name = os.path.split(env_dir)[1]
      prompt = (
          self.prompt if self.prompt is not None else context.env_name
      )
      context.prompt = "(%s) " % prompt
      create_if_needed(env_dir)
      executable = sys._base_executable
      if not executable:  # see gh-96861
          raise ValueError(
              "Unable to determine path to the running "
              "Python interpreter. Provide an explicit path or "
              "check that your PATH environment variable is "
              "correctly set."
          )
      dirname, exename = os.path.split(os.path.abspath(executable))
      context.executable = executable
      context.python_dir = dirname
      context.python_exe = exename
      binpath = self._venv_path(env_dir, "scripts")
      incpath = self._venv_path(env_dir, "include")
      libpath = self._venv_path(env_dir, "purelib")
  
      context.inc_path = incpath
      create_if_needed(incpath)
      create_if_needed(libpath)
      # Issue 21197: create lib64 as a symlink to lib on 64-bit non-OS X POSIX
      if (
          (sys.maxsize > 2**32)
          and (os.name == "posix")
          and (sys.platform != "darwin")
      ):
          link_path = os.path.join(env_dir, "lib64")
          if not os.path.exists(link_path):  # Issue #21643
              os.symlink("lib", link_path)
      context.bin_path = binpath
      context.bin_name = os.path.relpath(binpath, env_dir)
      context.env_exe = os.path.join(binpath, exename)
      create_if_needed(binpath)
      # Assign and update the command to use when launching the newly created
      # environment, in case it isn't simply the executable script (e.g. bpo-45337)
      context.env_exec_cmd = context.env_exe
      if sys.platform == "win32":
          # bpo-45337: Fix up env_exec_cmd to account for file system redirections.
          # Some redirects only apply to CreateFile and not CreateProcess
          real_env_exe = os.path.realpath(context.env_exe)
          if os.path.normcase(real_env_exe) != os.path.normcase(
              context.env_exe
          ):
              logger.warning(
                  "Actual environment location may have moved due to "
                  "redirects, links or junctions.\n"
                  '  Requested location: "%s"\n'
                  '  Actual location:    "%s"',
                  context.env_exe,
                  real_env_exe,
              )
              context.env_exec_cmd = real_env_exe
      return context
  
imports: import logging
  import os
  import shutil
  import subprocess
  import sys
  import sysconfig
  import types
label_desc: Use image node_id 5 for calling the EnvBuilder obj's underlying member method code with example usage: obj.ensure_directories(env_dir) and returns: context