capistrano-pyenv 0.0.8 → 0.0.9

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.
@@ -1,8 +1,232 @@
1
- require "capistrano-pyenv/deploy"
2
1
  require "capistrano-pyenv/version"
2
+ require "capistrano/configuration"
3
+ require "capistrano/recipes/deploy/scm"
3
4
 
4
5
  module Capistrano
5
- module Pyenv
6
- # Your code goes here...
6
+ module PyEnv
7
+ def self.extended(configuration)
8
+ configuration.load {
9
+ namespace(:pyenv) {
10
+ _cset(:pyenv_path) {
11
+ capture("echo $HOME/.pyenv").chomp()
12
+ }
13
+ _cset(:pyenv_bin) {
14
+ File.join(pyenv_path, 'bin', 'pyenv')
15
+ }
16
+ _cset(:pyenv_cmd) { # to use custom pyenv_path, we use `env` instead of cap's default_environment.
17
+ "env PYENV_VERSION=#{pyenv_python_version.dump} #{pyenv_bin}"
18
+ }
19
+ _cset(:pyenv_repository, 'git://github.com/yyuu/pyenv.git')
20
+ _cset(:pyenv_branch, 'master')
21
+
22
+ _cset(:pyenv_plugins) {{
23
+ "pyenv-virtualenv" => { :repository => "git://github.com/yyuu/pyenv-virtualenv.git", :branch => "master" },
24
+ }}
25
+ _cset(:pyenv_plugins_options, {}) # for backward compatibility. plugin options can be configured from :pyenv_plugins.
26
+ _cset(:pyenv_plugins_path) {
27
+ File.join(pyenv_path, 'plugins')
28
+ }
29
+ _cset(:pyenv_python_version, "2.7.3")
30
+
31
+ _cset(:pyenv_use_virtualenv, false)
32
+ _cset(:pyenv_virtualenv_python_version, '2.7.3')
33
+ _cset(:pyenv_virtualenv_options, %w(--distribute --quiet --system-site-packages))
34
+
35
+ desc("Setup pyenv.")
36
+ task(:setup, :except => { :no_release => true }) {
37
+ dependencies
38
+ update
39
+ configure
40
+ build
41
+ }
42
+ after 'deploy:setup', 'pyenv:setup'
43
+
44
+ def pyenv_update_repository(destination, options={})
45
+ configuration = Capistrano::Configuration.new()
46
+ options = {
47
+ :source => proc { Capistrano::Deploy::SCM.new(configuration[:scm], configuration) },
48
+ :revision => proc { configuration[:source].head },
49
+ :real_revision => proc {
50
+ configuration[:source].local.query_revision(configuration[:revision]) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } }
51
+ },
52
+ }.merge(options)
53
+ variables.merge(options).each do |key, val|
54
+ configuration.set(key, val)
55
+ end
56
+ source = configuration[:source]
57
+ revision = configuration[:real_revision]
58
+ #
59
+ # we cannot use source.sync since it cleans up untacked files in the repository.
60
+ # currently we are just calling git sub-commands directly to avoid the problems.
61
+ #
62
+ verbose = configuration[:scm_verbose] ? nil : "-q"
63
+ run((<<-EOS).gsub(/\s+/, ' ').strip)
64
+ if [ -d #{destination} ]; then
65
+ cd #{destination} &&
66
+ #{source.command} fetch #{verbose} #{source.origin} &&
67
+ #{source.command} fetch --tags #{verbose} #{source.origin} &&
68
+ #{source.command} reset #{verbose} --hard #{revision};
69
+ else
70
+ #{source.checkout(revision, destination)};
71
+ fi
72
+ EOS
73
+ end
74
+
75
+ desc("Update pyenv installation.")
76
+ task(:update, :except => { :no_release => true }) {
77
+ pyenv_update_repository(pyenv_path, :scm => :git, :repository => pyenv_repository, :branch => pyenv_branch)
78
+ plugins.update
79
+ }
80
+
81
+ desc("Purge pyenv.")
82
+ task(:purge, :except => { :no_release => true }) {
83
+ run("rm -rf #{pyenv_path}")
84
+ }
85
+
86
+ namespace(:plugins) {
87
+ desc("Update pyenv plugins.")
88
+ task(:update, :except => { :no_release => true }) {
89
+ pyenv_plugins.each do |name, repository|
90
+ # for backward compatibility, obtain plugin options from :pyenv_plugins_options first
91
+ options = pyenv_plugins_options.fetch(name, {})
92
+ options = options.merge(Hash === repository ? repository : {:repository => repository})
93
+ pyenv_update_repository(File.join(pyenv_plugins_path, name), options.merge(:scm => :git))
94
+ end
95
+ }
96
+ }
97
+
98
+ _cset(:pyenv_configure_home) { capture("echo $HOME").chomp }
99
+ _cset(:pyenv_configure_shell) { capture("echo $SHELL").chomp }
100
+ _cset(:pyenv_configure_files) {
101
+ if fetch(:pyenv_configure_basenames, nil)
102
+ [ pyenv_configure_basenames ].flatten.map { |basename|
103
+ File.join(pyenv_configure_home, basename)
104
+ }
105
+ else
106
+ bash_profile = File.join(pyenv_configure_home, '.bash_profile')
107
+ profile = File.join(pyenv_configure_home, '.profile')
108
+ case File.basename(pyenv_configure_shell)
109
+ when /bash/
110
+ [ capture("test -f #{profile.dump} && echo #{profile.dump} || echo #{bash_profile.dump}").chomp ]
111
+ when /zsh/
112
+ [ File.join(pyenv_configure_home, '.zshenv') ]
113
+ else # other sh compatible shell such like dash
114
+ [ profile ]
115
+ end
116
+ end
117
+ }
118
+ _cset(:pyenv_configure_script) {
119
+ (<<-EOS).gsub(/^\s*/, '')
120
+ # Configured by capistrano-pyenv. Do not edit directly.
121
+ export PATH="#{pyenv_path}/bin:$PATH"
122
+ eval "$(pyenv init -)"
123
+ EOS
124
+ }
125
+ _cset(:pyenv_configure_signature, '##pyenv:configure')
126
+ task(:configure, :except => { :no_release => true }) {
127
+ if fetch(:pyenv_use_configure, true)
128
+ script = File.join('/tmp', "pyenv.#{$$}")
129
+ config = [ pyenv_configure_files ].flatten
130
+ config_map = Hash[ config.map { |f| [f, File.join('/tmp', "#{File.basename(f)}.#{$$}")] } ]
131
+ begin
132
+ execute = []
133
+ put(pyenv_configure_script, script)
134
+ config_map.each { |file, temp|
135
+ ## (1) copy original config to temporaly file and then modify
136
+ execute << "( test -f #{file} || touch #{file} )"
137
+ execute << "cp -fp #{file} #{temp}"
138
+ execute << "sed -i -e '/^#{Regexp.escape(pyenv_configure_signature)}/,/^#{Regexp.escape(pyenv_configure_signature)}/d' #{temp}"
139
+ execute << "echo #{pyenv_configure_signature.dump} >> #{temp}"
140
+ execute << "cat #{script} >> #{temp}"
141
+ execute << "echo #{pyenv_configure_signature.dump} >> #{temp}"
142
+ ## (2) update config only if it is needed
143
+ execute << "cp -fp #{file} #{file}.orig"
144
+ execute << "( diff -u #{file} #{temp} || mv -f #{temp} #{file} )"
145
+ }
146
+ run(execute.join(' && '))
147
+ ensure
148
+ remove = [ script ] + config_map.values
149
+ run("rm -f #{remove.join(' ')}") rescue nil
150
+ end
151
+ end
152
+ }
153
+
154
+ _cset(:pyenv_platform) {
155
+ capture((<<-EOS).gsub(/\s+/, ' ')).strip
156
+ if test -f /etc/debian_version; then
157
+ if test -f /etc/lsb-release && grep -i -q DISTRIB_ID=Ubuntu /etc/lsb-release; then
158
+ echo ubuntu;
159
+ else
160
+ echo debian;
161
+ fi;
162
+ elif test -f /etc/redhat-release; then
163
+ echo redhat;
164
+ else
165
+ echo unknown;
166
+ fi;
167
+ EOS
168
+ }
169
+ _cset(:pyenv_python_dependencies) {
170
+ case pyenv_platform
171
+ when /(debian|ubuntu)/i
172
+ %w(git-core build-essential libreadline6-dev zlib1g-dev libssl-dev)
173
+ when /redhat/i
174
+ %w(git-core autoconf glibc-devel patch readline readline-devel zlib zlib-devel openssl)
175
+ else
176
+ []
177
+ end
178
+ }
179
+ task(:dependencies, :except => { :no_release => true }) {
180
+ unless pyenv_python_dependencies.empty?
181
+ case pyenv_platform
182
+ when /(debian|ubuntu)/i
183
+ begin
184
+ run("dpkg-query -s #{pyenv_python_dependencies.join(' ')} > /dev/null")
185
+ rescue
186
+ run("#{sudo} apt-get install -q -y #{pyenv_python_dependencies.join(' ')}")
187
+ end
188
+ when /redhat/i
189
+ begin
190
+ run("rpm -qi #{pyenv_python_dependencies.join(' ')} > /dev/null")
191
+ rescue
192
+ run("#{sudo} yum install -q -y #{pyenv_python_dependencies.join(' ')}")
193
+ end
194
+ else
195
+ # nop
196
+ end
197
+ end
198
+ }
199
+
200
+ desc("Build python within pyenv.")
201
+ task(:build, :except => { :no_release => true }) {
202
+ python = fetch(:pyenv_python_cmd, 'python')
203
+ if pyenv_use_virtualenv
204
+ if pyenv_virtualenv_python_version != 'system'
205
+ # build python for virtualenv
206
+ run("#{pyenv_bin} whence #{python} | fgrep -q #{pyenv_virtualenv_python_version} || " +
207
+ "#{pyenv_bin} install #{pyenv_virtualenv_python_version}")
208
+ end
209
+ if pyenv_python_version != 'system'
210
+ # create virtualenv
211
+ run("#{pyenv_bin} whence #{python} | fgrep -q #{pyenv_python_version} || " +
212
+ "#{pyenv_bin} virtualenv #{pyenv_virtualenv_options.join(' ')} #{pyenv_virtualenv_python_version} #{pyenv_python_version}")
213
+ end
214
+ else
215
+ if pyenv_python_version != 'system'
216
+ run("#{pyenv_bin} whence #{python} | fgrep -q #{pyenv_python_version} || #{pyenv_bin} install #{pyenv_python_version}")
217
+ end
218
+ end
219
+
220
+ run("#{pyenv_cmd} exec #{python} --version && #{pyenv_cmd} global #{pyenv_python_version}")
221
+ }
222
+ }
223
+ }
224
+ end
7
225
  end
