virtual-env.cfg 1.62 KB
Newer Older
1 2 3 4 5 6
[buildout]
extends =
	../pygolang/buildout.cfg

[virtual-env-base]
recipe = slapos.recipe.build
7 8
name = ${:_buildout_section_name_}
default-instance = true
9 10 11
init =
  from zc.buildout.easy_install import working_set
  import os
12
  name = options['name']
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  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())
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

  if is_true(options.get('default-instance')):
    self.buildout.parse("""
    [.%(name)s.instance]
    recipe = slapos.recipe.template
    output = ${buildout:directory}/instance.cfg
    depends = ${slapos-cookbook:recipe}
    inline =
      [buildout]
      parts = publish

      eggs-directory = ${buildout:eggs-directory}
      develop-eggs-directory = ${buildout:develop-eggs-directory}

      [publish]
      recipe = slapos.cookbook:publish
      activate-script = %(location)s
    """ % locals())

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
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