About circular dependencies in RubyGems (the library). And about theorder in $".

Discussion in 'Ruby' started by Erik Veenstra, Aug 1, 2008.

  1. [Note: parts of this message were removed to make it a legal post.]

    Hi,

    There's a circular dependency in RubyGems. I mean in the
    library itself, not in the collection of gems.

    Try this:

    $ RUBYOPT= ruby -e 'require "rubygems/exceptions"'
    /usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:19:
    uninitialized constant Gem::Exception (NameError)
    from
    /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:4:in `require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:4
    from
    /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:10:in `require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:10
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:767:in `require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:767
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/exceptions.rb:1:in
    `require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/exceptions.rb:1
    from -e:1:in `require'
    from -e:1

    The main script requires rubygems/exceptions.rb, which requires
    rubygems.rb, which requires rubygems/exceptions.rb (which is
    skipped since it has already been required (although is not yet
    listed in $"...)) and rubygems/source_index.rb, which requires
    rubygems/spec_fetcher.rb, which requires
    rubygems/remote_fetcher.rb, which defines class FetchError as a
    subclass of Gem::Exception, which fails since Gem::Exception
    has not yet been defined (rubygems/exceptions.rb is still on
    line 1).

    This causes RubyScript2Exe to fail. RubyScript2Exe sequentially
    requires every entry in $" when tracing the application. It's
    essentially doing this:

    $ export RUBYOPT=
    $ ruby -r $THE_LIBRARY -e 'puts $"' | xargs ruby -e 'ARGV.each{|x| puts x ;
    require x}'

    Which works for all libraries on my machine, except for
    RubyGems.

    The essence of the problem is a bit nasty: a library is only
    added to $" _after_ it's executed, so the order in which the
    libraries appear in $" is reversed. Well that's true for
    indirect dependencies (app requires a, which requires b, which
    requires c ==> $" == ["c.rb", "b.rb", "a.rb"], but not for
    sequential dependencies (app requires a, b and c ==> $" ==
    ["a.rb", "b.rb", "c.rb"]).

    Question: Is it possible to investigate the exact order in which
    libraries are required correctly? Obviously $" won't work. We
    can't wrap Kernel#require either, since you'll miss the
    libraries which are required on the command line or in $RUBYOPT.

    Any ideas/suggestions/comments?

    Thanks.

    gegroet,
    Erik V. - http://www.erikveen.dds.nl/
    Erik Veenstra, Aug 1, 2008
    #1
    1. Advertising

  2. Erik Veenstra

    Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    This is exactly the problem that brought me to rubytalk a week ago. I
    don't seem to have left yet :):grin::)

    My problem was solved by realising that I had too many 'require's -- I
    didn't need to require if the object in question was referenced inside
    a method definition. I don't know if that will help you.

    On 8/1/08, Erik Veenstra <> wrote:
    > Hi,
    >
    > There's a circular dependency in RubyGems. I mean in the
    > library itself, not in the collection of gems.
    >
    > Try this:
    >
    > $ RUBYOPT= ruby -e 'require "rubygems/exceptions"'
    > /usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:19:
    > uninitialized constant Gem::Exception (NameError)
    > from
    > /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:4:in `require'
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:4
    > from
    > /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:10:in `require'
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:10
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:767:in `require'
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:767
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/exceptions.rb:1:in
    > `require'
    > from /usr/local/lib/ruby/site_ruby/1.8/rubygems/exceptions.rb:1
    > from -e:1:in `require'
    > from -e:1
    >
    > The main script requires rubygems/exceptions.rb, which requires
    > rubygems.rb, which requires rubygems/exceptions.rb (which is
    > skipped since it has already been required (although is not yet
    > listed in $"...)) and rubygems/source_index.rb, which requires
    > rubygems/spec_fetcher.rb, which requires
    > rubygems/remote_fetcher.rb, which defines class FetchError as a
    > subclass of Gem::Exception, which fails since Gem::Exception
    > has not yet been defined (rubygems/exceptions.rb is still on
    > line 1).
    >
    > This causes RubyScript2Exe to fail. RubyScript2Exe sequentially
    > requires every entry in $" when tracing the application. It's
    > essentially doing this:
    >
    > $ export RUBYOPT=
    > $ ruby -r $THE_LIBRARY -e 'puts $"' | xargs ruby -e 'ARGV.each{|x| puts x ;
    > require x}'
    >
    > Which works for all libraries on my machine, except for
    > RubyGems.
    >
    > The essence of the problem is a bit nasty: a library is only
    > added to $" _after_ it's executed, so the order in which the
    > libraries appear in $" is reversed. Well that's true for
    > indirect dependencies (app requires a, which requires b, which
    > requires c ==> $" == ["c.rb", "b.rb", "a.rb"], but not for
    > sequential dependencies (app requires a, b and c ==> $" ==
    > ["a.rb", "b.rb", "c.rb"]).
    >
    > Question: Is it possible to investigate the exact order in which
    > libraries are required correctly? Obviously $" won't work. We
    > can't wrap Kernel#require either, since you'll miss the
    > libraries which are required on the command line or in $RUBYOPT.
    >
    > Any ideas/suggestions/comments?
    >
    > Thanks.
    >
    > gegroet,
    > Erik V. - http://www.erikveen.dds.nl/
    >



    --
    Me, I imagine places that I have never seen / The colored lights in
    fountains, blue and green / And I imagine places that I will never go
    / Behind these clouds that hang here dark and low
    But it's there when I'm holding you / There when I'm sleeping too /
    There when there's nothing left of me / Hanging out behind the
    burned-out factories / Out of reach but leading me / Into the
    beautiful sea
    , Aug 1, 2008
    #2
    1. Advertising

  3. Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    [Note: parts of this message were removed to make it a legal post.]

    > I didn't need to require if the object in question was
    > referenced inside a method definition.


    Could you please elaborate?

    Thanks.

    gegroet,
    Erik V. - http://www.erikveen.dds.nl/
    Erik Veenstra, Aug 1, 2008
    #3
  4. Erik Veenstra

    Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    Sure.

    Assuming you keep each class in a seperate file:

    require 'person'
    #require 'employee' # this is not necessary

    class Accountant < Person
    def initialize()
    @payrollid = Employee.getnewid()
    end
    end


    Of course, for the code to work, then somewhere in your application,
    *some* file must require employee. If you want to make sure that
    each file will require everything that it will need at runtime -- for
    example, if you are going to do unit testing -- then one solution is
    to do this:

    require 'person'

    class Accountant < Person
    require 'employee'

    def initialize()
    @payrollid = Employee.getnewid()
    end
    end



    On 8/1/08, Erik Veenstra <> wrote:
    >> I didn't need to require if the object in question was
    >> referenced inside a method definition.

    >
    > Could you please elaborate?
    >
    > Thanks.
    >
    > gegroet,
    > Erik V. - http://www.erikveen.dds.nl/
    >



    --
    Me, I imagine places that I have never seen / The colored lights in
    fountains, blue and green / And I imagine places that I will never go
    / Behind these clouds that hang here dark and low
    But it's there when I'm holding you / There when I'm sleeping too /
    There when there's nothing left of me / Hanging out behind the
    burned-out factories / Out of reach but leading me / Into the
    beautiful sea
    , Aug 1, 2008
    #4
  5. Erik Veenstra

    Ryan Davis Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    On Aug 1, 2008, at 06:54 , Erik Veenstra wrote:

    > There's a circular dependency in RubyGems. I mean in the
    > library itself, not in the collection of gems.


    I'll talk to eric about this at lunch (5 min).
    Ryan Davis, Aug 1, 2008
    #5
  6. Erik Veenstra

    Daniel Moore Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    Is there a work-around for getting rubyscript2exe to work in the meantime?

    On Fri, Aug 1, 2008 at 6:54 AM, Erik Veenstra <> wrote:
    > Hi,
    >
    > There's a circular dependency in RubyGems. I mean in the
    > library itself, not in the collection of gems.
    > This causes RubyScript2Exe to fail.


    --

    -Daniel
    Daniel Moore, Aug 3, 2008
    #6
  7. Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    [Note: parts of this message were removed to make it a legal post.]

    > Is there a work-around for getting rubyscript2exe to work in
    > the meantime?


    Add "require 'rubygems'" _in_ your application and temporarily
    remove rubygems from RUBYOPT before compiling:

    $ RUBYOPT= ruby rubyscript2exe.rb test.rb

    Or:

    C:\> unset RUBYOPT
    C:\> ruby rubyscript2exe.rb test.rb

    That seems to work. At least, on my machine...

    gegroet,
    Erik V. - http://www.erikveen.dds.nl/
    Erik Veenstra, Aug 3, 2008
    #7
  8. Erik Veenstra

    Eric Hodel Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    On Aug 1, 2008, at 06:54 AM, Erik Veenstra wrote:
    > There's a circular dependency in RubyGems. I mean in the
    > library itself, not in the collection of gems.
    >
    > Try this:
    >
    > $ RUBYOPT= ruby -e 'require "rubygems/exceptions"'
    > /usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:19:
    > uninitialized constant Gem::Exception (NameError)


    Yes, I could merge rubygems/exception.rb back into the appropriate
    places, but got lazy during my refactor. Can you file a bug for me in
    the rubygems tracker?

    > [...]
    >
    > Question: Is it possible to investigate the exact order in which
    > libraries are required correctly? Obviously $" won't work. We
    > can't wrap Kernel#require either, since you'll miss the
    > libraries which are required on the command line or in $RUBYOPT.
    >
    > Any ideas/suggestions/comments?


    I'm not sure what a good general solution to this problem is.
    Eric Hodel, Aug 7, 2008
    #8
  9. Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    > Can you file a bug for me in the rubygems tracker?

    Done.

    gegroet,
    Erik V.


    On 8/7/08, Eric Hodel <> wrote:
    > On Aug 1, 2008, at 06:54 AM, Erik Veenstra wrote:
    >> There's a circular dependency in RubyGems. I mean in the
    >> library itself, not in the collection of gems.
    >>
    >> Try this:
    >>
    >> $ RUBYOPT= ruby -e 'require "rubygems/exceptions"'
    >> /usr/local/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:19:
    >> uninitialized constant Gem::Exception (NameError)

    >
    > Yes, I could merge rubygems/exception.rb back into the appropriate
    > places, but got lazy during my refactor. Can you file a bug for me in
    > the rubygems tracker?
    >
    >> [...]
    >>
    >> Question: Is it possible to investigate the exact order in which
    >> libraries are required correctly? Obviously $" won't work. We
    >> can't wrap Kernel#require either, since you'll miss the
    >> libraries which are required on the command line or in $RUBYOPT.
    >>
    >> Any ideas/suggestions/comments?

    >
    > I'm not sure what a good general solution to this problem is.
    >
    >
    >
    Erik Veenstra, Aug 7, 2008
    #9
  10. Erik Veenstra

    Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    On 3 Aug, 11:58, Erik Veenstra <> wrote:
    > [Note:  parts of this message were removed to make it a legal post.]
    >
    > > Is there a work-around for getting rubyscript2exe to work in
    > > the meantime?

    >
    > Add "require 'rubygems'" _in_ your application and temporarily
    > remove rubygems from RUBYOPT before compiling:
    >
    >  $ RUBYOPT= ruby rubyscript2exe.rb test.rb
    >
    > Or:
    >
    >  C:\> unset RUBYOPT
    >  C:\> ruby rubyscript2exe.rb test.rb
    >
    > That seems to work. At least, on my machine...
    >
    > gegroet,
    > Erik V. -http://www.erikveen.dds.nl/


    This doesn't work on my XP machine with newest oneclick rubyinstall
    and rubygems 1.2 (same Gem::Exception error as usual)
    I've tried with both rubyscript2exe and rubyscript2exe.rb. Do you have
    any other workaround ideas until something is made about rubygems?
    , Aug 9, 2008
    #10
  11. Erik Veenstra

    Ryan Davis Guest

    Re: About circular dependencies in RubyGems (the library). And about the order in $".

    On Aug 8, 2008, at 19:18 , wrote:

    > This doesn't work on my XP machine with newest oneclick rubyinstall
    > and rubygems 1.2 (same Gem::Exception error as usual)
    > I've tried with both rubyscript2exe and rubyscript2exe.rb. Do you have
    > any other workaround ideas until something is made about rubygems?


    While there IS a fix that we can add to a file in rubygems, I think it
    is necessary to point out that rubyscript2exe is going to have these
    problems again and again. Depending on $LOADED_FEATURES is going to be
    problematic.

    Also, are you sure you added "require 'rubygems'" at the top of your
    app? It really should fix the issue.
    Ryan Davis, Aug 9, 2008
    #11
  12. Erik Veenstra

    Guest

    Re: About circular dependencies in RubyGems (the library). And aboutthe order in $".

    On 9 Aug, 11:52, Ryan Davis <> wrote:
    > On Aug 8, 2008, at 19:18 , wrote:
    >
    > > This doesn't work on  my XP machine with newest oneclick rubyinstall
    > > and rubygems 1.2 (same Gem::Exception error as usual)
    > > I've tried with both rubyscript2exe and rubyscript2exe.rb. Do you have
    > > any other workaround ideas until something is made about rubygems?

    >
    > While there IS a fix that we can add to a file in rubygems, I think it  
    > is necessary to point out that rubyscript2exe is going to have these  
    > problems again and again. Depending on $LOADED_FEATURES is going to be  
    > problematic.
    >
    > Also, are you sure you added "require 'rubygems'" at the top of your  
    > app? It really should fix the issue.



    I've tried with and without require 'rubygems' on top of hello.rb,
    actually I've tried all possible combinations of theese 4 lines:
    ---
    require "rubygems"
    # require "rubyscript2exe"
    # exit if RUBYSCRIPT2EXE.is_compiling?
    puts "hello world!"
    ---

    "rubyscript2exe hello.rb" always gives me this: http://pastie.org/250556

    (The remote_fetcher.rb:19: uninitialized constant Gem::Exception
    (NameError) error)
    , Aug 9, 2008
    #12
  13. Re: About circular dependencies in RubyGems (the library). And about the order in $".

    unknown wrote:
    > On 9 Aug, 11:52, Ryan Davis <> wrote:
    >> problematic.
    >>
    >> Also, are you sure you added "require 'rubygems'" at the top of your �
    >> app? It really should fix the issue.

    >
    >
    > I've tried with and without require 'rubygems' on top of hello.rb,
    > actually I've tried all possible combinations of theese 4 lines:
    > ---
    > require "rubygems"
    > # require "rubyscript2exe"
    > # exit if RUBYSCRIPT2EXE.is_compiling?
    > puts "hello world!"
    > ---
    >
    > "rubyscript2exe hello.rb" always gives me this: http://pastie.org/250556
    >
    > (The remote_fetcher.rb:19: uninitialized constant Gem::Exception
    > (NameError) error)


    Hi guys,

    I am a newbie with ruby. I have an identical problem as described above
    and my output matches http://pastie.org/250556. Is there a workaround /
    fix ? Have I missed anything?

    I am just using helloworld.rb

    Much appreciated..
    Andy.
    --
    Posted via http://www.ruby-forum.com/.
    Andrew Goifeld, Sep 19, 2008
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Suzanne Vogel
    Replies:
    2
    Views:
    2,613
    Suzanne Vogel
    Jun 26, 2003
  2. crichmon
    Replies:
    3
    Views:
    761
    crichmon
    Jun 28, 2004
  3. Dylan
    Replies:
    7
    Views:
    562
    Dylan
    Jul 7, 2004
  4. ernesto basc?n pantoja

    Circular dependencies

    ernesto basc?n pantoja, Nov 29, 2004, in forum: C++
    Replies:
    2
    Views:
    3,756
    Larry Brasfield
    Nov 29, 2004
  5. Kiuhnm
    Replies:
    16
    Views:
    737
    Jonathan Mcdougall
    Jan 3, 2005
Loading...

Share This Page