8
226
  end
227
+
228
+ if Capistrano::Configuration.instance
229
+ Capistrano::Configuration.instance.extend(Capistrano::PyEnv)
230
+ end
231
+
232
+ # vim:set ft=ruby ts=2 sw=2 :
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module PyEnv
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
5
5
  end
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: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
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: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2013-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -41,7 +41,6 @@ files:
41
41
  - Rakefile
42
42
  - capistrano-pyenv.gemspec
43
43
  - lib/capistrano-pyenv.rb
44
- - lib/capistrano-pyenv/deploy.rb
45
44
  - lib/capistrano-pyenv/version.rb
46
45
  homepage: https://github.com/yyuu/capistrano-pyenv
47
46
  licenses: []
@@ -1,224 +0,0 @@
1
-
2
- require "capistrano/configuration"
3
- require "capistrano/recipes/deploy/scm"
4
-
5
- module Capistrano
6
- module PyEnv
7
- def self.extended(configuration)
8
- configuration.load {
9
- namespace(:pyenv) {
10
- _cset(:pyenv_path) {
11
- capture("echo $HOME/.pyenv").chomp()
12
- }
13
- _cset(:pyenv_bin) {
14
- File.join(pyenv_path, 'bin', 'pyenv')
15
- }
16
- _cset(:pyenv_cmd) { # to use custom pyenv_path, we use `env` instead of cap's default_environment.
17
- "env PYENV_VERSION=#{pyenv_python_version.dump} #{pyenv_bin}"
18
- }
19
- _cset(:pyenv_repository, 'git://github.com/yyuu/pyenv.git')
20
- _cset(:pyenv_branch, 'master')
21
-
22
- _cset(:pyenv_plugins) {{
23
- "python-virtualenv" => { :repository => "git://github.com/yyuu/python-virtualenv.git", :branch => "master" },
24
- }}
25
- _cset(:pyenv_plugins_options, {}) # for backward compatibility. plugin options can be configured from :pyenv_plugins.
26
- _cset(:pyenv_plugins_path) {
27
- File.join(pyenv_path, 'plugins')
28
- }
29
- _cset(:pyenv_python_version, "2.7.3")
30
-
31
- _cset(:pyenv_use_virtualenv, false)
32
- _cset(:pyenv_virtualenv_python_version, '2.7.3')
33
- _cset(:pyenv_virtualenv_options, %w(--distribute --quiet --system-site-packages))
34
-
35
- desc("Setup pyenv.")
36
- task(:setup, :except => { :no_release => true }) {
37
- dependencies
38
- update
39
- configure
40
- build
41
- }
42
- after 'deploy:setup', 'pyenv:setup'
43
-
44
- def pyenv_update_repository(destination, options={})
45
- configuration = Capistrano::Configuration.new()
46
- options = {
47
- :source => proc { Capistrano::Deploy::SCM.new(configuration[:scm], configuration) },
48
- :revision => proc { configuration[:source].head },
49
- :real_revision => proc {
50
- configuration[:source].local.query_revision(configuration[:revision]) { |cmd| with_env("LC_ALL", "C") { run_locally(cmd) } }
51
- },
52
- }.merge(options)
53
- variables.merge(options).each do |key, val|
54
- configuration.set(key, val)
55
- end
56
- source = configuration[:source]
57
- revision = configuration[:real_revision]
58
- #
59
- # we cannot use source.sync since it cleans up untacked files in the repository.
60
- # currently we are just calling git sub-commands directly to avoid the problems.
61
- #
62
- verbose = configuration[:scm_verbose] ? nil : "-q"
63
- run((<<-EOS).gsub(/\s+/, ' ').strip)
64
- if [ -d #{destination} ]; then
65
- cd #{destination} &&
66
- #{source.command} fetch #{verbose} #{source.origin} &&
67
- #{source.command} fetch --tags #{verbose} #{source.origin} &&
68
- #{source.command} reset #{verbose} --hard #{revision};
69
- else
70
- #{source.checkout(revision, destination)};
71
- fi
72
- EOS
73
- end
74
-
75
- desc("Update pyenv installation.")
76
- task(:update, :except => { :no_release => true }) {
77
- pyenv_update_repository(pyenv_path, :scm => :git, :repository => pyenv_repository, :branch => pyenv_branch)
78
- plugins.update
79
- }
80
-
81
- desc("Purge pyenv.")
82
- task(:purge, :except => { :no_release => true }) {
83
- run("rm -rf #{pyenv_path}")
84
- }
85
-
86
- namespace(:plugins) {
87
- desc("Update pyenv plugins.")
88
- task(:update, :except => { :no_release => true }) {
89
- pyenv_plugins.each do |name, repository|
90
- # for backward compatibility, obtain plugin options from :pyenv_plugins_options first
91
- options = pyenv_plugins_options.fetch(name, {})
92
- options = options.merge(Hash === repository ? repository : {:repository => repository})
93
- pyenv_update_repository(File.join(pyenv_plugins_path, name), options.merge(:scm => :git))
94
- end
95
- }
96
- }
97
-
98
- _cset(:pyenv_configure_home) { capture("echo $HOME").chomp }
99
- _cset(:pyenv_configure_shell) { capture("echo $SHELL").chomp }
100
- _cset(:pyenv_configure_files) {
101
- if fetch(:pyenv_configure_basenames, nil)
102
- [ pyenv_configure_basenames ].flatten.map { |basename|
103
- File.join(pyenv_configure_home, basename)
104
- }
105
- else
106
- bash_profile = File.join(pyenv_configure_home, '.bash_profile')
107
- profile = File.join(pyenv_configure_home, '.profile')
108
- case File.basename(pyenv_configure_shell)
109
- when /bash/
110
- [ capture("test -f #{profile.dump} && echo #{profile.dump} || echo #{bash_profile.dump}") ]
111
- when /zsh/
112
- [ File.join(pyenv_configure_home, '.zshenv') ]
113
- else # other sh compatible shell such like dash
114
- [ profile ]
115
- end
116
- end
117
- }
118
- _cset(:pyenv_configure_script) {
119
- (<<-EOS).gsub(/^\s*/, '')
120
- # Configured by capistrano-pyenv. Do not edit directly.
121
- export PATH="#{pyenv_path}/bin:$PATH"
122
- eval "$(pyenv init -)"
123
- EOS
124
- }
125
- _cset(:pyenv_configure_signature, '##pyenv:configure')
126
- task(:configure, :except => { :no_release => true }) {
127
- if fetch(:pyenv_use_configure, true)
128
- script = File.join('/tmp', "pyenv.#{$$}")
129
- config = [ pyenv_configure_files ].flatten
130
- config_map = Hash[ config.map { |f| [f, File.join('/tmp', "#{File.basename(f)}.#{$$}")] } ]
131
- begin
132
- execute = []
133
- put(pyenv_configure_script, script)
134
- config_map.each { |file, temp|
135
- ## (1) copy original config to temporaly file and then modify
136
- execute << "( test -f #{file} || touch #{file} )"
137
- execute << "cp -fp #{file} #{temp}"
138
- execute << "sed -i -e '/^#{Regexp.escape(pyenv_configure_signature)}/,/^#{Regexp.escape(pyenv_configure_signature)}/d' #{temp}"
139
- execute << "echo #{pyenv_configure_signature.dump} >> #{temp}"
140
- execute << "cat #{script} >> #{temp}"
141
- execute << "echo #{pyenv_configure_signature.dump} >> #{temp}"
142
- ## (2) update config only if it is needed
143
- execute << "cp -fp #{file} #{file}.orig"
144
- execute << "( diff -u #{file} #{temp} || mv -f #{temp} #{file} )"
145
- }
146
- run(execute.join(' && '))
147
- ensure
148
- remove = [ script ] + config_map.values
149
- run("rm -f #{remove.join(' ')}") rescue nil
150
- end
151
- end
152
- }
153
-
154
- _cset(:pyenv_platform) {
155
- capture((<<-EOS).gsub(/\s+/, ' ')).strip
156
- if test -f /etc/debian_version; then
157
- if test -f /etc/lsb-release && grep -i -q DISTRIB_ID=Ubuntu /etc/lsb-release; then
158
- echo ubuntu;
159
- else
160
- echo debian;
161
- fi;
162
- elif test -f /etc/redhat-release; then
163
- echo redhat;
164
- else
165
- echo unknown;
166
- fi;
167
- EOS
168
- }
169
- _cset(:pyenv_python_dependencies) {
170
- case pyenv_platform
171
- when /(debian|ubuntu)/i
172
- %w(git-core build-essential libreadline6-dev zlib1g-dev libssl-dev)
173
- when /redhat/i
174
- %w(git-core autoconf glibc-devel patch readline readline-devel zlib zlib-devel openssl)
175
- else
176
- []
177
- end
178
- }
179
- task(:dependencies, :except => { :no_release => true }) {
180
- unless pyenv_python_dependencies.empty?
181
- case pyenv_platform
182
- when /(debian|ubuntu)/i
183
- run("#{sudo} apt-get install -q -y #{pyenv_python_dependencies.join(' ')}")
184
- when /redhat/i
185
- run("#{sudo} yum install -q -y #{pyenv_python_dependencies.join(' ')}")
186
- else
187
- # nop
188
- end
189
- end
190
- }
191
-
192
- desc("Build python within pyenv.")
193
- task(:build, :except => { :no_release => true }) {
194
- python = fetch(:pyenv_python_cmd, 'python')
195
- if pyenv_use_virtualenv
196
- if pyenv_virtualenv_python_version != 'system'
197
- # build python for virtualenv
198
- run("#{pyenv_bin} whence #{python} | fgrep -q #{pyenv_virtualenv_python_version} || " +
199
- "#{pyenv_bin} install #{pyenv_virtualenv_python_version}")
200
- end
201
- if pyenv_python_version != 'system'
202
- # create virtualenv
203
- run("#{pyenv_bin} whence #{python} | fgrep -q #{pyenv_python_version} || " +
204
- "#{pyenv_bin} virtualenv #{pyenv_virtualenv_options.join(' ')} #{pyenv_virtualenv_python_version} #{pyenv_python_version}")
205
- end
206
- else
207
- if pyenv_python_version != 'system'
208
- run("#{pyenv_bin} whence #{python} | fgrep -q #{pyenv_python_version} || #{pyenv_bin} install #{pyenv_python_version}")
209
- end
210
- end
211
-
212
- run("#{pyenv_cmd} exec #{python} --version && #{pyenv_cmd} global #{pyenv_python_version}")
213
- }
214
- }
215
- }
216
- end
217
- end
218
- end
219
-
220
- if Capistrano::Configuration.instance
221
- Capistrano::Configuration.instance.extend(Capistrano::PyEnv)
222
- end
223
-
224
- # vim:set ft=ruby ts=2 sw=2 :