Importing .py files embedded as resources (from Silverlight)

View: New views
5 Messages — Rating Filter:   Alert me  

Importing .py files embedded as resources (from Silverlight)

by thbar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

this is my first post here, so hi!

I'm currently porting some IronPython library I'd like to use from a C# or IronRuby Silverlight app. For that purpose, I'm creating a Silverlight C# library which embeds all the required .py files and try to compile/execute them at runtime.

Is there a built-in way of telling the IronPython engine that some resources are embedded in the dll ? Maybe some hooks to detect imports and return the stream of content for a given .py file ?

The IronPython library has multiple subfolders on several levels, for increased fun.

Should I iterate over all the available files and execute them in the same scope ?

Thanks for any insight when dealing with that kind of scenario,

cheers,

-- Thibaut

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Importing .py files embedded as resources (from Silverlight)

by Jimmy Schementi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
No special support; you'll have to iterate over all the files as resources, get their contents, and do the following:

var scope = scriptEngine.CreateScope();
scriptEngine.CreateScriptSourceFromString(code).Execute(scope);

Though, why not just put the python files in the XAP? Then importing will just work, since the engine knows how to look in the XAP. If you're really hellbent on having them as resources, you could built a custom version of Microsoft.Scripting.Silverlight.BrowserPAL to look for files as embedded resources.

~js

From: users-bounces@... [users-bounces@...] on behalf of Thibaut Barrère [thibaut.barrere@...]
Sent: Friday, June 19, 2009 12:37 AM
To: users@...
Subject: [IronPython] Importing .py files embedded as resources (from Silverlight)

Hello,

this is my first post here, so hi!

I'm currently porting some IronPython library I'd like to use from a C# or IronRuby Silverlight app. For that purpose, I'm creating a Silverlight C# library which embeds all the required .py files and try to compile/execute them at runtime.

Is there a built-in way of telling the IronPython engine that some resources are embedded in the dll ? Maybe some hooks to detect imports and return the stream of content for a given .py file ?

The IronPython library has multiple subfolders on several levels, for increased fun.

Should I iterate over all the available files and execute them in the same scope ?

Thanks for any insight when dealing with that kind of scenario,

cheers,

-- Thibaut

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Importing .py files embedded as resources (from Silverlight)

by thbar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jimmy,

No special support; you'll have to iterate over all the files as resources, get their contents, and do the following:

var scope = scriptEngine.CreateScope();
scriptEngine.CreateScriptSourceFromString(code).Execute(scope);

Though, why not just put the python files in the XAP? Then importing will just work, since the engine knows how to look in the XAP. If you're really hellbent on having them as resources, you could built a custom version of Microsoft.Scripting.Silverlight.BrowserPAL to look for files as embedded resources.

I just had a chat with Ivan and he suggested the same idea. For some reason I thought that it would be hard to mix .py and .rb directly, but the dlrconsole sample does that, it seems.

So I'm going to follow that advice and put the .py files into the XAP, and let the engine do the job.

I still have one question then: if the main app file is a Ruby one, how can I call the Python function from there ?

-- Thibaut

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Parent Message unknown Re: Importing .py files embedded as resources (from Silverlight)

by Jimmy Schementi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

You can execute Python code from Ruby in 2 ways:

 

1.       Use the Hosting API from Ruby. I have a “python.rb” lying around that I usually use which demonstrates what to do: http://gist.github.com/132558 (this one is for Silverlight, line 10 will have to be slightly changed for the Desktop).

2.       Use the DLR language interop. Read Tomas’ blogpost about it: http://blog.tomasm.net/2009/04/15/python-says-hello-to-ruby/

~js

 

From: users-bounces@... [mailto:users-bounces@...] On Behalf Of Thibaut Barrère
Sent: Friday, June 19, 2009 4:03 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Importing .py files embedded as resources (from Silverlight)

 

Hi Jimmy,


No special support; you'll have to iterate over all the files as resources, get their contents, and do the following:

var scope = scriptEngine.CreateScope();
scriptEngine.CreateScriptSourceFromString(code).Execute(scope);

Though, why not just put the python files in the XAP? Then importing will just work, since the engine knows how to look in the XAP. If you're really hellbent on having them as resources, you could built a custom version of Microsoft.Scripting.Silverlight.BrowserPAL to look for files as embedded resources.

 

I just had a chat with Ivan and he suggested the same idea. For some reason I thought that it would be hard to mix .py and .rb directly, but the dlrconsole sample does that, it seems.

 

So I'm going to follow that advice and put the .py files into the XAP, and let the engine do the job.

 

I still have one question then: if the main app file is a Ruby one, how can I call the Python function from there ?

 

-- Thibaut


_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Re: Importing .py files embedded as resources (from Silverlight)

by thbar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

       Use the Hosting API from Ruby. I have a “python.rb” lying around that I usually use which demonstrates what to do: http://gist.github.com/132558 (this one is for Silverlight, line 10 will have to be slightly changed for the Desktop).


I used that and after a bit of tweaking I got what I need.

Thanks!

-- Thibaut

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com