[IronPython] Transparent import of dlls?

2011-03-29 Thread Markus Schaber
Hi,

 

I have some questions that may seem stupid, but I did not find the right
answers yet. So simple pointers to the correct google query are as
welcome as elaborate Howtos. J

 

For cPython, it is possible to compile a module into a .pyc file. If
this file resides in sys.path, it is transparently used instead of the
.py source file. (We can ignore the exact details of lookup and version
dependency here.)

 

For IronPython, there is the pyc.py compiler script. This allows a
python module to be precompiled into a .NET dll. However, it seems that
it is not used transparently when placed in a directory in sys.path, one
has to explicitly add a Reference to the dll (via clr.AddReference or
hosting API).

 

Now my questions:

 

Is there any way to make this work transparently? (e. G. via a Flag to
the interpreter, or a modified import() function, or renaming the .dll
to .pyc?)

 

Is there a way to extend this mechanism to python modules created in C#?
(Creating a foo.dll that contains a foo module created via
PythonModuleAttribute, similar to the way the modules in
Ironpython.Modules.dll are created).

 

We're currently using IronPytho 2.6 in a hosted .NET 2 environment.

 

Thanks a lot,

 

Regards,

Markus

 

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


[IronPython] IronLanguages

2011-03-29 Thread Matthias

Hello,

this question is not 100% targeted at IronPython, but I didn't know a  
better list to write to.


I've started writing a C# - javascript bridge. Unlike IronPython and  
IronRuby I don't want to write a javascript engine in .net, but rather use  
existing ones. I can already access C# classes from javascript and  
instance them. The opposite way turns out to be much harder for non-PODs.  
Example:


public class JSObject
{
// has members like GetProperty/SetProperty which can act upon the  
javascript object

}

public class TestClass
{
public string message = This is a C# string;
}

public class TestApp
{
public string testComplexObject(TestClass obj)
{
return obj.message;
}

public void runTest()
{
JSObject jsObj = ...;
string message = testComplexObject(jsObj);
}
}

The problem here is the testComplexObject(jsObj) call. Of course the  
jsObj cannot be converted directly to a TestClass, because it's an  
arbitrary javascript object.


I am wondering how IronPython solves this problem. I've read the sources a  
bit and it seems it makes use of IDynamicMetaObjectProvider etc. If  
JSObject provided IDynamicMetaObjectProvider, would it allow converting  
the jsObj to a TestClass obj? How?


It's not easy to find information on using the DLR for things like this on  
the net, so I've asked here. Apologies if I am off-topic.


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


Re: [IronPython] Transparent import of dlls?

2011-03-29 Thread Jeff Hardy
On Tue, Mar 29, 2011 at 4:30 AM, Markus Schaber
m.scha...@3s-software.com wrote:
 For IronPython, there is the pyc.py compiler script. This allows a python
 module to be precompiled into a .NET dll. However, it seems that it is not
 used transparently when placed in a directory in sys.path, one has to
 explicitly add a Reference to the dll (via clr.AddReference or hosting API).


That, currently, is the only way to do it.

 We’re currently using IronPytho 2.6 in a hosted .NET 2 environment.

For ipy.exe, there's a special directory called 'DLLs' that it reads
on startup and does the hosting equivalent of clr.AddReference for
each .dll in the folder. That's about the best you can do right now.

I've been thinking of adding support for .ipyd files (similar to
Python .pyd files), which could handle this case, but haven't thought
it through yet.

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


Re: [IronPython] IronLanguages

2011-03-29 Thread Bill Chiles
You'll want to look at the DLR overview doc and then the Sympl sample 
walkthrough doc:
http://dlr.codeplex.com/wikipage?title=Docs%20and%20specsreferringTitle=HomeProjectName=dlr
 

You'll want to type the parameter to testComplexObject as 'dynamic' and 
implement IDMOP on JSObject, which you can see how to do from the Sympl sample. 
 Now, the Sympl sample is VERY light on real .NET bindin, but if it all maps to 
GetProp/SetProp, then maybe this is fine.  If you might flow into your code a 
regular C# object (not just a JSObj), then you may want to make use of the 
DefaultBinder from the DLR project, which is what the Iron languages use to get 
much richer binding.  You could also make use of the C# runtime binder to get 
C#'s semantics for binding members of objects at runtime, but you get that for 
free if you declare the parameter 'dynamic' and have your JSOjbectMetaObject 
simply punt whenever the object is not a derived type of JSObject.  You get 
that for free because you'll call back on the binder at the obj.message call 
site, and C# will have compiled that callsite to use its binder.

