Forum: IronRuby Accessing open-uri from the same directory

Posted by Mohammad Azam (azamsharp)
on 2009-06-16 23:46
Hi,

I am have placed open-uri in the same directory as my application and I
am trying to include open-uri in my application using the require
attribute.

require File.dirname(__FILE__) + '/open-uri'

It throws the following error:



C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs>ir test.rb
:0:in `require': no such file to load -- uri (LoadError)
        from ./open-uri.rb:1
        from test.rb:4
        from :0:in `require'

Thanks,
Posted by Shay Friedman (shayfriedman)
on 2009-06-17 06:11
Hi Mohammad,

It happens because open-uri tries to load the uri library and it fails 
to find it.

I couldn't reproduce this behavior on my end...
The uri library should be located at 
<path_to_merlin>\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\uri.rb
Is there a chance you're changing the $LOAD_PATH array?

By the way, why would you want to copy the open-uri lib to your 
application directory? The standard library folder is a part of the file 
lookup paths, so no matter where your application is installed to, the 
standard libraries (like open-uri) will still be available.

Shay.
----------------------------
Shay Friedman
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 10:03
(Received via mailing list)
it can be useful when  you want to deploy your application to systems 
where
you don't know if ironruby is installed etc. I'm doing the same for an
ironrubymvc application.
I still have to find a nicer solution to that maybe by reusing the 
ironruby
configuration to make those paths configurable.
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Shay Friedman (shayfriedman)
on 2009-06-17 10:06
How can IronRuby work if it's not installed?
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 10:16
(Received via mailing list)
it are just DLL's you could host them inside your own application.ir.exe
also calls out to those libraries to do its work
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 16:34
I am using the following code to scrape the webpage.

button = Button.new
button.Text = 'Scrape URL'
button.Location = System::Drawing::Point.new(108,61)
button.click  do |sender,args|

  page = File.open("http://www.azamsharp.com/Default.aspx")
  System::Windows::Forms::MessageBox.Show(page.read)

end

I get the following error message:

Invalid argument - URI formats are not supported
Posted by Shay Friedman (shayfriedman)
on 2009-06-17 17:13
You're trying to use the File class to open URIs which is not supported.
Try open instead of File.open (and add require "open-uri" as well).

Shay.
----------------------------
Shay Friedman
http://www.ironshay.com
Follow me: http://twitter.com/ironshay
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 17:17
(Received via mailing list)
if you have openuri required
just remove the File that should work
or

uri = URI.parse("http://somewhere.com/default.aspx")
uri.open do |f|
  #some logic here
end

or

you could just use

open("http://somewhere.com/default.aspx") do |f|
   # some logic here
end

taken from
http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI.html
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 18:55
If I put:

require 'open-uri'

then it throws the error that error locating the file 'open-uri'.

I used the following code:

def scrape_page()

uri = URI.parse("http://somewhere.com/default.aspx")

end

And now it throws the exception:

Unintitialzied constant Object: URI



Ivan Porto carrero wrote:
> if you have openuri required
> just remove the File that should work
> or
> 
> uri = URI.parse("http://somewhere.com/default.aspx")
> uri.open do |f|
>   #some logic here
> end
> 
> or
> 
> you could just use
> 
> open("http://somewhere.com/default.aspx") do |f|
>    # some logic here
> end
> 
> taken from
> http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/classes/OpenURI.html
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Blog: http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 19:00
I tried to add a require 'open-uri' but for some reason it is not able 
to locate the open-uri files.

I have placed the open-uri in the libs folder and I said:

require 'libs/open-uri' but it is not able to locate the file.
Posted by Shay Friedman (shayfriedman)
on 2009-06-17 19:22
Can you check if the open-uri.rb file exists in the folder:
<path_to_merlin>\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 19:22
(Received via mailing list)
what version of ironruby are you using?it looks like your search paths 
are
messed up.

for example does require File.dirname(__FILE__) + '/libs/open-uri' work?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 19:24
I have placed the open-uri file in the libs folder within the project. 
But for some reason it blows up and says unable to locate open-uri file.
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 19:25
I tried with the path and got the following error:

require File.dirname(__FILE__) + '/libs/open-uri'

C:\IronRubyProjects\IronRubyTaskListApplication>ir main_form.rb
:0:in `require': no such file to load -- uri (LoadError)
        from ./libs/open-uri.rb:1
        from main_form.rb:4
        from :0:in `require'


Ivan Porto carrero wrote:
> what version of ironruby are you using?it looks like your search paths 
> are
> messed up.
> 
> for example does require File.dirname(__FILE__) + '/libs/open-uri' work?
> 
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Blog: http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 19:26
Here is the version:


