Sven Fuchs
2007-Dec-09 12:56 UTC
Different order of plugin load_paths in $LOAD_PATHS and Dependencies
I was just about to submit the following ticket including a patch for Rails 2.0. But then I noticed that this behaviour hasn''t been invented with the recent refactorings of the plugin loading mechanism but was already there in Rails 1.2.x: http://dev.rubyonrails.org/browser/tags/rel_1-2-6/railties/lib/initializer.rb#L393 Therefor I thought it might make more sense to submit this to the mailinglist first for discussion. So, is there a particular reason for this behaviour? # Different order of plugin load_paths in $LOAD_PATHS and Dependencies In Rails::Plugin::Loader#add_plugin_load_paths paths are inserted into $LOAD_PATHS in reverse alphabetical order so that plugins loaded later will take precedence over plugins loaded earlier. (This has been described as the intended behaviour here: http://www.ruby-forum.com/topic/133009) However these paths are appended to Dependencies.load_paths and Dependencies.load_once_paths so they will appear in alphabetical order in these array. http://dev.rubyonrails.org/browser/tags/rel_2-0-1/railties/lib/rails/plugin/loader.rb#L44 So in effect if there are two files with the same name in two different plugins like these ... /plugins/plugin_a/lib/something.rb /plugins/plugin_b/lib/something.rb ... require ''something'' will load the one with latter file while using Dependencies constant autoloading will load the former file: require ''something'' # loads /plugins/plugin_b/lib/something.rb (correct) Something # loads /plugins/plugin_a/lib/something.rb (wrong) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~--- -- sven fuchs svenfuchs@artweb-design.de artweb design http://www.artweb-design.de grünberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile)
Frederick Cheung
2007-Dec-09 15:55 UTC
Re: Different order of plugin load_paths in $LOAD_PATHS and Dependencies
On 9 Dec 2007, at 12:56, Sven Fuchs wrote:> I was just about to submit the following ticket including a patch for > Rails 2.0. But then I noticed that this behaviour hasn''t been invented > with the recent refactorings of the plugin loading mechanism but was > already there in Rails 1.2.x: http://dev.rubyonrails.org/browser/tags/rel_1-2-6/railties/lib/initializer.rb#L393 > > Therefor I thought it might make more sense to submit this to the > mailinglist first for discussion. > > So, is there a particular reason for this behaviour? >In days of old, this meant that ''your'' stuff would be top of the list when your init.rb ran, but that''s no longer the case. Just my opinion, but I wouldn''t think you''d ever want to be relying on a specific load path ordering Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Chad Woolley
2007-Dec-10 20:44 UTC
Re: Different order of plugin load_paths in $LOAD_PATHS and Dependencies
On Dec 9, 2007 5:56 AM, Sven Fuchs <svenfuchs@artweb-design.de> wrote:> I was just about to submit the following ticket including a patch for > Rails 2.0. But then I noticed that this behaviour hasn''t been invented > with the recent refactorings of the plugin loading mechanism but was > already there in Rails 1.2.x: http://dev.rubyonrails.org/browser/tags/rel_1-2-6/railties/lib/initializer.rb#L393 > > Therefor I thought it might make more sense to submit this to the > mailinglist first for discussion. > > So, is there a particular reason for this behaviour? > > > # Different order of plugin load_paths in $LOAD_PATHS and Dependencies > > In Rails::Plugin::Loader#add_plugin_load_paths paths are inserted into > $LOAD_PATHS in reverse alphabetical order so that plugins loaded later > will take precedence over plugins loaded earlier. (This has been > described as the intended behaviour here: http://www.ruby-forum.com/topic/133009) > > However these paths are appended to Dependencies.load_paths and > Dependencies.load_once_paths so they will appear in alphabetical order > in these array. > > http://dev.rubyonrails.org/browser/tags/rel_2-0-1/railties/lib/rails/plugin/loader.rb#L44 > > So in effect if there are two files with the same name in two > different plugins like these ... > > /plugins/plugin_a/lib/something.rb > /plugins/plugin_b/lib/something.rb > > ... require ''something'' will load the one with latter file while using > Dependencies constant autoloading will load the former file: > > require ''something'' # loads /plugins/plugin_b/lib/something.rb (correct) > Something # loads /plugins/plugin_a/lib/something.rb (wrong) >Check out the thread recently called ''Are plugins supposed to be loaded alphabetically?'' We explored this in depth, and I think the current behavior is correct. Bottom line, you SHOULDN''T have identically named files on your load path and depend on load path order. If you don''t agree with that, it''s a separate issue. I think I agree with it :) -- Chad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Sven Fuchs
2007-Dec-12 16:34 UTC
Re: Different order of plugin load_paths in $LOAD_PATHS and Dependencies
Hi Frederick, hi Chad, thanks for your responses. No offense, but I think both of you missed the point here. Am 10.12.2007 um 21:44 schrieb Chad Woolley:> Check out the thread recently called ''Are plugins supposed to be > loaded alphabetically?'' We explored this in depth, and I think the > current behavior is correct.I even linked to that thread. And no, it doesn''t explore this issue.> Bottom line, you SHOULDN''T have > identically named files on your load path and depend on load path > order.I''m not talking about load path order. In fact, the current implementation in Plugin::Loader makes sure that the issue is present no matter in which order plugins are loaded: plugin load_paths are appended to the end of Dependencies.load_paths, but unshifted to the front (sort of, you get the point) of $LOAD_PATHS. (see lines 47-49 in rails/plugin/loader.rb) Thus, no matter how the load order of two plugins is specified, if you have two files with the same filenames in your plugin load_paths, the following statements will load different files: require "something" # uses $LOAD_PATH Something.called # uses Dependencies.load_paths -- sven fuchs svenfuchs@artweb-design.de artweb design http://www.artweb-design.de grünberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Chad Woolley
2007-Dec-12 19:17 UTC
Re: Different order of plugin load_paths in $LOAD_PATHS and Dependencies
On Dec 12, 2007 9:34 AM, Sven Fuchs <svenfuchs@artweb-design.de> wrote:> I even linked to that thread. And no, it doesn''t explore this issue.Sorry, should have read closer :/> I''m not talking about load path order. > > In fact, the current implementation in Plugin::Loader makes sure that > the issue is present no matter in which order plugins are loaded: > plugin load_paths are appended to the end of Dependencies.load_paths, > but unshifted to the front (sort of, you get the point) of > $LOAD_PATHS. (see lines 47-49 in rails/plugin/loader.rb) > > Thus, no matter how the load order of two plugins is specified, if you > have two files with the same filenames in your plugin load_paths, the > following statements will load different files: > > require "something" # uses $LOAD_PATH > Something.called # uses Dependencies.load_pathsI get it. If this is the case, it does seem like a bug to me. As mentioned in the other thread, I think the official position still seems to be that you shouldn''t have identically-named files, which would make this a moot point. However, given that 1) this bug didn''t exist before, 2) there''s probably plenty of plugins out there that do rely on the identically-named-file approach, 3) some people won''t want to buy into the idea that identically named files are bad, then it seems like this should be fixed. -- Chad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Sven Fuchs
2008-Jan-07 20:59 UTC
Re: Different order of plugin load_paths in $LOAD_PATHS and Dependencies
Ok, I now created a ticket for this and added a patch accordingly. See http://dev.rubyonrails.org/ticket/10737 Anybody mind to check this out? Thanks! Am 12.12.2007 um 20:17 schrieb Chad Woolley:> > On Dec 12, 2007 9:34 AM, Sven Fuchs <svenfuchs@artweb-design.de> > wrote: >> I even linked to that thread. And no, it doesn''t explore this issue. > > Sorry, should have read closer :/ > >> I''m not talking about load path order. >> >> In fact, the current implementation in Plugin::Loader makes sure that >> the issue is present no matter in which order plugins are loaded: >> plugin load_paths are appended to the end of Dependencies.load_paths, >> but unshifted to the front (sort of, you get the point) of >> $LOAD_PATHS. (see lines 47-49 in rails/plugin/loader.rb) >> >> Thus, no matter how the load order of two plugins is specified, if >> you >> have two files with the same filenames in your plugin load_paths, the >> following statements will load different files: >> >> require "something" # uses $LOAD_PATH >> Something.called # uses Dependencies.load_paths > > I get it. If this is the case, it does seem like a bug to me. As > mentioned in the other thread, I think the official position still > seems to be that you shouldn''t have identically-named files, which > would make this a moot point. However, given that 1) this bug didn''t > exist before, 2) there''s probably plenty of plugins out there that do > rely on the identically-named-file approach, 3) some people won''t want > to buy into the idea that identically named files are bad, then it > seems like this should be fixed. > > -- Chad > > >-- sven fuchs svenfuchs@artweb-design.de artweb design http://www.artweb-design.de grünberger 65 + 49 (0) 30 - 47 98 69 96 (phone) d-10245 berlin + 49 (0) 171 - 35 20 38 4 (mobile) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---