Bill

-Original Message-
From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Matthias
Sent: Tuesday, March 29, 2011 3:34 AM
To: users@lists.ironpython.com
Subject: [IronPython] IronLanguages

Hello,

this question is not 100% targeted at IronPython, but I didn't know a  
better list to write to.

I've started writing a C# - javascript bridge. Unlike IronPython and  
IronRuby I don't want to write a javascript engine in .net, but rather use  
existing ones. I can already access C# classes from javascript and  
instance them. The opposite way turns out to be much harder for non-PODs.  
Example:

public class JSObject
{
 // has members like GetProperty/SetProperty which can act upon the  
javascript object
}

public class TestClass
{
 public string message = This is a C# string;
}

public class TestApp
{
 public string testComplexObject(TestClass obj)
 {
 return obj.message;
 }

 public void runTest()
 {
 JSObject jsObj = ...;
 string message = testComplexObject(jsObj);
 }
}

The problem here is the testComplexObject(jsObj) call. Of course the  
jsObj cannot be converted directly to a TestClass, because it's an  
arbitrary javascript object.

I am wondering how IronPython solves this problem. I've read the sources a  
bit and it seems it makes use of IDynamicMetaObjectProvider etc. If  
JSObject provided IDynamicMetaObjectProvider, would it allow converting  
the jsObj to a TestClass obj? How?

It's not easy to find information on using the DLR for things like this on  
the net, so I've asked here. Apologies if I am off-topic.

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

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


[IronPython] IPy 2.7 successfully built for .NET 3.5, but problem w. indirect v4 dependencies

2011-03-29 Thread Jaromír Matýšek
Hi,
I've suceeded building 2.7 for .NET 3.5 (I'm using it in SharePoint, so 
there's no way to use .NET 4) and it works, using v2release configuration. 
I've built IronPython, IronPython.Modules, Microsoft.Dynamic, 
Microsoft.Scripting and Microsoft.Scripting.Core dlls.

However, when I reference my class library (which is referencing my 
custom-built 2.7 dlls) from another solution and try to compile, I get 
several instances of the following warning and of course errors wherever I'm 
using some of my class library functions:

The primary reference SPTools ...  could not be resolved because it has an 
indirect dependency on the .NET Framework assembly mscorlib, 
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 which has 
a higher version 4.0.0.0 than the version 2.0.0.0 in the current target 
framework.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets

I've now spent a day and half trying to get rid of this problem. I've combed 
through the project files - they're all switched to v2, there's nothing even 
vaguely v4 related, it all compiles too, the problem remains.

I'd be very grateful for any ideas. 

Thanks
Jaromír Matýšek

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


Re: [IronPython] IronLanguages

2011-03-29 Thread Dino Viehland
Just to chime in on how to do the conversion: the answer is that you probably 
can't, at least not for something like TestClass.  You could look at what sort 
of type you're converting from in JS (number, string, function, etc...) and see 
if TestClass has any implicit conversions to it from primitive .NET types 
(double, string, delegate, etc...) and if so you could invoke one of those 
conversions.  But most likely you won't be able to convert directly to 
TestClass.  If TestClass was something more like IList then you could do a 
conversion there as well.  The only way you're likely able to convert to 
TestClass is if the user got a TestClass object from .NET, brought it into JS 
(where you wrapped it in some object of your own), and then you brought it back 
to .NET - but then when you bring it back to .NET you should bring it back as 
the real TestClass instead of your wrapped TestClass.

The only other way would be figuring out somehow to allow a JavaScript 
developer to subclass a .NET TestClass type.  We allow this in IronPython via 
our NewTypeMaker class but we are lucky in that everything is in the .NET 
world.  One way you could go about this is having a function like CreateClass 
which takes a subtype (TestClass) and a dictionary of string - JS functions 
which you then call into for the implementation of the various subclass 
methods.  You would then have a .NET type which is being extended by JavaScript 
- there's probably going to be some fun and tricky problems in doing this 
though.  Then the user can call the resulting class you give them, they'll get 
an instance which is wrapped in JavaScript, and when you pass it back to .NET 
you can unwrap it.


-Original Message-
From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Bill Chiles
Sent: Tuesday, March 29, 2011 9:57 AM
To: Discussion of IronPython
Subject: Re: [IronPython] IronLanguages

You'll want to look at the DLR overview doc and then the Sympl sample 
walkthrough doc:
http://dlr.codeplex.com/wikipage?title=Docs%20and%20specsreferringTitle=HomeProjectName=dlr
 

