capistrano-virtualenv 0.0.3 → 0.0.4

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.
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Capistrano::Virtualenv::VERSION
17
17
 
18
18
  gem.add_dependency("capistrano")
19
+ gem.add_dependency("capistrano-file-transfer-ext", "~> 0.0.3")
19
20
  end
@@ -1,8 +1,219 @@
1
- require "capistrano-virtualenv/deploy"
2
1
  require "capistrano-virtualenv/version"
2
+ require "capistrano/configuration/actions/file_transfer_ext"
3
+ require "uri"
3
4
 
4
5
  module Capistrano
5
6
  module Virtualenv
6
- # Your code goes here...
7
+ def self.extended(configuration)
8
+ configuration.load {
9
+ namespace(:virtualenv) {
10
+ _cset(:virtualenv_use_system, false) # controls whether virtualenv should be use system packages or not.
11
+
12
+ _cset(:virtualenv_script_url, 'https://raw.github.com/pypa/virtualenv/master/virtualenv.py')
13
+ _cset(:virtualenv_script_file) {
14
+ File.join(shared_path, 'virtualenv', File.basename(URI.parse(virtualenv_script_url).path))
15
+ }
16
+ _cset(:virtualenv_bootstrap_python, 'python') # the python executable which will be used to craete virtualenv
17
+ _cset(:virtualenv_cmd) {
18
+ [
19
+ virtualenv_bootstrap_python,
20
+ virtualenv_script_file,
21
+ virtualenv_options,
22
+ ].flatten.join(' ')
23
+ }
24
+ _cset(:virtualenv_options) {
25
+ os = %w(--quiet)
26
+ os << "--system-site-packages" if virtualenv_use_system
27
+ os
28
+ }
29
+ _cset(:virtualenv_easy_install_options, %w(--quiet))
30
+ _cset(:virtualenv_pip_options, %w(--quiet))
31
+ _cset(:virtualenv_pip_install_options, [])
32
+ _cset(:virtualenv_pip_package, 'pip')
33
+ _cset(:virtualenv_requirements, []) # primary package list
34
+ _cset(:virtualenv_requirements_file) { # secondary package list
35
+ File.join(release_path, 'requirements.txt')
36
+ }
37
+ _cset(:virtualenv_build_requirements, {})
38
+ _cset(:virtualenv_install_packages, []) # apt packages
39
+
40
+ ## shared virtualenv:
41
+ ## - created in shared_path
42
+ ## - to be used to share libs between releases
43
+ _cset(:virtualenv_shared_path) {
44
+ File.join(shared_path, 'virtualenv', 'shared')
45
+ }
46
+ _cset(:virtualenv_shared_python) {
47
+ File.join(virtualenv_shared_path, 'bin', 'python')
48
+ }
49
+ _cset(:virtualenv_shared_easy_install) {
50
+ File.join(virtualenv_shared_path, 'bin', 'easy_install')
51
+ }
52
+ _cset(:virtualenv_shared_easy_install_cmd) {
53
+ # execute from :virtualenv_shared_python
54
+ # since `virtualenv --relocatable` will not set shebang line with absolute path.
55
+ [
56
+ virtualenv_shared_python,
57
+ virtualenv_shared_easy_install,
58
+ virtualenv_easy_install_options,
59
+ ].flatten.join(' ')
60
+ }
61
+ _cset(:virtualenv_shared_pip) {
62
+ File.join(virtualenv_shared_path, 'bin', 'pip')
63
+ }
64
+ _cset(:virtualenv_shared_pip_cmd) {
65
+ [
66
+ virtualenv_shared_python,
67
+ virtualenv_shared_pip,
68
+ virtualenv_pip_options,
69
+ ].flatten.join(' ')
70
+ }
71
+
72
+ ## release virtualenv
73
+ ## - created in release_path
74
+ ## - common libs are copied from shared virtualenv
75
+ ## - will be used for running application
76
+ _cset(:virtualenv_release_path) { # the path where runtime virtualenv will be created
77
+ File.join(release_path, 'vendor', 'virtualenv')
78
+ }
79
+ _cset(:virtualenv_release_python) { # the python executable within virtualenv
80
+ File.join(virtualenv_release_path, 'bin', 'python')
81
+ }
82
+ _cset(:virtualenv_release_easy_install) {
83
+ File.join(virtualenv_release_path, 'bin', 'easy_install')
84
+ }
85
+ _cset(:virtualenv_release_easy_install_cmd) {
86
+ [
87
+ virtualenv_release_python,
88
+ virtualenv_release_easy_install,
89
+ virtualenv_easy_install_options,
90
+ ].flatten.join(' ')
91
+ }
92
+ _cset(:virtualenv_release_pip) {
93
+ File.join(virtualenv_release_path, 'bin', 'pip')
94
+ }
95
+ _cset(:virtualenv_release_pip_cmd) {
96
+ [
97
+ virtualenv_release_python,
98
+ virtualenv_release_pip,
99
+ virtualenv_pip_options,
100
+ ].flatten.join(' ')
101
+ }
102
+
103
+ ## current virtualenv
104
+ ## - placed in current_path
105
+ ## - virtualenv of currently running application
106
+ _cset(:virtualenv_current_path) {
107
+ File.join(current_path, 'vendor', 'virtualenv')
108
+ }
109
+ _cset(:virtualenv_current_python) {
110
+ File.join(virtualenv_current_path, 'bin', 'python')
111
+ }
112
+ _cset(:virtualenv_current_easy_install) {
113
+ File.join(virtualenv_current_path, 'bin', 'easy_install')
114
+ }
115
+ _cset(:virtualenv_current_easy_install_cmd) {
116
+ [
117
+ virtualenv_current_python,
118
+ virtualenv_current_easy_install,
119
+ virtualenv_easy_install_options,
120
+ ].flatten.join(' ')
121
+ }
122
+ _cset(:virtualenv_current_pip) {
123
+ File.join(virtualenv_current_path, 'bin', 'pip')
124
+ }
125
+ _cset(:virtualenv_current_pip_cmd) {
126
+ [
127
+ virtualenv_current_python,
128
+ virtualenv_current_pip,
129
+ virtualenv_pip_options,
130
+ ].flatten.join(' ')
131
+ }
132
+
133
+ desc("Setup virtualenv.")
134
+ task(:setup, :except => { :no_release => true }) {
135
+ transaction {
136
+ install
137
+ create_shared
138
+ }
139
+ }
140
+ after 'deploy:setup', 'virtualenv:setup'
141
+
142
+ desc("Install virtualenv.")
143
+ task(:install, :except => { :no_release => true }) {
144
+ run("#{sudo} apt-get install #{virtualenv_install_packages.join(' ')}") unless virtualenv_install_packages.empty?
145
+ dirs = [ File.dirname(virtualenv_script_file) ].uniq()
146
+ run("mkdir -p #{dirs.join(' ')} && ( test -f #{virtualenv_script_file} || wget --no-verbose -O #{virtualenv_script_file} #{virtualenv_script_url} )")
147
+ }
148
+
149
+ desc("Uninstall virtualenv.")
150
+ task(:uninstall, :except => { :no_release => true }) {
151
+ run("rm -f #{virtualenv_script_file}")
152
+ }
153
+
154
+ task(:create_shared, :except => { :no_release => true }) {
155
+ dirs = [ File.dirname(virtualenv_shared_path) ].uniq()
156
+ cmds = [ ]
157
+ cmds << "mkdir -p #{dirs.join(' ')}"
158
+ cmds << "( test -d #{virtualenv_shared_path} || #{virtualenv_cmd} #{virtualenv_shared_path} )"
159
+ cmds << "( test -x #{virtualenv_shared_pip} || #{virtualenv_shared_easy_install_cmd} #{virtualenv_pip_package} )"
160
+ cmds << "#{virtualenv_shared_python} --version && #{virtualenv_shared_pip_cmd} --version"
161
+ run(cmds.join(' && '))
162
+ }
163
+
164
+ task(:destroy_shared, :except => { :no_release => true }) {
165
+ run("rm -rf #{virtualenv_shared_path}")
166
+ }
167
+
168
+ desc("Update virtualenv for project.")
169
+ task(:update, :except => { :no_release => true }) {
170
+ transaction {
171
+ update_shared
172
+ create_release
173
+ }
174
+ }
175
+ after 'deploy:finalize_update', 'virtualenv:update'
176
+
177
+ task(:update_shared, :except => { :no_release => true }) {
178
+ unless virtualenv_requirements.empty?
179
+ top.safe_put(virtualenv_requirements.join("\n"), virtualenv_requirements_file, :place => :if_modified)
180
+ end
181
+ run("touch #{virtualenv_requirements_file} && #{virtualenv_shared_pip_cmd} install #{virtualenv_pip_install_options.join(' ')} -r #{virtualenv_requirements_file}")
182
+
183
+ execute = virtualenv_build_requirements.map { |package, options|
184
+ build_options = ( options || [] )
185
+ "#{virtualenv_shared_pip_cmd} install #{virtualenv_pip_install_options.join(' ')} #{build_options.join(' ')} #{package.dump}"
186
+ }
187
+ run(execute.join(' && ')) unless execute.empty?
188
+ }
189
+
190
+ task(:create_release, :except => { :no_release => true }) {
191
+ dirs = [ File.dirname(virtualenv_release_path) ].uniq()
192
+ cmds = [ ]
193
+ cmds << "mkdir -p #{dirs.join(' ')}"
194
+ # TODO: turn :virtualenv_use_relocatable true if it will be an official features.
195
+ # `virtualenv --relocatable` does not work expectedly as of virtualenv 1.7.2.
196
+ if fetch(:virtualenv_use_relocatable, false)
197
+ cmds << "#{virtualenv_cmd} --relocatable #{virtualenv_shared_path}"
198
+ cmds << "cp -RPp #{virtualenv_shared_path} #{virtualenv_release_path}"
199
+ else
200
+ cmds << "( test -d #{virtualenv_release_path} || #{virtualenv_cmd} #{virtualenv_release_path} )"
201
+ cmds << "( test -x #{virtualenv_release_pip} || #{virtualenv_release_easy_install_cmd} #{virtualenv_pip_package} )"
202
+ cmds << "#{virtualenv_release_python} --version && #{virtualenv_release_pip_cmd} --version"
203
+ cmds << "rsync -lrpt -u #{virtualenv_shared_path}/bin/ #{virtualenv_release_path}/bin/" # copy binaries and scripts from shared virtualenv
204
+ cmds << "sed -i -e 's|^#!#{virtualenv_shared_path}/bin/python.*$|#!#{virtualenv_release_path}/bin/python|' #{virtualenv_release_path}/bin/*"
205
+ cmds << "rsync -lrpt #{virtualenv_shared_path}/lib/ #{virtualenv_release_path}/lib/" # copy libraries from shared virtualenv
206
+ end
207
+ run(cmds.join(' && '))
208
+ }
209
+ }
210
+ }
211
+ end
7
212
  end
