New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/tasks/resque.rake cannot load files from lib/ #1185

Closed
postmodern opened this Issue Mar 25, 2013 · 14 comments

Comments

Projects
None yet
3 participants
@postmodern
Contributor

postmodern commented Mar 25, 2013

When loading the Rakefile, I get this error message:

lib/tasks/resque.rake: cannot load such file -- foo

foo is located at lib/foo.rb. After checking $LOAD_PATH, it appears lib/ is not being added:

task :check do
  p $LOAD_PATH.include?(File.expand_path('lib'))
end

$ rake check
lib/tasks/resque.rake: cannot load such file -- foo
false
@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Mar 25, 2013

Member

Interesting, we did make a lot of changes to the rake task loading in 0.11.0, we'll take a look at this for 0.11.1

Member

nesquena commented Mar 25, 2013

Interesting, we did make a lot of changes to the rake task loading in 0.11.0, we'll take a look at this for 0.11.1

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 25, 2013

Member

I think should be normal since environment isn't loaded, this should work:

task :check => :environment do
  p $LOAD_PATH.include?(File.expand_path('lib'))
end
Member

DAddYE commented Mar 25, 2013

I think should be normal since environment isn't loaded, this should work:

task :check => :environment do
  p $LOAD_PATH.include?(File.expand_path('lib'))
end
@postmodern

This comment has been minimized.

Show comment
Hide comment
@postmodern

postmodern Mar 25, 2013

Contributor

lib/ directory should be added to $LOAD_PATH, so any additional rake tasks can load additional code.

Contributor

postmodern commented Mar 25, 2013

lib/ directory should be added to $LOAD_PATH, so any additional rake tasks can load additional code.

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Mar 26, 2013

Member

I think this is a decent idea, it's nice having the lib available even for rake tasks with no environment loaded. @postmodern can you confirm this is fixed on edge

Member

nesquena commented Mar 26, 2013

I think this is a decent idea, it's nice having the lib available even for rake tasks with no environment loaded. @postmodern can you confirm this is fixed on edge

@postmodern

This comment has been minimized.

Show comment
Hide comment
@postmodern

postmodern Mar 26, 2013

Contributor

Upgrading to edge causes this error when I run bundle exec rake -T:

undefined method `root' for Padrino:Module
lib/foo.rb
lib/tasks/resque.rake:3:in `require'
lib/tasks/resque.rake:3:in `'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:in `load'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:in `block in '
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:in `each'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:in `'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:in `load'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:in `init'
Contributor

postmodern commented Mar 26, 2013

Upgrading to edge causes this error when I run bundle exec rake -T:

undefined method `root' for Padrino:Module
lib/foo.rb
lib/tasks/resque.rake:3:in `require'
lib/tasks/resque.rake:3:in `'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:in `load'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:in `block in '
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:in `each'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:in `'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:in `load'
/home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:in `init'
@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Mar 26, 2013

Member