C:\IronRubyProjects\IronRubyTaskListApplication>ir -v
IronRuby 0.5.0.0 on .NET 2.0.0.0
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 19:31
(Received via mailing list)
ok you also need the uri file
open-uri has a dependency on that file.

But still I think your search paths are messed up.
how does you config look like?
Where is ironruby located

did you pick a release or build from git?
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 19:39
(Received via mailing list)
are you hosting ironruby in your application or are you using the ir 
command
to run it?
Are the paths correct in ir.exe.config?
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 19:48
I am using ir command to run it. It is all ruby code.

I went to the 
C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8 
folder and run the following code:

require 'open-uri'

it asked for stringio (not sure why it was missing) so I placed it in 
the 1.8 folder and ran again and it worked. But now when I use the same 
files for my project libs/stringio.rb it does not work.


C:\IronRubyProjects\IronRubyTaskListApplication>ir main_form.rb
:0:in `require': no such file to load -- uri (LoadError)
        from ./libs/open-uri.rb:1
        from main_form.rb:4
        from :0:in `require'

Posted by Mohammad Azam (azamsharp)
on 2009-06-17 20:00
Actually I checked using the ir.exe command line and it did not work 
either. It seems like the

C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8

and

C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs

contains duplicate rb files. One open-uri is for url and other is for 
file system. I think the dependencies are messed up!
Posted by Ivan Porto carrero (casualjim)
on 2009-06-17 20:12
(Received via mailing list)
for me the compiled binaries end up in:

C:\tools\ironruby\merlin\main\bin\debug

and this is how the relevant tag looks like in that ir.exe.config file

<set option='LibraryPaths' language='Ruby'
value='..\..\Languages\Ruby\libs;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\Ruby-1.8.6p287\lib\ruby\site_ruby\1.8;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\Ruby-1.8.6p287\lib\ruby\site_ruby;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\Ruby-1.8.6p287\lib\ruby\1.8'/>


I know it's lame but it works for me.

+ C:\tools\ironruby
(master) » ir
IronRuby 0.5.0.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'open-uri'
=> true
>>>


---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 20:20
I have the exact same path in the ir.exe.config file. But I can only run 
the open-uri if I am in the lib folder where the file is physically 
located.

This is really strange!
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 20:22
Here is the part of the ir.exe.config file.


 <microsoft.scripting>
    <languages>
      <language names="IronPython;Python;py" extensions=".py" 
displayName="IronPython 2.6 Alpha" 
type="IronPython.Runtime.PythonContext, IronPython, Version=2.6.0.10, 
Culture=neutral, PublicKeyToken=null" />
      <language names="IronRuby;Ruby;rb" extensions=".rb" 
displayName="IronRuby" type="IronRuby.Runtime.RubyContext, IronRuby, 
Version=0.5.0.0, Culture=neutral, PublicKeyToken=null" />
    </languages>

    <options>
      <set language="Ruby" option="LibraryPaths" 
value="..\..\Languages\Ruby\libs\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\site_ruby\1.8\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\" 
/>
    </options>
  </microsoft.scripting>
Posted by Jim Deville (Guest)
on 2009-06-17 20:26
(Received via mailing list)
Usually, the one in
> C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs

Contains hacks or workarounds to load the correct one from

> C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\re
> dist-libs\ruby\1.8

In other cases, the first one may simply load code from C#.

What does your ir.exe.config look like?

Thanks,
JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-17 20:27
Here is the complete ir.exe.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="microsoft.scripting" 
type="Microsoft.Scripting.Hosting.Configuration.Section, 
Microsoft.Scripting, Version=0.9.6.10, Culture=neutral, 
PublicKeyToken=null" requirePermission="false" />
  </configSections>

  <microsoft.scripting>
    <languages>
      <language names="IronPython;Python;py" extensions=".py" 
displayName="IronPython 2.6 Alpha" 
type="IronPython.Runtime.PythonContext, IronPython, Version=2.6.0.10, 
Culture=neutral, PublicKeyToken=null" />
      <language names="IronRuby;Ruby;rb" extensions=".rb" 
displayName="IronRuby" type="IronRuby.Runtime.RubyContext, IronRuby, 
Version=0.5.0.0, Culture=neutral, PublicKeyToken=null" />
    </languages>

    <options>
      <set language="Ruby" option="LibraryPaths" 
value="..\..\Languages\Ruby\libs\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\site_ruby\1.8\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\" 
/>
    </options>
  </microsoft.scripting>
</configuration>
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.