fnando-renv 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +83 -0
- data/Rakefile +73 -0
- data/bin/renv +157 -0
- data/lib/renv.rb +22 -0
- data/lib/renv/env.rb +86 -0
- data/lib/renv/gem.rb +36 -0
- data/renv.gemspec +26 -0
- metadata +80 -0
data/README.markdown
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Renv
|
2
|
+
====
|
3
|
+
|
4
|
+
Renv is a simple and dumb environment manager for RubyGems.
|
5
|
+
|
6
|
+
Install Renv:
|
7
|
+
|
8
|
+
sudo gem install fnando-renv --source=http://gems.github.com
|
9
|
+
|
10
|
+
Or
|
11
|
+
|
12
|
+
git clone git://github.com/fnando/renv.git
|
13
|
+
cd renv
|
14
|
+
rake gem:install
|
15
|
+
|
16
|
+
Then put this on your `~/.bash_profile`:
|
17
|
+
|
18
|
+
export RENVDIR="$HOME/.renv"
|
19
|
+
export PATH="$PATH:$RENVDIR/active/bin"
|
20
|
+
export GEM_HOME="$RENVDIR/active/lib"
|
21
|
+
|
22
|
+
Reload your profile with `source ~/.bash_profile`.
|
23
|
+
|
24
|
+
Here's the supported commands
|
25
|
+
|
26
|
+
renv use base
|
27
|
+
#=> create and switch to "base" environment
|
28
|
+
|
29
|
+
renv install json -v 1.1.3
|
30
|
+
#=> install json 1.1.3
|
31
|
+
|
32
|
+
renv uninstall json
|
33
|
+
#=> uninstall json
|
34
|
+
|
35
|
+
renv env
|
36
|
+
#=> display current environment
|
37
|
+
|
38
|
+
renv clone base mycopy
|
39
|
+
#=> duplicate an environment as mycopy
|
40
|
+
|
41
|
+
renv delete mycopy
|
42
|
+
#=> remove the environment
|
43
|
+
|
44
|
+
renv list
|
45
|
+
#=> list all environments
|
46
|
+
|
47
|
+
renv gems
|
48
|
+
#=> list all installed gems in the current environment
|
49
|
+
|
50
|
+
To get all available commands, run `renv help`.
|
51
|
+
|
52
|
+
**Note:** I implemented Renv because I needed something for 3 projects I'm currently
|
53
|
+
working on. I tried [Rip](http://hellorip.com) but Rip uses `gem unpack` for now
|
54
|
+
and I couldn't make it install old gems versions.
|
55
|
+
|
56
|
+
MAINTAINER
|
57
|
+
----------
|
58
|
+
|
59
|
+
* Nando Vieira ([http://simplesideias.com.br](http://simplesideias.com.br))
|
60
|
+
|
61
|
+
LICENSE:
|
62
|
+
--------
|
63
|
+
|
64
|
+
(The MIT License)
|
65
|
+
|
66
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
67
|
+
a copy of this software and associated documentation files (the
|
68
|
+
'Software'), to deal in the Software without restriction, including
|
69
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
70
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
71
|
+
permit persons to whom the Software is furnished to do so, subject to
|
72
|
+
the following conditions:
|
73
|
+
|
74
|
+
The above copyright notice and this permission notice shall be
|
75
|
+
included in all copies or substantial portions of the Software.
|
76
|
+
|
77
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
78
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
79
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
80
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
81
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
82
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
83
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "rake"
|
2
|
+
require File.dirname(__FILE__) + "/lib/renv"
|
3
|
+
|
4
|
+
PKG_FILES = %w(Rakefile renv.gemspec README.markdown) + Dir["{bin,lib}/**/*"]
|
5
|
+
|
6
|
+
spec = Gem::Specification.new do |s|
|
7
|
+
s.name = "renv"
|
8
|
+
s.version = Renv::VERSION
|
9
|
+
s.summary = "Renv is a simple and dumb environment manager for RubyGems."
|
10
|
+
s.authors = ["Nando Vieira"]
|
11
|
+
s.email = ["fnando.vieira@gmail.com"]
|
12
|
+
s.homepage = "http://github.com/fnando/renv"
|
13
|
+
s.has_rdoc = false
|
14
|
+
s.files = PKG_FILES
|
15
|
+
s.bindir = "bin"
|
16
|
+
s.executables = "renv"
|
17
|
+
|
18
|
+
s.add_dependency "rubigen"
|
19
|
+
s.add_dependency "main"
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :gem do
|
23
|
+
# Thanks to the Merb project for this code.
|
24
|
+
desc "Update Github Gemspec"
|
25
|
+
task :update_gemspec do
|
26
|
+
skip_fields = %w(new_platform original_platform specification_version loaded required_ruby_version rubygems_version platform )
|
27
|
+
|
28
|
+
result = "# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!\n"
|
29
|
+
result << "# RUN : 'rake gem:update_gemspec'\n\n"
|
30
|
+
result << "Gem::Specification.new do |s|\n"
|
31
|
+
|
32
|
+
spec.instance_variables.each do |ivar|
|
33
|
+
value = spec.instance_variable_get(ivar)
|
34
|
+
name = ivar.split("@").last
|
35
|
+
next if name == "date"
|
36
|
+
|
37
|
+
next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
|
38
|
+
if name == "dependencies"
|
39
|
+
value.each do |d|
|
40
|
+
dep, *ver = d.to_s.split(" ")
|
41
|
+
result << " s.add_dependency #{dep.inspect}, #{ver.join(" ").inspect.gsub(/[()]/, "").gsub(", runtime", "")}\n"
|
42
|
+
end
|
43
|
+
else
|
44
|
+
case value
|
45
|
+
when Array
|
46
|
+
value = name != "files" ? value.inspect : value.inspect.split(",").join(",\n")
|
47
|
+
when FalseClass
|
48
|
+
when TrueClass
|
49
|
+
when Fixnum
|
50
|
+
when String
|
51
|
+
value = value.inspect
|
52
|
+
else
|
53
|
+
value = value.to_s.inspect
|
54
|
+
end
|
55
|
+
result << " s.#{name} = #{value}\n"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
result << "end"
|
60
|
+
File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Build gem"
|
64
|
+
task :build => [:update_gemspec] do
|
65
|
+
system "gem build #{spec.instance_variable_get('@name')}.gemspec"
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Install gem"
|
69
|
+
task :install => [:update_gemspec, :build] do
|
70
|
+
system "sudo gem install #{spec.instance_variable_get('@name')}"
|
71
|
+
system "rm *.gem"
|
72
|
+
end
|
73
|
+
end
|
data/bin/renv
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "main"
|
5
|
+
require File.dirname(__FILE__) + "/../lib/renv"
|
6
|
+
|
7
|
+
Main {
|
8
|
+
description <<-TXT
|
9
|
+
The 'renv' command handles RubyGems environments.
|
10
|
+
|
11
|
+
VERSION: #{Renv::VERSION}
|
12
|
+
|
13
|
+
USAGE: renv help [command]
|
14
|
+
TXT
|
15
|
+
|
16
|
+
mode(:use) {
|
17
|
+
description <<-TXT
|
18
|
+
Create and use a new environment
|
19
|
+
TXT
|
20
|
+
|
21
|
+
examples <<-TXT
|
22
|
+
* renv use base
|
23
|
+
* renv use simplesideias
|
24
|
+
TXT
|
25
|
+
|
26
|
+
argument(:name) {
|
27
|
+
attr
|
28
|
+
}
|
29
|
+
|
30
|
+
run { Renv::Env.setup(name) }
|
31
|
+
}
|
32
|
+
|
33
|
+
mode(:clone) {
|
34
|
+
description <<-TXT
|
35
|
+
Clone a existing environment
|
36
|
+
TXT
|
37
|
+
|
38
|
+
examples <<-TXT
|
39
|
+
* renv clone [source] [destiny]
|
40
|
+
* renv clone base simplesideias
|
41
|
+
TXT
|
42
|
+
|
43
|
+
argument(:source) {
|
44
|
+
attr
|
45
|
+
}
|
46
|
+
|
47
|
+
argument(:destiny) {
|
48
|
+
attr
|
49
|
+
}
|
50
|
+
|
51
|
+
run { Renv::Env.clone(:source => source, :destiny => destiny) }
|
52
|
+
}
|
53
|
+
|
54
|
+
mode(:list) {
|
55
|
+
description <<-TXT
|
56
|
+
List all environments
|
57
|
+
TXT
|
58
|
+
|
59
|
+
examples <<-TXT
|
60
|
+
* renv list
|
61
|
+
TXT
|
62
|
+
|
63
|
+
run { Renv::Env.list }
|
64
|
+
}
|
65
|
+
|
66
|
+
mode(:env) {
|
67
|
+
description <<-TXT
|
68
|
+
Display current environment
|
69
|
+
TXT
|
70
|
+
|
71
|
+
examples <<-TXT
|
72
|
+
* renv env
|
73
|
+
TXT
|
74
|
+
|
75
|
+
run {
|
76
|
+
puts "Current environment: #{Renv.env}"
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
mode(:gems) {
|
81
|
+
description <<-TXT
|
82
|
+
List all environment installed gems
|
83
|
+
TXT
|
84
|
+
|
85
|
+
examples <<-TXT
|
86
|
+
* renv gems
|
87
|
+
TXT
|
88
|
+
|
89
|
+
run { Renv::Gem.list }
|
90
|
+
}
|
91
|
+
|
92
|
+
mode(:delete) {
|
93
|
+
description <<-TXT
|
94
|
+
Remove an environment
|
95
|
+
TXT
|
96
|
+
|
97
|
+
examples <<-TXT
|
98
|
+
* renv delete base
|
99
|
+
TXT
|
100
|
+
|
101
|
+
argument(:name) {
|
102
|
+
attr
|
103
|
+
}
|
104
|
+
|
105
|
+
run { Renv::Env.delete(name) }
|
106
|
+
}
|
107
|
+
|
108
|
+
mode(:install) {
|
109
|
+
description <<-TXT
|
110
|
+
Install a new RubyGem.
|
111
|
+
TXT
|
112
|
+
|
113
|
+
examples <<-TXT
|
114
|
+
* renv install json
|
115
|
+
* renv install json --version=1.1.3
|
116
|
+
TXT
|
117
|
+
|
118
|
+
argument(:name) {
|
119
|
+
attr
|
120
|
+
}
|
121
|
+
|
122
|
+
option(:version, :v) {
|
123
|
+
optional
|
124
|
+
argument :required
|
125
|
+
desc "Gem version"
|
126
|
+
attr
|
127
|
+
}
|
128
|
+
|
129
|
+
run { Renv::Gem.install(:name => name, :version => version) }
|
130
|
+
}
|
131
|
+
|
132
|
+
mode(:uninstall) {
|
133
|
+
description <<-TXT
|
134
|
+
Uninstall a RubyGem.
|
135
|
+
TXT
|
136
|
+
|
137
|
+
examples <<-TXT
|
138
|
+
* renv uninstall json
|
139
|
+
* renv uninstall json --version=1.1.3
|
140
|
+
TXT
|
141
|
+
|
142
|
+
argument(:name) {
|
143
|
+
attr
|
144
|
+
}
|
145
|
+
|
146
|
+
option(:version, :v) {
|
147
|
+
optional
|
148
|
+
argument :required
|
149
|
+
desc "Gem version"
|
150
|
+
attr
|
151
|
+
}
|
152
|
+
|
153
|
+
run { Renv::Gem.uninstall(:name => name, :version => version) }
|
154
|
+
}
|
155
|
+
|
156
|
+
run { help! }
|
157
|
+
}
|
data/lib/renv.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Renv
|
2
|
+
extend self
|
3
|
+
|
4
|
+
VERSION = "0.0.1"
|
5
|
+
|
6
|
+
def dir
|
7
|
+
ENV["RENVDIR"] || File.expand_path("~/.renv")
|
8
|
+
end
|
9
|
+
|
10
|
+
def env
|
11
|
+
file = File.join(Renv.dir, "env")
|
12
|
+
exit 1 unless File.file?(file)
|
13
|
+
File.read(file)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# add renv lib to load path
|
18
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
19
|
+
|
20
|
+
require "FileUtils" unless defined?(FileUtils)
|
21
|
+
require "renv/env"
|
22
|
+
require "renv/gem"
|
data/lib/renv/env.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Renv
|
2
|
+
module Env
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def setup(environment)
|
6
|
+
create_root
|
7
|
+
use(environment)
|
8
|
+
end
|
9
|
+
|
10
|
+
def clone(options)
|
11
|
+
unless File.exists?(File.join(Renv.dir, options[:source]))
|
12
|
+
puts "source environment doesn't exist"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
if File.exists?(File.join(Renv.dir, options[:destiny]))
|
17
|
+
puts "destiny environment already exist"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
FileUtils.cp_r(File.join(Renv.dir, options[:source]), File.join(Renv.dir, options[:destiny]))
|
22
|
+
use options[:destiny]
|
23
|
+
end
|
24
|
+
|
25
|
+
def list
|
26
|
+
envs = Dir.entries(Renv.dir).reject do |d|
|
27
|
+
%w(. .. active env).include?(d) || !File.directory?(File.join(Renv.dir, d))
|
28
|
+
end
|
29
|
+
|
30
|
+
if envs.empty?
|
31
|
+
puts "no environments created"
|
32
|
+
else
|
33
|
+
puts envs.join(", ")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(environment)
|
38
|
+
if Renv.env == environment
|
39
|
+
puts "cannot remove active environment"
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
puts "removing #{environment.inspect} environment"
|
44
|
+
FileUtils.rm_rf File.join(Renv.dir, environment)
|
45
|
+
puts "done!"
|
46
|
+
end
|
47
|
+
|
48
|
+
def create
|
49
|
+
target = File.join(Renv.dir, Renv.env)
|
50
|
+
|
51
|
+
unless File.directory?(target)
|
52
|
+
puts "creating #{Renv.env.inspect} environment"
|
53
|
+
FileUtils.mkdir_p(target)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def create_root
|
58
|
+
unless File.directory?(Renv.dir)
|
59
|
+
puts "creating ~/.renv"
|
60
|
+
FileUtils.mkdir_p(Renv.dir)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def use(environment)
|
65
|
+
if %w(active env).include?(environment)
|
66
|
+
puts "#{environment.inspect} cannot be used as environment name"
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "activating #{environment.inspect} environment"
|
71
|
+
File.open(File.join(Renv.dir, "env"), "w+") do |f|
|
72
|
+
f << environment
|
73
|
+
end
|
74
|
+
|
75
|
+
create
|
76
|
+
symlink
|
77
|
+
puts "done!"
|
78
|
+
end
|
79
|
+
|
80
|
+
def symlink
|
81
|
+
dir = File.join(Renv.dir, "active")
|
82
|
+
FileUtils.rm_rf(dir) if File.directory?(dir)
|
83
|
+
FileUtils.ln_s(File.join(Renv.dir, Renv.env), dir)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/renv/gem.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Renv
|
2
|
+
module Gem
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def install(options)
|
6
|
+
cmd = "gem install #{options[:name]}"
|
7
|
+
cmd << " --no-rdoc --no-ri"
|
8
|
+
cmd << " -i #{File.join(Renv.dir, Renv.env)}/lib"
|
9
|
+
cmd << " -n #{File.join(Renv.dir, Renv.env)}/bin"
|
10
|
+
cmd << " --version=#{options[:version]}" if options[:version]
|
11
|
+
|
12
|
+
system cmd
|
13
|
+
end
|
14
|
+
|
15
|
+
def uninstall(options)
|
16
|
+
puts "uninstalling gem with #{options.inspect}"
|
17
|
+
cmd = "gem uninstall #{options[:name]}"
|
18
|
+
cmd << " -i #{File.join(Renv.dir, Renv.env)}/lib"
|
19
|
+
cmd << " -n #{File.join(Renv.dir, Renv.env)}/bin"
|
20
|
+
cmd << " --version=#{options[:version]}" if options[:version]
|
21
|
+
|
22
|
+
system cmd
|
23
|
+
end
|
24
|
+
|
25
|
+
def list
|
26
|
+
dir = File.join(Renv.dir, Renv.env, "lib", "gems")
|
27
|
+
gems = Dir.entries(dir).reject {|d| %w(. ..).include?(d) }
|
28
|
+
|
29
|
+
if gems.empty?
|
30
|
+
puts "no gems installed"
|
31
|
+
else
|
32
|
+
puts gems.join(", ")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/renv.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# WARNING : RAKE AUTO-GENERATED FILE. DO NOT MANUALLY EDIT!
|
2
|
+
# RUN : 'rake gem:update_gemspec'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.required_rubygems_version = ">= 0"
|
6
|
+
s.has_rdoc = true
|
7
|
+
s.email = ["fnando.vieira@gmail.com"]
|
8
|
+
s.name = "renv"
|
9
|
+
s.homepage = "http://github.com/fnando/renv"
|
10
|
+
s.bindir = "bin"
|
11
|
+
s.executables = ["renv"]
|
12
|
+
s.summary = "Renv is a simple and dumb environment manager for RubyGems."
|
13
|
+
s.add_dependency "rubigen", ">= 0"
|
14
|
+
s.add_dependency "main", ">= 0"
|
15
|
+
s.version = "0.0.1"
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.files = ["Rakefile",
|
18
|
+
"renv.gemspec",
|
19
|
+
"README.markdown",
|
20
|
+
"bin/renv",
|
21
|
+
"lib/renv",
|
22
|
+
"lib/renv/env.rb",
|
23
|
+
"lib/renv/gem.rb",
|
24
|
+
"lib/renv.rb"]
|
25
|
+
s.authors = ["Nando Vieira"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fnando-renv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nando Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rubigen
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: main
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email:
|
37
|
+
- fnando.vieira@gmail.com
|
38
|
+
executables:
|
39
|
+
- renv
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- Rakefile
|
46
|
+
- renv.gemspec
|
47
|
+
- README.markdown
|
48
|
+
- bin/renv
|
49
|
+
- lib/renv
|
50
|
+
- lib/renv/env.rb
|
51
|
+
- lib/renv/gem.rb
|
52
|
+
- lib/renv.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/fnando/renv
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
version:
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.2.0
|
76
|
+
signing_key:
|
77
|
+
specification_version: 2
|
78
|
+
summary: Renv is a simple and dumb environment manager for RubyGems.
|
79
|
+
test_files: []
|
80
|
+
|