You'll want to type the parameter to testComplexObject as 'dynamic' and 
implement IDMOP on JSObject, which you can see how to do from the Sympl sample. 
 Now, the Sympl sample is VERY light on real .NET bindin, but if it all maps to 
GetProp/SetProp, then maybe this is fine.  If you might flow into your code a 
regular C# object (not just a JSObj), then you may want to make use of the 
DefaultBinder from the DLR project, which is what the Iron languages use to get 
much richer binding.  You could also make use of the C# runtime binder to get 
C#'s semantics for binding members of objects at runtime, but you get that for 
free if you declare the parameter 'dynamic' and have your JSOjbectMetaObject 
simply punt whenever the object is not a derived type of JSObject.  You get 
that for free because you'll call back on the binder at the obj.message call 
site, and C# will have compiled that callsite to use its binder.

Bill

-Original Message-
From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Matthias
Sent: Tuesday, March 29, 2011 3:34 AM
To: users@lists.ironpython.com
Subject: [IronPython] IronLanguages

Hello,

this question is not 100% targeted at IronPython, but I didn't know a better 
list to write to.

I've started writing a C# - javascript bridge. Unlike IronPython and IronRuby 
I don't want to write a javascript engine in .net, but rather use existing 
ones. I can already access C# classes from javascript and instance them. The 
opposite way turns out to be much harder for non-PODs.  
Example:

public class JSObject
{
 // has members like GetProperty/SetProperty which can act upon the 
javascript object }

public class TestClass
{
 public string message = This is a C# string; }

public class TestApp
{
 public string testComplexObject(TestClass obj)
 {
 return obj.message;
 }

 public void runTest()
 {
 JSObject jsObj = ...;
 string message = testComplexObject(jsObj);
 }
}

The problem here is the testComplexObject(jsObj) call. Of course the jsObj 
cannot be converted directly to a TestClass, because it's an arbitrary 
javascript object.

I am wondering how IronPython solves this problem. I've read the sources a bit 
and it seems it makes use of IDynamicMetaObjectProvider etc. If JSObject 
provided IDynamicMetaObjectProvider, would it allow converting  
the jsObj to a TestClass obj? How?

It's not easy to find information on using the DLR for things like this on the 
net, so I've asked here. Apologies if I am off-topic.

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

___
Users mailing list
Users@lists.ironpython.com

Re: [IronPython] IPy 2.7 successfully built for .NET 3.5, but problem w. indirect v4 dependencies

2011-03-29 Thread Dino Viehland
It sounds like you need to re-build your own DLLs (or whatever SPTools is) to 
run against .NET 3.5 instead of .NET 4.0.

From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Jaromír Matýšek
Sent: Monday, March 28, 2011 8:09 AM
To: iro...@googlegroups.com
Subject: [IronPython] IPy 2.7 successfully built for .NET 3.5, but problem w. 
indirect v4 dependencies

Hi,
I've suceeded building 2.7 for .NET 3.5 (I'm using it in SharePoint, so there's 
no way to use .NET 4) and it works, using v2release configuration. I've built 
IronPython, IronPython.Modules, Microsoft.Dynamic, Microsoft.Scripting and 
Microsoft.Scripting.Core dlls.

However, when I reference my class library (which is referencing my 
custom-built 2.7 dlls) from another solution and try to compile, I get several 
instances of the following warning and of course errors wherever I'm using some 
of my class library functions:

The primary reference SPTools ...  could not be resolved because it has an 
indirect dependency on the .NET Framework assembly mscorlib, Version=4.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089 which has a higher version 
4.0.0.0 than the version 2.0.0.0 in the current target framework.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets

I've now spent a day and half trying to get rid of this problem. I've combed 
through the project files - they're all switched to v2, there's nothing even 
vaguely v4 related, it all compiles too, the problem remains.

I'd be very grateful for any ideas.

Thanks
Jaromír Matýšek
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] IronLanguages

2011-03-29 Thread Matthias

Am 29.03.2011, 18:57 Uhr, schrieb Bill Chiles bill...@microsoft.com:

You'll want to look at the DLR overview doc and then the Sympl sample  
walkthrough doc:

http://dlr.codeplex.com/wikipage?title=Docs%20and%20specsreferringTitle=HomeProjectName=dlr


Thanks for the link, it will keep me busy for a while :)


You'll want to type the parameter to testComplexObject as 'dynamic' and


I was assuming testComplexObject came out of some third party c# library  
which I cannot change. So making it dynamic is not possible.