Without the Padrino environment loaded, I'm guessing Padrino.root simply doesn't exist. Shouldn't resque.rake include the Padrino environment? and or alternatively couldn't the tasks avoid Padrino.root (in cases where the environment isn't loaded)

Nathan Esquenazi

On Monday, March 25, 2013 at 8:31 PM, Postmodern wrote:

Upgrading to edge causes this error when I run bundle exec rake -T:
undefined method root' for Padrino:Module /path/to/lib/foo.rb lib/tasks/resque.rake:3:inrequire' lib/tasks/resque.rake:3:in ' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:inload' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:in block in ' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:ineach' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:in ' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:inload' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:in `init'


Reply to this email directly or view it on GitHub (#1185 (comment)).

Member

nesquena commented Mar 26, 2013

Without the Padrino environment loaded, I'm guessing Padrino.root simply doesn't exist. Shouldn't resque.rake include the Padrino environment? and or alternatively couldn't the tasks avoid Padrino.root (in cases where the environment isn't loaded)

Nathan Esquenazi

On Monday, March 25, 2013 at 8:31 PM, Postmodern wrote:

Upgrading to edge causes this error when I run bundle exec rake -T:
undefined method root' for Padrino:Module /path/to/lib/foo.rb lib/tasks/resque.rake:3:inrequire' lib/tasks/resque.rake:3:in ' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:inload' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:4:in block in ' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:ineach' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake_tasks.rb:2:in ' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:inload' /home/hal/.gem/ruby/1.9.1/bundler/gems/padrino-framework-3bc9980420cb/padrino-core/lib/padrino-core/cli/rake.rb:12:in `init'


Reply to this email directly or view it on GitHub (#1185 (comment)).

@postmodern

This comment has been minimized.

Show comment
Hide comment
@postmodern

postmodern Mar 26, 2013

Contributor

The resque:setup task does depend on environment. However, some constants in foo.rb use Padrino.root to generate absolute paths to various data files.

Contributor

postmodern commented Mar 26, 2013

The resque:setup task does depend on environment. However, some constants in foo.rb use Padrino.root to generate absolute paths to various data files.

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Mar 26, 2013

Member

Ah I see, the issue being that the rake task is being loaded before the Padrino environment which means no Padrino.root when you are using require in the rake task. Thoughts @DAddYE @skade @dariocravero ?

Member

nesquena commented Mar 26, 2013

Ah I see, the issue being that the rake task is being loaded before the Padrino environment which means no Padrino.root when you are using require in the rake task. Thoughts @DAddYE @skade @dariocravero ?

@postmodern

This comment has been minimized.

Show comment
Hide comment
@postmodern

postmodern Mar 26, 2013

Contributor

Is there another constant that represents the root or should I use the old File.join(File.dirname(__FILE__),'..',...) trick in lib/ files?

Contributor

postmodern commented Mar 26, 2013

Is there another constant that represents the root or should I use the old File.join(File.dirname(__FILE__),'..',...) trick in lib/ files?

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Mar 26, 2013

Member

Probably the easiest way to workaround this for now is to do the latter or this similar approach:

require File.expand_path('../../something/foo', __FILE__)

The constant PADRINO_ROOT unfortunately also is set at the same time that the environment is loaded. Also, using require_relative should work now as an alternative as well.

Member

nesquena commented Mar 26, 2013

Probably the easiest way to workaround this for now is to do the latter or this similar approach:

require File.expand_path('../../something/foo', __FILE__)

The constant PADRINO_ROOT unfortunately also is set at the same time that the environment is loaded. Also, using require_relative should work now as an alternative as well.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 26, 2013

Member

Generally I prefer to use task foo: :environment whenever is possible, since not all should depend on that, for example we can have a task like: rake install_deps that would fail if we depends on the environment.

Otherwise, if you like you can load the tiny env:

Change the first line in Rakefile from require 'bundler/setup to require './config/boot'

Everything should works fine.

Remember that this will load only a subset of padrino, if you need full deps, like models controllers app mailers etc... :environment do the trick.

Member

DAddYE commented Mar 26, 2013

Generally I prefer to use task foo: :environment whenever is possible, since not all should depend on that, for example we can have a task like: rake install_deps that would fail if we depends on the environment.

Otherwise, if you like you can load the tiny env:

Change the first line in Rakefile from require 'bundler/setup to require './config/boot'

Everything should works fine.

Remember that this will load only a subset of padrino, if you need full deps, like models controllers app mailers etc... :environment do the trick.

@DAddYE

This comment has been minimized.

Show comment
Hide comment
@DAddYE

DAddYE Mar 26, 2013

Member
  • updated with typo fixes
Member

DAddYE commented Mar 26, 2013

  • updated with typo fixes
@postmodern

This comment has been minimized.

Show comment
Hide comment
@postmodern

postmodern Mar 26, 2013

Contributor

Updated all constants to use File.dirname(__FILE__) instead of Padrino.root. Confirmed edge fixed the $LOAD_PATH issue.

Contributor

postmodern commented Mar 26, 2013

Updated all constants to use File.dirname(__FILE__) instead of Padrino.root. Confirmed edge fixed the $LOAD_PATH issue.

@nesquena

This comment has been minimized.

Show comment
Hide comment
@nesquena

nesquena Mar 26, 2013

Member

OK I think this is good enough for now IMO, closing.

Member

nesquena commented Mar 26, 2013

OK I think this is good enough for now IMO, closing.

@nesquena nesquena closed this Mar 26, 2013

WaYdotNET added a commit to WaYdotNET/padrino-framework that referenced this issue Mar 26, 2013

Merge remote-tracking branch 'upstream/master' into all-custom-error
* upstream/master:
  have plugin generator respect root option
  Fix very strange bug with form_for and capture_html @ujifgc padrino#1177
  [padrino-core/rake] Adds lib as a load_path for rake tasks padrino#1185
  [form_helpers] Use count instead of size (Closes padrino#1184)
  [format_helpers] Mark escaped text as html_safe (Closes padrino#1183)
  Closes padrino#1179 for accidental appended extensions for js urls
  format activerecord migrate
  formatting activerecord migration test
  Thanks to @kenkeiter for bringing up the fact that http_router [is missing PATCH](https://github.com/joshbuddy/http_router/blob/master/lib/http_router/route.rb#L5).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment