gemenv 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,16 +9,16 @@ Introduction
9
9
  gemenv is a tool to build rubygem environments, in the spirit of
10
10
  Python's virtualenv. It creates a directory with a complete GEM\_HOME
11
11
  to contain all of your project's gems. It also contains an activation
12
- script to enable this environment.
12
+ script to enable this environment, and an executor to run subshells
13
+ (or anything else) with the right environment variables set.
13
14
 
14
15
  Here's an example session:
15
16
 
16
17
  $ cd /tmp
17
18
  $ gemenv my-new-env
18
19
  $ ls my-new-env
19
- bin/ gem\_home
20
+ bin/ gem_home
20
21
  $ source my-new-env/bin/activate
21
- {gemenv:my-new-env}
22
22
  $ gem install rake
23
23
  Fetching: rake-10.0.3.gem (100%)
24
24
  Successfully installed rake-10.0.3
@@ -26,25 +26,34 @@ Here's an example session:
26
26
  Installing ri documentation for rake-10.0.3...
27
27
  Installing RDoc documentation for rake-10.0.3...
28
28
  {gemenv:my-new-env}
29
- $ ls my-new-env/gem\_home/gems
29
+ $ ls my-new-env/gem_home/gems
30
30
  rake-10.0.3
31
- {gemenv:my-new-env}
32
31
  $ which rake
33
32
  /tmp/my-new-env/gem_home/bin/rake
33
+ $ echo $VIRTUAL_ENV
34
+ /tmp/my-new-env
35
+
34
36
 
35
37
  You can see that sourcing the activate script does three things:
36
38
 
37
- 1. It adds the environment name to the prompt
38
- 2. It sets GEM\_HOME so that gem installations go into the environment,
39
+ 1. It sets GEM\_HOME so that gem installations go into the environment,
39
40
  not your home or system GEM\_HOME
40
- 3. It adds the GEM\_HOME bin/ directory to your $PATH so that
41
+ 2. It adds the GEM\_HOME bin/ directory to your $PATH so that
41
42
  gem-installed binaries are available.
43
+ 3. It adds a VIRTUAL\_ENV environment variable that you can strap into
44
+ PS1 if you wish.
42
45
 
43
- This is (almost) all it does. There is currently no way to deactivate a
44
- gemenv environment, although this could be added in the future.
46
+ This is (almost) all it does. There is currently no way to deactivate
47
+ a gemenv environment activated by bin/activate. If you want a
48
+ deactivatable environment, use bin/exec:
49
+
50
+ $ my-new-env/bin/exec /bin/bash
45
51
 
46
52
  Anything which respects GEM\_HOME should work with gemenv, so you can,
47
53
  for instance, use bundler to install gems into a gemenv.
48
54
 
49
- --
55
+ The activation script currently overwrites GEM_PATH, so gemenv does
56
+ not currently support "global" gems.
57
+
58
+ --
50
59
  Alex Young <alex@bytemark.co.uk>
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'gemenv/activate_script'
4
+ require 'gemenv/exec_script'
4
5
  require 'gemenv/env_dir'
5
6
 
6
7
  module Gemenv
@@ -12,7 +13,7 @@ module Gemenv
12
13
  def run
13
14
  raise "Need an env dir!" unless @env_dir
14
15
  full_env_dir = File.expand_path( @env_dir )
15
- EnvDir.new( full_env_dir, ActivateScript ).make
16
+ EnvDir.new( full_env_dir, ActivateScript, ExecScript ).make
16
17
  end
17
18
  end
18
19
  end
@@ -1,18 +1,14 @@
1
- VIRTUAL_ENV="<%= @env_dir %>"
2
- export VIRTUAL_ENV
1
+ # Pick this up in $PS1 if you want
2
+ export VIRTUAL_ENV="<%= @env_path %>"
3
3
 
4
- PATH="$VIRTUAL_ENV/gem_home/bin:$PATH"
5
- export PATH
4
+ export PATH="$VIRTUAL_ENV/gem_home/bin:$PATH"
6
5
 
7
6
  if [ -n "$GEM_HOME" ]; then
8
7
  unset GEM_HOME
9
8
  fi
10
9
 
11
- GEM_HOME=$VIRTUAL_ENV/gem_home
12
- export GEM_HOME
13
- GEM_PATH=$(gem env home)
14
-
15
- PS1="{gemenv:$(basename $VIRTUAL_ENV)} $PS1"
10
+ export GEM_HOME=$VIRTUAL_ENV/gem_home
11
+ export GEM_PATH=$(gem env home)
16
12
 
17
13
  if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
18
14
  hash -r 2> /dev/null
@@ -1,18 +1,7 @@
1
1
  # encoding: utf-8
