Bundle install runs from incorrect directory
Asked Answered
G

2

5

I'm building a simple thor based generator for some internal projects, and can't seem to get bundle install running from the correct directory.

As I run the new [APP_NAME] function, it should create the directories and files, then run bundle install to install the gems required for the application.

The source of the generator function:

def create
  puts "Creating application #{name}"

  directory 'application', "#{name}"

  Dir.chdir("#{Dir.pwd}/#{name}") do
    puts `bundle install`
  end
end

And the console output from running the command that calls this create method:

$ bundle exec bin/my_gem new test_app
Creating application test_app
      create  test_app
      create  test_app/Gemfile
      create  test_app/Guardfile
      create  test_app/README.md
      create  test_app/app/controllers
      create  test_app/app/helpers
      create  test_app/app/models
      create  test_app/app/views
Using thor (0.14.6) 
Using my_gem (0.0.1) 
Using bundler (1.1.3) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

As you can see, it is running bundle install but it's running it in my current directory (thor, bundler, my_gem), as opposed to the test_app directory (guard, guard-coffeescript, guard-less, and others) .

Running other commands such as ls or pwd give the expected results:

Gemfile
Guardfile
README.md
app

and

/Users/davidlumley/Development/Gems/my_gem/test_app

Not sure if it makes any difference, but I use RVM for managing my rubies.

Grolier answered 17/4, 2012 at 5:23 Comment(2)
"Not sure if it makes any difference, but I use RVM for managing my rubies." - Yes :)Grolier
Yes of course it manging ruby but with the help of rvm you should create gemset and use that gemset directory for installing gem and there will be no issues which you faced now..Gluconeogenesis
I
20

Sounds like your app is already using bundler and you have a bundler-inside-bundler problem. Try this:

Bundler.with_clean_env do
  puts `bundle install`
end

I'm guessing what's happening is that your outer bundler sets the BUNDLE_GEMFILE env variable to your app's Gemfile, and then your inner bundler ends up inheriting it.

Insensibility answered 23/4, 2012 at 5:37 Comment(0)
G
-1

Please try this i will sure helps you.

      rvm gemset create app_name


      rvm use ruby-1.9.2@app_name

Ruby version what else you used.

then install bundler gem

      gem install bundler.           

Then bundle install and run server..

Gluconeogenesis answered 17/4, 2012 at 5:47 Comment(3)
I'm using a fresh gemset at the moment, it has thor and bundler installed. The issue isn't that the bundle isn't getting installed, it's that my generator isn't running the command in the appropriate directory, and therefore it's using the wrong Gemfile.Grolier
Oh i have faced this problem then i use this trick.go to directory of app through command line and install all gem one by one and also sure after any gem either it is installed in the right gemset directory.Gluconeogenesis
I'm trying to automate that, which is why I'm trying to run bundle install programmatically, similar to the way rails does in its generators.Grolier

© 2022 - 2024 — McMap. All rights reserved.