Class: Vx::Builder::ScriptBuilder::Python

Inherits:
Base
  • Object
show all
Defined in:
lib/vx/builder/script_builder/python.rb

Constant Summary collapse

DEFAULT_PYTHON =
'2.7'
VIRTUALENV_ROOT =
"~/.python-virtualenv"
PIP_DOWNLOADS =
"~/.pip-downloads"
PIP_OPTS =
" --download-cache=#{PIP_DOWNLOADS}"

Instance Attribute Summary

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#deploy?, #do_after_deploy, #do_announce, #do_before_deploy, #do_before_install, #do_before_script, #do_cache_key, #do_cached_directories, #do_deploy_script, #do_init, #do_install, #do_script

Methods included from Helper::VxvmInstall

#vxvm_install

Methods included from Helper::TraceShCommand

#trace_sh_command

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vx/builder/script_builder/python.rb', line 12

def call(env)
  if enabled?(env)

    py_v = python_version(env)

    vxvm_install(env, 'python', py_v)

    do_init(env) do |i|
      i << "export TRAVIS_PYTHON_VERSION=#{py_v}" # for tornado
    end

    do_before_install(env) do |i|
      i << trace_sh_command("virtualenv #{VIRTUALENV_ROOT}")
      i << trace_sh_command("source #{VIRTUALENV_ROOT}/bin/activate")
    end

    do_announce(env) do |i|
      i << trace_sh_command("python --version")
      i << trace_sh_command("pip --version")
    end

    do_install(env) do |i|
      i << "if [ -f Requirements.txt ] ; then \n #{trace_sh_command "pip install -r Requirements.txt #{PIP_OPTS}"}\nfi"
      i << "if [ -f requirements.txt ] ; then \n #{trace_sh_command "pip install -r requirements.txt #{PIP_OPTS}"}\nfi"
      i << "if [ -f setup.py ] ; then \n #{trace_sh_command "python setup.py install"}\nfi"
    end

    do_before_script(env) do |i|
      i << trace_sh_command("vx_builder python:django:settings")
    end

    do_script(env) do |i|
      script =<<EOF
      if [[ -f manage.py ]] ; then
        #{trace_sh_command 'python manage.py test'}
      elif [[ -f setup.py ]] ; then
        #{trace_sh_command 'python setup.py test'}
      else
        #{trace_sh_command 'nosetests'}
      fi
EOF
      i << script
    end

    do_cache_key(env) do |i|
      i << "python-#{py_v}"
    end

    do_cached_directories(env) do |i|
      i << PIP_DOWNLOADS
    end
  end

  app.call(env)
end