implement IDMOP on JSObject, which you can see how to do from the Sympl  
sample.  Now, the Sympl sample is VERY light on real .NET bindin, but if  
it all maps to GetProp/SetProp, then maybe this is fine.  If you might  
flow into your code a regular C# object (not just a JSObj), then you may  
want to make use of the DefaultBinder from the DLR project, which is  
what the Iron languages use to get much richer binding.  You could also  
make use of the C# runtime binder to get C#'s semantics for binding  
members of objects at runtime, but you get that for free if you declare  
the parameter 'dynamic' and have your JSOjbectMetaObject simply punt  
whenever the object is not a derived type of JSObject.  You get that for  
free because you'll call back on the binder at the obj.message call  
site, and C# will have compiled that callsite to use its binder.


Ok, I need to read more of the document and apply what I learned to what  
you just said :)


Thanks for your help!

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


Re: [IronPython] IronLanguages

2011-03-29 Thread Matthias

Am 29.03.2011, 19:27 Uhr, schrieb Dino Viehland di...@microsoft.com:

Just to chime in on how to do the conversion: the answer is that you  
probably can't, at least not for something like TestClass.  You could  
look at what sort of type you're converting from in JS (number, string,  
function, etc...) and see if TestClass has any implicit conversions to  
it from primitive .NET types (double, string, delegate, etc...) and if  
so you could invoke one of those conversions.  But most likely you won't


This is what I am doing now already and it works quite nicely for simple  
types.


be able to convert directly to TestClass.  If TestClass was something  
more like IList then you could do a conversion there as well.  The only  
way you're likely able to convert to TestClass is if the user got a  
TestClass object from .NET, brought it into JS (where you wrapped it in  
some object of your own), and then you brought it back to .NET - but  
then when you bring it back to .NET you should bring it back as the real  
TestClass instead of your wrapped TestClass.


Yes, I have thought to force users to inherit from (use a prototype  
object) which comes from .net.


The only other way would be figuring out somehow to allow a JavaScript  
developer to subclass a .NET TestClass type.  We allow this in  
IronPython via our NewTypeMaker class but we are lucky in that  
everything is in the .NET world.  One way you could go about this is  
having a function like CreateClass which takes a subtype (TestClass) and  
a dictionary of string - JS functions which you then call into for the  
implementation of the various subclass methods.  You would then have a  
.NET type which is being extended by JavaScript - there's probably going  
to be some fun and tricky problems in doing this though.  Then the user  
can call the resulting class you give them, they'll get an instance  
which is wrapped in JavaScript, and when you pass it back to .NET you  
can unwrap it.


Yes, this was my main idea. It's very similar how SWIG directors handle  
cross-language polymorphism. At runtime I'd create a class which derives  
from TestClass and which overrides all virtual methods and properties. The  
C# overrides would call the JSObject to see if there's a javascript  
implementation for them. If there is, it will call the javascript  
implementation, otherwise it will call the base class's (TestClass in the  
example) implementation.


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


Re: [IronPython] IronLanguages

2011-03-29 Thread Dino Viehland
Matthias wrote:

 Yes, this was my main idea. It's very similar how SWIG directors handle 
 cross-language polymorphism. At runtime I'd create a class which derives  
 from TestClass and which overrides all virtual methods and properties. 
 The C# overrides would call the JSObject to see if there's a javascript 
 implementation for them. If there is, it will call the javascript 
 implementation, 
 otherwise it will call the base class's (TestClass in the example) 
 implementation.

Ok, then you totally want to look at NewTypeMaker in either IronRuby or 
IronPython
- they're slightly different but they both do the same thing and already handle 
all
sorts of corner cases w/ .NET types so it should be a good starting point.  
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Newbie InterOp-related question

2011-03-29 Thread Tilley, Paul
Hi,

 

I've just started using IronPython but have hit a bit of a roadblock.
This may also be caused by inadequate .Net knowledge.

 

In C# I can call a COM object (where the COM method is going to fill in
the parameter) like so:

object blah;

myComObj.Foo(out blah);

 

If for example the COM method returns an array of strings ( with the
parameter VARIANT* in COM method signature) then in C# I get an object[]
back which with appropriate massaging I can process.

 

How would I declare the variable in Python if I want access the returned
contents correctly? Knowing I was to get an array back I naively tried:

blah = []

myComObj.Foo(blah)

 

The call is made correctly - I can see the COM object is filling out the
return parameter OK but blah remains an empty list.

Any insights on what I should be doing more than welcome,

 

Thanks,

 

Paul

 

 

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