2
- require 'erb'
2
+ require 'gemenv/generated_script'
3
3
 
4
4
  module Gemenv
5
- class ActivateScript
6
- def initialize( env_dir )
7
- @env_dir = env_dir
8
- end
9
-
10
- def to_bash
11
- here = File.dirname( __FILE__ )
12
- template_filename = File.join( here, "activate.erb" )
13
- template = File.read( template_filename )
14
- ERB.new( template ).result( binding )
15
- end
16
-
5
+ class ActivateScript < GeneratedScript
17
6
  end
18
7
  end
@@ -44,23 +44,25 @@ module Gemenv
44
44
  class EnvDir
45
45
  attr_reader :path
46
46
 
47
- def initialize( env_dir, script_class )
47
+ def initialize( env_dir, *script_classes )
48
48
  @path = Path.new( env_dir )
49
- @script_class = script_class
49
+ @script_classes = script_classes
50
50
  end
51
51
 
52
52
  def make
53
+ scripts = make_scripts( @path, @script_classes )
54
+
53
55
  @path.mkdir_p
54
-
55
- make_activate()
56
+ scripts.each do |script| script.render end
57
+
56
58
  make_gem_home()
57
59
  self
58
60
  end
59
61
 
60
62
  private
61
- def make_activate
62
- activate_path.dirname.mkdir_p
63
- activate_path.write( activate_contents )
63
+
64
+ def make_scripts( env_path, script_classes )
65
+ script_classes.map { |cls| cls.new( env_path ) }
64
66
  end
65
67
 
66
68
 
@@ -69,18 +71,10 @@ module Gemenv
69
71
  end
70
72
 
71
73
 
72
- def activate_path
73
- @path/"bin"/"activate"
74
- end
75
-
76
74
  def gem_home_path
77
75
  @path/"gem_home"
78
76
  end
79
77
 
80
- def activate_contents
81
- @script_class.new( @path ).to_bash
82
- end
83
-
84
78
 
85
79
  end
86
80
  end
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ . "<%= @env_path/"bin"/"activate" %>"
4
+
5
+ exec "$@"
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ require 'gemenv/generated_script'
4
+
5
+ module Gemenv
6
+ class ExecScript < GeneratedScript
7
+ def render
8
+ super
9
+ target_filename.chmod(0755)
10
+ end
11
+ end
12
+ end # module Gemenv
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'erb'
4
+
5
+ module Gemenv
6
+ class GeneratedScript
7
+ def self.template_basename
8
+ self.target_basename + ".erb"
9
+ end
10
+
11
+ def self.target_basename
12
+ self.name.split("::").last.
13
+ sub("Script", '').
14
+ gsub(/([a-z])([A-Z])/, '\1_\2').
15
+ downcase
16
+ end
17
+
18
+
19
+ def self.template
20
+ here = File.dirname( __FILE__ )
21
+ template_filename = File.join( here, template_basename )
22
+ template = File.read( template_filename )
23
+ end
24
+
25
+
26
+ attr_reader :env_path
27
+
28
+ def initialize( env_path )
29
+ @env_path = env_path
30
+ end
31
+
32
+ def to_bash
33
+ ERB.new( self.class.template ).result( binding )
34
+ end
35
+
36
+
37
+ def mkdir
38
+ target_filename.dirname.mkdir_p
39
+ end
40
+
41
+ def target_filename
42
+ env_path/"bin"/self.class.target_basename
43
+ end
44
+
45
+
46
+ def render
47
+ mkdir
48
+ target_filename.write( to_bash )
49
+ end
50
+
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Gemenv
4
- VERSION="0.0.1"
4
+ VERSION="0.0.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
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-14 00:00:00.000000000 Z
12
+ date: 2013-03-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Gemenv provides a container for your gems, and otherwise stays out of
15
15
  your way.
@@ -21,10 +21,13 @@ extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
23
23
  - bin/gemenv
24
- - lib/gemenv/env_dir.rb
25
24
  - lib/gemenv/activate_script.rb
26
- - lib/gemenv/activate.erb
27
25
  - lib/gemenv/version.rb
26
+ - lib/gemenv/generated_script.rb
27
+ - lib/gemenv/activate.erb
28
+ - lib/gemenv/env_dir.rb
29
+ - lib/gemenv/exec.erb
30
+ - lib/gemenv/exec_script.rb
28
31
  - lib/gemenv.rb
29
32
  - LICENSE.txt
30
33
  - README.md
@@ -48,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
51
  version: 1.3.6
49
52
  requirements: []
50
53
  rubyforge_project: gemenv
51
- rubygems_version: 1.8.24
54
+ rubygems_version: 1.8.25
52
55
  signing_key:
53
56
  specification_version: 3
54
57
  summary: The best way to contain your dependencies