[buildout]
extends =
	../pygolang/buildout.cfg

[virtual-env-base]
recipe = slapos.recipe.build
_name = ${:_buildout_section_name_}
init =
  from zc.buildout.easy_install import working_set
  import os
  name = options['_name']
  eggs = options['eggs']
  try:
    scripts = "scripts = " + options['scripts']
  except KeyError:
    scripts = ""

  self.buildout.parse("""
  [.%(name)s.install-eggs]
  recipe = zc.recipe.egg
  eggs = %(eggs)s
  %(scripts)s

  [.%(name)s.install-interpreter]
  <= python-interpreter
  eggs += %(eggs)s
  """ % locals())
install =
  with open(location, "w") as f:
    f.write(options['template'] % {
      "path" : self.buildout['buildout']['bin-directory'],
      "name" : self.name,
    })

# Template virtual env for bash shell in posix
[virtual-env-base:posix]
template =
  deactivate () {
    set PATH PS1
    while [ "$1" ]; do
      eval "if [ \"\$_OLD_VENV_$1\" ]; then $1=\$_OLD_VENV_$1; else unset $1; fi; unset \$_OLD_VENV_$1"
      shift
    done
    unset -f deactivate
  }


  VENV_PATH=%(path)s
  _OLD_VENV_PATH=$PATH
  _OLD_VENV_PS1=$PS1
  PATH=$VENV_PATH:$PATH
  PS1='(%(name)s) '$PS1
