capistrano-pyenv 1.0.0rc1 → 1.0.0rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/capistrano-pyenv/version.rb +1 -1
- data/lib/capistrano-pyenv.rb +66 -35
- data/test/config/deploy.rb +108 -12
- metadata +2 -2
data/lib/capistrano-pyenv.rb
CHANGED
@@ -17,8 +17,22 @@ module Capistrano
|
|
17
17
|
_cset(:pyenv_bin) {
|
18
18
|
File.join(pyenv_bin_path, "pyenv")
|
19
19
|
}
|
20
|
-
|
21
|
-
|
20
|
+
def pyenv_command(options={})
|
21
|
+
environment = pyenv_environment.merge(options.fetch(:env, {}))
|
22
|
+
environment["PYENV_VERSION"] = options[:version] if options.key?(:version)
|
23
|
+
if environment.empty?
|
24
|
+
pyenv_bin
|
25
|
+
else
|
26
|
+
env = (["env"] + environment.map { |k, v| "#{k}=#{v.dump}" }).join(" ")
|
27
|
+
"#{env} #{pyenv_bin}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
_cset(:pyenv_cmd) { pyenv_command(:version => pyenv_python_version) } # this declares PYENV_VERSION.
|
31
|
+
_cset(:pyenv_environment) {
|
32
|
+
{
|
33
|
+
"PYENV_ROOT" => pyenv_path,
|
34
|
+
"PATH" => [ pyenv_shims_path, pyenv_bin_path, "$PATH" ].join(":"),
|
35
|
+
}
|
22
36
|
}
|
23
37
|
_cset(:pyenv_repository, 'git://github.com/yyuu/pyenv.git')
|
24
38
|
_cset(:pyenv_branch, 'master')
|
@@ -52,12 +66,24 @@ module Capistrano
|
|
52
66
|
|
53
67
|
desc("Setup pyenv.")
|
54
68
|
task(:setup, :except => { :no_release => true }) {
|
69
|
+
#
|
70
|
+
# skip installation if the requested version has been installed.
|
71
|
+
#
|
72
|
+
begin
|
73
|
+
installed = pyenv_python_versions.include?(pyenv_python_version)
|
74
|
+
rescue
|
75
|
+
installed = false
|
76
|
+
end
|
77
|
+
_setup unless installed
|
78
|
+
configure if pyenv_setup_shell
|
79
|
+
}
|
80
|
+
after "deploy:setup", "pyenv:setup"
|
81
|
+
|
82
|
+
task(:_setup, :except => { :no_release => true }) {
|
55
83
|
dependencies if pyenv_install_dependencies
|
56
84
|
update
|
57
|
-
configure if pyenv_setup_shell
|
58
85
|
build
|
59
86
|
}
|
60
|
-
after 'deploy:setup', 'pyenv:setup'
|
61
87
|
|
62
88
|
def _update_repository(destination, options={})
|
63
89
|
configuration = Capistrano::Configuration.new()
|
@@ -97,10 +123,7 @@ module Capistrano
|
|
97
123
|
}
|
98
124
|
|
99
125
|
def _setup_default_environment
|
100
|
-
|
101
|
-
env["PYENV_ROOT"] = pyenv_path
|
102
|
-
env["PATH"] = [ pyenv_shims_path, pyenv_bin_path, env.fetch("PATH", "$PATH") ].join(":")
|
103
|
-
set(:default_environment, env)
|
126
|
+
set(:default_environment, default_environment.merge(pyenv_environment))
|
104
127
|
end
|
105
128
|
|
106
129
|
_cset(:pyenv_setup_default_environment) {
|
@@ -111,7 +134,7 @@ module Capistrano
|
|
111
134
|
true
|
112
135
|
end
|
113
136
|
}
|
114
|
-
# workaround for `
|
137
|
+
# workaround for loading `capistrano-rbenv` later than `capistrano/ext/multistage`.
|
115
138
|
# https://github.com/yyuu/capistrano-rbenv/pull/5
|
116
139
|
if top.namespaces.key?(:multistage)
|
117
140
|
after "multistage:ensure" do
|
@@ -119,7 +142,15 @@ module Capistrano
|
|
119
142
|
end
|
120
143
|
else
|
121
144
|
on :start do
|
122
|
-
|
145
|
+
if top.namespaces.key?(:multistage)
|
146
|
+
# workaround for loading `capistrano-rbenv` earlier than `capistrano/ext/multistage`.
|
147
|
+
# https://github.com/yyuu/capistrano-rbenv/issues/7
|
148
|
+
after "multistage:ensure" do
|
149
|
+
_setup_default_environment if pyenv_setup_default_environment
|
150
|
+
end
|
151
|
+
else
|
152
|
+
_setup_default_environment if pyenv_setup_default_environment
|
153
|
+
end
|
123
154
|
end
|
124
155
|
end
|
125
156
|
|
@@ -270,52 +301,51 @@ module Capistrano
|
|
270
301
|
end
|
271
302
|
end
|
272
303
|
pyenv.exec("#{python} --version") # chck if python is executable
|
273
|
-
pyenv.global(pyenv_python_version)
|
304
|
+
pyenv.global(pyenv_python_version) if fetch(:pyenv_setup_global_version, true)
|
274
305
|
}
|
275
306
|
|
276
307
|
# call `pyenv rehash` to update shims.
|
277
308
|
def rehash(options={})
|
278
|
-
|
309
|
+
invoke_command("#{pyenv_command} rehash", options)
|
279
310
|
end
|
280
311
|
|
281
312
|
def global(version, options={})
|
282
|
-
|
313
|
+
invoke_command("#{pyenv_command} global #{version.dump}", options)
|
283
314
|
end
|
284
315
|
|
285
316
|
def local(version, options={})
|
286
317
|
path = options.delete(:path)
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
end
|
318
|
+
execute = []
|
319
|
+
execute << "cd #{path.dump}" if path
|
320
|
+
execute << "#{pyenv_command} local #{version.dump}"
|
321
|
+
invoke_command(execute.join(" && "), options)
|
292
322
|
end
|
293
323
|
|
294
324
|
def which(command, options={})
|
295
325
|
path = options.delete(:path)
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
326
|
+
version = ( options.delete(:version) || pyenv_python_version )
|
327
|
+
execute = []
|
328
|
+
execute << "cd #{path.dump}" if path
|
329
|
+
execute << "#{pyenv_command(:version => version)} which #{command.dump}"
|
330
|
+
capture(execute.join(" && "), options).strip
|
301
331
|
end
|
302
332
|
|
303
333
|
def exec(command, options={})
|
304
334
|
# users of pyenv.exec must sanitize their command line.
|
305
335
|
path = options.delete(:path)
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
336
|
+
version = ( options.delete(:version) || pyenv_python_version )
|
337
|
+
execute = []
|
338
|
+
execute << "cd #{path.dump}" if path
|
339
|
+
execute << "#{pyenv_command(:version => version)} exec #{command}"
|
340
|
+
invoke_command(execute.join(" && "), options)
|
311
341
|
end
|
312
342
|
|
313
343
|
def versions(options={})
|
314
|
-
capture("#{
|
344
|
+
capture("#{pyenv_command} versions --bare", options).split(/(?:\r?\n)+/)
|
315
345
|
end
|
316
346
|
|
317
347
|
def available_versions(options={})
|
318
|
-
capture("#{
|
348
|
+
capture("#{pyenv_command} install --complete", options).split(/(?:\r?\n)+/)
|
319
349
|
end
|
320
350
|
|
321
351
|
_cset(:pyenv_install_python_threads) {
|
@@ -323,15 +353,16 @@ module Capistrano
|
|
323
353
|
}
|
324
354
|
# create build processes as many as processor count
|
325
355
|
_cset(:pyenv_make_options) { "-j #{pyenv_install_python_threads}" }
|
356
|
+
_cset(:pyenv_configure_options, nil)
|
326
357
|
def install(version, options={})
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
358
|
+
environment = {}
|
359
|
+
environment["CONFIGURE_OPTS"] = pyenv_configure_options.to_s if pyenv_configure_options
|
360
|
+
environment["MAKE_OPTS"] = pyenv_make_options.to_s if pyenv_make_options
|
361
|
+
invoke_command("#{pyenv_command(:env => environment)} install #{version.dump}", options)
|
331
362
|
end
|
332
363
|
|
333
364
|
def uninstall(version, options={})
|
334
|
-
|
365
|
+
invoke_command("#{pyenv_command} uninstall -f #{version.dump}", options)
|
335
366
|
end
|
336
367
|
|
337
368
|
def virtualenv(version, venv, options={})
|
data/test/config/deploy.rb
CHANGED
@@ -20,40 +20,136 @@ role :db, "192.168.33.10", :primary => true
|
|
20
20
|
$LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
|
21
21
|
require "capistrano-pyenv"
|
22
22
|
|
23
|
-
|
23
|
+
task(:test_all) {
|
24
|
+
find_and_execute_task("test_default")
|
25
|
+
find_and_execute_task("test_with_virtualenv")
|
26
|
+
find_and_execute_task("test_without_global")
|
27
|
+
}
|
28
|
+
|
29
|
+
namespace(:test_default) {
|
24
30
|
task(:default) {
|
25
|
-
find_and_execute_task("pyenv:setup")
|
26
31
|
methods.grep(/^test_/).each do |m|
|
27
32
|
send(m)
|
28
33
|
end
|
29
|
-
|
34
|
+
}
|
35
|
+
before "test_default", "test_default:setup"
|
36
|
+
after "test_default", "test_default:teardown"
|
37
|
+
|
38
|
+
task(:setup) {
|
39
|
+
find_and_execute_task("pyenv:setup")
|
30
40
|
}
|
31
41
|
|
32
|
-
task(:
|
42
|
+
task(:teardown) {
|
43
|
+
}
|
44
|
+
|
45
|
+
task(:test_pyenv) {
|
33
46
|
run("pyenv --version")
|
34
47
|
}
|
35
48
|
|
36
|
-
|
49
|
+
## standard
|
50
|
+
task(:test_pyenv_exec) {
|
51
|
+
pyenv.exec("python --version")
|
52
|
+
}
|
53
|
+
|
54
|
+
task(:test_run_pyenv_exec) {
|
37
55
|
run("pyenv exec python --version")
|
38
56
|
}
|
39
57
|
|
40
|
-
|
58
|
+
## with path
|
59
|
+
task(:test_pyenv_exec_with_path) {
|
60
|
+
pyenv.exec("python -c 'import os;assert os.getcwd()==\"/\"'", :path => "/")
|
61
|
+
}
|
62
|
+
|
63
|
+
# task(:test_pyenv_exec_python_via_sudo_with_path) {
|
64
|
+
# # capistrano does not provide safer way to invoke multiple commands via sudo.
|
65
|
+
# pyenv.exec("python -c 'import os;assert os.getcwd()==\"/\" and os.getuid()==0'", :path => "/", :via => :sudo )
|
66
|
+
# }
|
67
|
+
|
68
|
+
## via sudo
|
69
|
+
task(:test_pyenv_exec_via_sudo) {
|
70
|
+
pyenv.exec("python -c 'import os;assert os.getuid()==0'", :via => :sudo)
|
71
|
+
}
|
72
|
+
|
73
|
+
task(:test_run_sudo_pyenv_exec) {
|
74
|
+
# we may not be able to invoke pyenv since sudo may reset $PATH.
|
75
|
+
# if you prefer to invoke pyenv via sudo, call it with absolute path.
|
76
|
+
# run("#{sudo} pyenv exec python -c 'import os;assert os.getuid()==0'")
|
77
|
+
run("#{sudo} #{pyenv_cmd} exec python -c 'import os;assert os.getuid()==0'")
|
78
|
+
}
|
79
|
+
|
80
|
+
task(:test_sudo_pyenv_exec) {
|
81
|
+
sudo("#{pyenv_cmd} exec python -c 'import os;assert os.getuid()==0'")
|
82
|
+
}
|
83
|
+
|
84
|
+
## pip
|
85
|
+
task(:test_pyenv_exec_pip) {
|
41
86
|
run("pyenv exec pip --version")
|
42
87
|
}
|
88
|
+
}
|
89
|
+
|
90
|
+
namespace(:test_with_virtualenv) {
|
91
|
+
task(:default) {
|
92
|
+
methods.grep(/^test_/).each do |m|
|
93
|
+
send(m)
|
94
|
+
end
|
95
|
+
}
|
96
|
+
before "test_with_virtualenv", "test_with_virtualenv:setup"
|
97
|
+
after "test_with_virtualenv", "test_with_virtualenv:teardown"
|
43
98
|
|
44
|
-
task(:
|
45
|
-
python_version = pyenv_python_version
|
99
|
+
task(:setup) {
|
46
100
|
set(:pyenv_use_virtualenv, true)
|
101
|
+
set(:pyenv_virtualenv_python_version, pyenv_python_version)
|
47
102
|
set(:pyenv_python_version, "venv")
|
48
|
-
set(:pyenv_virtualenv_python_version, python_version)
|
49
|
-
|
50
103
|
find_and_execute_task("pyenv:setup")
|
51
|
-
|
104
|
+
}
|
52
105
|
|
106
|
+
task(:teardown) {
|
53
107
|
set(:pyenv_use_virtualenv, false)
|
54
|
-
set(:pyenv_python_version,
|
108
|
+
set(:pyenv_python_version, pyenv_virtualenv_python_version)
|
55
109
|
set(:pyenv_virtualenv_python_version, nil)
|
56
110
|
}
|
111
|
+
|
112
|
+
task(:test_pyenv_exec) {
|
113
|
+
pyenv.exec("python --version")
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
namespace(:test_without_global) {
|
118
|
+
task(:default) {
|
119
|
+
methods.grep(/^test_/).each do |m|
|
120
|
+
send(m)
|
121
|
+
end
|
122
|
+
}
|
123
|
+
before "test_without_global", "test_without_global:setup"
|
124
|
+
after "test_without_global", "test_without_global:teardown"
|
125
|
+
|
126
|
+
task(:setup) {
|
127
|
+
version_file = File.join(pyenv_path, "version")
|
128
|
+
run("mv -f #{version_file} #{version_file}.orig")
|
129
|
+
set(:pyenv_setup_global_version, false)
|
130
|
+
find_and_execute_task("pyenv:setup")
|
131
|
+
run("test \! -f #{version_file.dump}")
|
132
|
+
}
|
133
|
+
|
134
|
+
task(:teardown) {
|
135
|
+
version_file = File.join(pyenv_path, "version")
|
136
|
+
run("mv -f #{version_file}.orig #{version_file}")
|
137
|
+
}
|
138
|
+
|
139
|
+
## standard
|
140
|
+
task(:test_pyenv_exec_python) {
|
141
|
+
pyenv.exec("python --version")
|
142
|
+
}
|
143
|
+
|
144
|
+
## with path
|
145
|
+
task(:test_pyenv_exec_python_with_path) {
|
146
|
+
pyenv.exec("python -c 'import os;assert os.getcwd()==\"/\"'", :path => "/")
|
147
|
+
}
|
148
|
+
|
149
|
+
## via sudo
|
150
|
+
task(:test_pyenv_exec_python_via_sudo) {
|
151
|
+
pyenv.exec("python -c 'import os;assert os.getuid()==0'", :via => :sudo)
|
152
|
+
}
|
57
153
|
}
|
58
154
|
|
59
155
|
# vim:set ft=ruby sw=2 ts=2 :
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-pyenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0rc2
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|