8
213
  end
214
+
215
+ if Capistrano::Configuration.instance
216
+ Capistrano::Configuration.instance.extend(Capistrano::Virtualenv)
217
+ end
218
+
219
+ # vim:set ft=ruby :
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Virtualenv
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-virtualenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-11-08 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
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano-file-transfer-ext
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.0.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.3
30
46
  description: a capistrano recipe to deploy python apps with virtualenv.
31
47
  email:
32
48
  - yamashita@geishatokyo.com
@@ -41,7 +57,6 @@ files:
41
57
  - Rakefile
42
58
  - capistrano-virtualenv.gemspec
43
59
  - lib/capistrano-virtualenv.rb
44
- - lib/capistrano-virtualenv/deploy.rb
45
60
  - lib/capistrano-virtualenv/version.rb
46
61
  homepage: https://github.com/yyuu/capistrano-virtualenv
47
62
  licenses: []
@@ -1,224 +0,0 @@
1
-
2
- require 'uri'
3
-
4
- module Capistrano
5
- module Virtualenv
6
- def self.extended(configuration)
7
- configuration.load {
8
- namespace(:virtualenv) {
9
- _cset(:virtualenv_use_system, false) # controls whether virtualenv should be use system packages or not.
10
-
11
- _cset(:virtualenv_script_url, 'https://raw.github.com/pypa/virtualenv/master/virtualenv.py')
12
- _cset(:virtualenv_script_file) {
13
- File.join(shared_path, 'virtualenv', File.basename(URI.parse(virtualenv_script_url).path))
14
- }
15
- _cset(:virtualenv_bootstrap_python, 'python') # the python executable which will be used to craete virtualenv
16
- _cset(:virtualenv_cmd) {
17
- [
18
- virtualenv_bootstrap_python,
19
- virtualenv_script_file,
20
- virtualenv_options,
21
- ].flatten.join(' ')
22
- }
23
- _cset(:virtualenv_options) {
24
- os = %w(--quiet)
25
- os << "--system-site-packages" if virtualenv_use_system
26
- os
27
- }
28
- _cset(:virtualenv_easy_install_options, %w(--quiet))
29
- _cset(:virtualenv_pip_options, %w(--quiet))
30
- _cset(:virtualenv_pip_install_options, [])
31
- _cset(:virtualenv_pip_package, 'pip')
32
- _cset(:virtualenv_requirements, []) # primary package list
33
- _cset(:virtualenv_requirements_file) { # secondary package list
34
- File.join(release_path, 'requirements.txt')
35
- }
36
- _cset(:virtualenv_build_requirements, {})
37
- _cset(:virtualenv_install_packages, []) # apt packages
38
-
39
- ## shared virtualenv:
40
- ## - created in shared_path
41
- ## - to be used to share libs between releases
42
- _cset(:virtualenv_shared_path) {
43
- File.join(shared_path, 'virtualenv', 'shared')
44
- }
45
- _cset(:virtualenv_shared_python) {
46
- File.join(virtualenv_shared_path, 'bin', 'python')
47
- }
48
- _cset(:virtualenv_shared_easy_install) {
49
- File.join(virtualenv_shared_path, 'bin', 'easy_install')
50
- }
51
- _cset(:virtualenv_shared_easy_install_cmd) {
52
- # execute from :virtualenv_shared_python
53
- # since `virtualenv --relocatable` will not set shebang line with absolute path.
54
- [
55
- virtualenv_shared_python,
56
- virtualenv_shared_easy_install,
57
- virtualenv_easy_install_options,
58
- ].flatten.join(' ')
59
- }
60
- _cset(:virtualenv_shared_pip) {
61
- File.join(virtualenv_shared_path, 'bin', 'pip')
62
- }
63
- _cset(:virtualenv_shared_pip_cmd) {
64
- [
65
- virtualenv_shared_python,
66
- virtualenv_shared_pip,
67
- virtualenv_pip_options,
68
- ].flatten.join(' ')
69
- }
70
-
71
- ## release virtualenv
72
- ## - created in release_path
73
- ## - common libs are copied from shared virtualenv
74
- ## - will be used for running application
75
- _cset(:virtualenv_release_path) { # the path where runtime virtualenv will be created
76
- File.join(release_path, 'vendor', 'virtualenv')
77
- }
78
- _cset(:virtualenv_release_python) { # the python executable within virtualenv
79
- File.join(virtualenv_release_path, 'bin', 'python')
80
- }
81
- _cset(:virtualenv_release_easy_install) {
82
- File.join(virtualenv_release_path, 'bin', 'easy_install')
83
- }
84
- _cset(:virtualenv_release_easy_install_cmd) {
85
- [
86
- virtualenv_release_python,
87
- virtualenv_release_easy_install,
88
- virtualenv_easy_install_options,
89
- ].flatten.join(' ')
90
- }
91
- _cset(:virtualenv_release_pip) {
92
- File.join(virtualenv_release_path, 'bin', 'pip')
93
- }
94
- _cset(:virtualenv_release_pip_cmd) {
95
- [
96
- virtualenv_release_python,
97
- virtualenv_release_pip,
98
- virtualenv_pip_options,
99
- ].flatten.join(' ')
100
- }
101
-
102
- ## current virtualenv
103
- ## - placed in current_path
104
- ## - virtualenv of currently running application
105
- _cset(:virtualenv_current_path) {
106
- File.join(current_path, 'vendor', 'virtualenv')
107
- }
108
- _cset(:virtualenv_current_python) {
109
- File.join(virtualenv_current_path, 'bin', 'python')
110
- }
111
- _cset(:virtualenv_current_easy_install) {
112
- File.join(virtualenv_current_path, 'bin', 'easy_install')
113
- }
114
- _cset(:virtualenv_current_easy_install_cmd) {
115
- [
116
- virtualenv_current_python,
117
- virtualenv_current_easy_install,
118
- virtualenv_easy_install_options,
119
- ].flatten.join(' ')
120
- }
121
- _cset(:virtualenv_current_pip) {
122
- File.join(virtualenv_current_path, 'bin', 'pip')
123
- }
124
- _cset(:virtualenv_current_pip_cmd) {
125
- [
126
- virtualenv_current_python,
127
- virtualenv_current_pip,
128
- virtualenv_pip_options,
129
- ].flatten.join(' ')
130
- }
131
-
132
- desc("Setup virtualenv.")
133
- task(:setup, :except => { :no_release => true }) {
134
- transaction {
135
- install
136
- create_shared
137
- }
138
- }
139
- after 'deploy:setup', 'virtualenv:setup'
140
-
141
- desc("Install virtualenv.")
142
- task(:install, :except => { :no_release => true }) {
143
- run("#{sudo} apt-get install #{virtualenv_install_packages.join(' ')}") unless virtualenv_install_packages.empty?
144
- dirs = [ File.dirname(virtualenv_script_file) ].uniq()
145
- run("mkdir -p #{dirs.join(' ')} && ( test -f #{virtualenv_script_file} || wget --no-verbose -O #{virtualenv_script_file} #{virtualenv_script_url} )")
146
- }
147
-
148
- desc("Uninstall virtualenv.")
149
- task(:uninstall, :except => { :no_release => true }) {
150
- run("rm -f #{virtualenv_script_file}")
151
- }
152
-
153
- task(:create_shared, :except => { :no_release => true }) {
154
- dirs = [ File.dirname(virtualenv_shared_path) ].uniq()
155
- cmds = [ ]
156
- cmds << "mkdir -p #{dirs.join(' ')}"
157
- cmds << "( test -d #{virtualenv_shared_path} || #{virtualenv_cmd} #{virtualenv_shared_path} )"
158
- cmds << "( test -x #{virtualenv_shared_pip} || #{virtualenv_shared_easy_install_cmd} #{virtualenv_pip_package} )"
159
- cmds << "#{virtualenv_shared_python} --version && #{virtualenv_shared_pip_cmd} --version"
160
- run(cmds.join(' && '))
161
- }
162
-
163
- task(:destroy_shared, :except => { :no_release => true }) {
164
- run("rm -rf #{virtualenv_shared_path}")
165
- }
166
-
167
- desc("Update virtualenv for project.")
168
- task(:update, :except => { :no_release => true }) {
169
- transaction {
170
- update_shared
171
- create_release
172
- }
173
- }
174
- after 'deploy:finalize_update', 'virtualenv:update'
175
-
176
- task(:update_shared, :except => { :no_release => true }) {
177
- unless virtualenv_requirements.empty?
178
- tempfile = "/tmp/requirements.txt.#{$$}"
179
- begin
180
- top.put(virtualenv_requirements.join("\n"), tempfile)
181
- run("diff -u #{virtualenv_requirements_file} #{tempfile} || mv -f #{tempfile} #{virtualenv_requirements_file}")
182
- ensure
183
- run("rm -f #{tempfile}")
184
- end
185
- end
186
- run("touch #{virtualenv_requirements_file} && #{virtualenv_shared_pip_cmd} install #{virtualenv_pip_install_options.join(' ')} -r #{virtualenv_requirements_file}")
187
-
188
- execute = virtualenv_build_requirements.map { |package, options|
189
- build_options = ( options || [] )
190
- "#{virtualenv_shared_pip_cmd} install #{virtualenv_pip_install_options.join(' ')} #{build_options.join(' ')} #{package.dump}"
191
- }
192
- run(execute.join(' && ')) unless execute.empty?
193
- }
194
-
195
- task(:create_release, :except => { :no_release => true }) {
196
- dirs = [ File.dirname(virtualenv_release_path) ].uniq()
197
- cmds = [ ]
198
- cmds << "mkdir -p #{dirs.join(' ')}"
199
- # TODO: turn :virtualenv_use_relocatable true if it will be an official features.
200
- # `virtualenv --relocatable` does not work expectedly as of virtualenv 1.7.2.
201
- if fetch(:virtualenv_use_relocatable, false)
202
- cmds << "#{virtualenv_cmd} --relocatable #{virtualenv_shared_path}"
203
- cmds << "cp -RPp #{virtualenv_shared_path} #{virtualenv_release_path}"
204
- else
205
- cmds << "( test -d #{virtualenv_release_path} || #{virtualenv_cmd} #{virtualenv_release_path} )"
206
- cmds << "( test -x #{virtualenv_release_pip} || #{virtualenv_release_easy_install_cmd} #{virtualenv_pip_package} )"
207
- cmds << "#{virtualenv_release_python} --version && #{virtualenv_release_pip_cmd} --version"
208
- cmds << "rsync -lrpt -u #{virtualenv_shared_path}/bin/ #{virtualenv_release_path}/bin/" # copy binaries and scripts from shared virtualenv
209
- cmds << "sed -i -e 's|^#!#{virtualenv_shared_path}/bin/python.*$|#!#{virtualenv_release_path}/bin/python|' #{virtualenv_release_path}/bin/*"
210
- cmds << "rsync -lrpt #{virtualenv_shared_path}/lib/ #{virtualenv_release_path}/lib/" # copy libraries from shared virtualenv
211
- end
212
- run(cmds.join(' && '))
213
- }
214
- }
215
- }
216
- end
217
- end
218
- end
219
-
220
- if Capistrano::Configuration.instance
221
- Capistrano::Configuration.instance.extend(Capistrano::Virtualenv)
222
- end
223
-
224
- # vim:set ft=ruby :