Module: Evoker

Defined in:
lib/evoker.rb,
lib/evoker/python.rb,
lib/evoker/version.rb

Overview

Evoker is a tool to manage external dependencies of a project using Rake to run downloads.

Defined Under Namespace

Modules: VERSION Classes: EntityTask

Constant Summary collapse

ENTITIES =

Rake::FileList of defined entities

Examples:

can be used as dependency for the default target

task :default => Evoker::ENTITIES
Rake::FileList[]

Class Method Summary collapse

Class Method Details

.entity(name, *args) {|Rake::Task| ... } ⇒ EntityTask

Base entity definition (wrapper over EntityTask)

Parameters:

Yields:

  • (Rake::Task)

    block executed to populate target directory

Returns:



68
69
70
# File 'lib/evoker.rb', line 68

def entity(name, *args, &block)
  Evoker::EntityTask.define_task(name, *args, &block)
end

.git(name, opts = {}) ⇒ Object

Check out Git repository



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/evoker.rb', line 125

def git(name, opts={})
  opts[:git] ||= "git"
  entity name do |t|
    cmd = "#{opts[:git]} clone"
    cmd << " #{opts[:clone_args]}" if opts[:clone_args]
    cmd << " #{t.config[:clone_args]}" if t.config[:clone_args]
    cmd << " #{opts[:url]}" if opts[:url]
    cmd << " #{t.config[:url]}" if t.config[:url]
    cmd << " #{t.name}"

    if rev = opts[:revision] || t.config[:revision]
      cmd << " && cd #{t.name}" \
        " && #{opts[:git]} checkout -b evoker-checkout #{rev}"
    end
    sh cmd
  end
end

.pip_requirements(file, args = {}) ⇒ Object

Download Python requirements using pip



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/evoker/python.rb', line 55

def pip_requirements(file, args={})
  stampfile = "#{file}.stamp"
  if args[:virtualenv]
    args[:pip] = "#{args[:virtualenv]}/bin/pip"
  else
    args[:pip] ||= 'pip'
  end
  pip_cmd = "#{args[:pip]}"
  pip_cmd << " #{args[:args]}" if args[:args]
  pip_cmd << " install"
  pip_cmd << " #{args[:install_args]}" if args[:install_args]
  pip_cmd << " -r #{file}"

  t = file stampfile => file do
    sh pip_cmd
    File.open(stampfile, 'w') { |f| f.write(DateTime::now.to_s) }
  end
  task t => args[:virtualenv] if args[:virtualenv]
  CLOBBER.add t.name
  ENTITIES.add t.name
  t
end

.subversion(name, opts = {}) ⇒ Object

Check out Subversion repository



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/evoker.rb', line 105

def subversion(name, opts={})
  opts[:svn] ||= "svn"
  entity name do |t|
    cmd = "#{opts[:svn]}"
    cmd << " #{opts[:svn_args]}" if opts[:svn_args]
    cmd << " #{t.config[:svn_args]}" if t.config[:svn_args]
    cmd << " checkout -q"
    cmd << " #{opts[:checkout_args]}" if opts[:checkout_args]
    cmd << " #{t.config[:checkout_args]}" if t.config[:checkout_args]
    cmd << " -r #{opts[:revision]}" if opts[:revision]
    cmd << " -r #{t.config[:revision]}" if t.config[:revision]
    cmd << " #{opts[:url]}" if opts[:url]
    cmd << " #{t.config[:url]}" if t.config[:url]
    cmd << " #{t.name}"
    sh cmd
  end
end

.virtualenv(*args) ⇒ Object

Create Python virtual environment



8
9
10
11
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
# File 'lib/evoker/python.rb', line 8

def virtualenv(*args)
  if args.last.is_a? Hash
    opts = args.pop
  else
    opts = {}
  end
  
  if opts[:download_virtualenv]
    opts[:python] ||= 'python'
    opts[:virtualenv] = "#{opts[:python]} ./virtualenv.py"
    opts[:virtualenv_version] ||= '1.6'
    opts[:virtualenv_url] ||= "http://github.com/pypa/virtualenv/raw/#{opts[:virtualenv_version]}/virtualenv.py"
    wget_virtualenv = wget opts[:virtualenv_url],
      :args => '--no-check-certificate',
      :no_entity => true
    CLOBBER.add(['virtualenv.pyc', 'setuptools-*.egg'])
  else
    opts[:virtualenv] ||= 'virtualenv'
    wget_virtualenv = nil
  end
  opts[:args] ||= nil

  virtualenv_command = "#{opts[:virtualenv]}"
  virtualenv_command << " #{opts[:args]}" if opts[:args]

  desc "Python virtual environment"
  venv = entity(*args) do |t|
    sh "#{virtualenv_command} #{t.name}"
  end

  task venv => wget_virtualenv if wget_virtualenv
  venv
end

.virtualenv_site_package(path, opts = {}) ⇒ Object

Create a symbolic link to virtualenv’s site-packages dir



44
45
46
47
48
49
50
51
# File 'lib/evoker/python.rb', line 44

def virtualenv_site_package(path, opts={})
  opts[:target] ||= File.basename(path)
  opts[:virtualenv] ||= :python
  venv = Rake::Task[opts[:virtualenv]].name
  ln_sf File.join('..', '..', '..', '..', path),
        File.join(Dir["#{venv}/lib/python*/site-packages"].first,
                  opts[:target])
end

.wget(url, opts = {}) ⇒ Object

Download a file using wget.

Parameters:

  • url (#to_s)

    address to download from

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :output_file (#to_s) — default: basename of `url`

    name of target file

  • :wget (#to_s) — default: 'wget'

    wget command to use

  • :args (#to_s) — default: nil

    custom command line arguments for wget

  • :no_entity (True, False) — default: false

    do not add task to ENTITIES



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/evoker.rb', line 82

def wget(url, opts={})
  opts[:output_file] ||= begin
                           require 'uri'
                           URI.parse(url).path.split('/').last
                         end
  opts[:wget] ||= 'wget'

  wget_command = "#{opts[:wget]} -O #{opts[:output_file]}"
  wget_command << " #{opts[:args]}" if opts[:args]
  wget_command << " #{url} && touch #{opts[:output_file]}"

  CLOBBER.add(opts[:output_file])
  ENTITIES.add(opts[:output_file]) unless opts[:no_entity]

  desc "Download #{url} as #{opts[:output_file]}"
  file opts[:output_file] do
    sh wget_command
    touch opts[:output_file]
  end
end