[IronPython] Accessing search path through ScriptEngine

2008-03-29 Thread Curt Hagenlocher
The script engine allows you to set the search path by calling
ScriptEngine.SetScriptSourceSearchPaths, but it neither lets you query the
existing path nor amend it -- just set it outright.  Is this intentional?

--
Curt Hagenlocher
[EMAIL PROTECTED]
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] IP 2 Hosting

2008-03-29 Thread Michael Foord
Hello guys,

I'm trying to do some simple examples of hosting with IronPython 2. Boy 
you made things more complicated than IronPython 1. :-)

Unfortunately the DLR hosting spec document is out of date. I have a 
couple of questions (but will keep exploring).

The simplest use case is just to evaluate an expression and return a result.

The hosting spec document mention 'ScriptRuntime.Execute(text)'. This 
may or may not be the right way to evaluate an expression, but in any 
case it has been removed.

An alternative is:

engine = PythonEngine.CurrentEngine # a ScriptEngine
unit = engine.CreateSourceUnitFromString(code, id)
result = unit.Execute()

Which is straightforward enough, however I can't see a way to set 
TrueDivision using this technique.  (What is the 'id' by the way?)

I can see that TrueDivision is a setting on 
IronPython.Runtime.ModuleOptions and IronPython.Runtime.PythonModule. 
Can I set this on the engine somehow?

All the alternative seem to lead down a rabbit warren of 'create this 
object - which requires this object - which you construct from another 
object - which...'. I don't know which path to follow down the rabbit 
hole...

:-)

Any suggestions to save me from madness?

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


Re: [IronPython] IP 2 Hosting

2008-03-29 Thread Curt Hagenlocher
Some of those look like names from A9, which have changed in B1.

The easiest way to evaluate an expression from scratch seems to be as
follows:

ScriptEngine engine = ScriptRuntime.Create().GetEngine(py);
ScriptScope scope = engine.CreateScope();
ScriptSource source = engine.CreateScriptSourceFromString(1 + 1,
SourceCodeKind.Expression);
int result = source.Executeint(scope);

On Sat, Mar 29, 2008 at 10:00 AM, Michael Foord [EMAIL PROTECTED]
wrote:

 Hello guys,

 I'm trying to do some simple examples of hosting with IronPython 2. Boy
 you made things more complicated than IronPython 1. :-)

 Unfortunately the DLR hosting spec document is out of date. I have a
 couple of questions (but will keep exploring).

 The simplest use case is just to evaluate an expression and return a
 result.

 The hosting spec document mention 'ScriptRuntime.Execute(text)'. This
 may or may not be the right way to evaluate an expression, but in any
 case it has been removed.

 An alternative is:

engine = PythonEngine.CurrentEngine # a ScriptEngine
unit = engine.CreateSourceUnitFromString(code, id)
result = unit.Execute()

 Which is straightforward enough, however I can't see a way to set
 TrueDivision using this technique.  (What is the 'id' by the way?)

 I can see that TrueDivision is a setting on
 IronPython.Runtime.ModuleOptions and IronPython.Runtime.PythonModule.
 Can I set this on the engine somehow?

 All the alternative seem to lead down a rabbit warren of 'create this
 object - which requires this object - which you construct from another
 object - which...'. I don't know which path to follow down the rabbit
 hole...

 :-)

 Any suggestions to save me from madness?

 Michael
 ___
 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


Re: [IronPython] IP 2 Hosting

2008-03-29 Thread Michael Foord
Curt Hagenlocher wrote:
 Some of those look like names from A9, which have changed in B1.
I'm using B1. I expect they'll change in the next release though. *sigh* ;-)

In the old days a beta used to mean the API was fixed and it was only 
bugfixes that would go in... 0.5 wink

Michael


  
 The easiest way to evaluate an expression from scratch seems to be as 
 follows:
  
 ScriptEngine engine = ScriptRuntime.Create().GetEngine(py);
 ScriptScope scope = engine.CreateScope();
 ScriptSource source = engine.CreateScriptSourceFromString(1 + 1, 
 SourceCodeKind.Expression);
 int result = source.Executeint(scope);

 On Sat, Mar 29, 2008 at 10:00 AM, Michael Foord 
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:

 Hello guys,

 I'm trying to do some simple examples of hosting with IronPython
 2. Boy
 you made things more complicated than IronPython 1. :-)

 Unfortunately the DLR hosting spec document is out of date. I have a
 couple of questions (but will keep exploring).

 The simplest use case is just to evaluate an expression and return
 a result.

 The hosting spec document mention 'ScriptRuntime.Execute(text)'. This
 may or may not be the right way to evaluate an expression, but in any
 case it has been removed.

 An alternative is:

engine = PythonEngine.CurrentEngine # a ScriptEngine
unit = engine.CreateSourceUnitFromString(code, id)
result = unit.Execute()

 Which is straightforward enough, however I can't see a way to set
 TrueDivision using this technique.  (What is the 'id' by the way?)

 I can see that TrueDivision is a setting on
 IronPython.Runtime.ModuleOptions and IronPython.Runtime.PythonModule.
 Can I set this on the engine somehow?

 All the alternative seem to lead down a rabbit warren of 'create this
 object - which requires this object - which you construct from another
 object - which...'. I don't know which path to follow down the rabbit
 hole...

 :-)

 Any suggestions to save me from madness?

 Michael
 ___
 Users mailing list
 Users@lists.ironpython.com mailto: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
   

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


Re: [IronPython] IP 2 Hosting

2008-03-29 Thread Michael Foord
Curt Hagenlocher wrote:
 Some of those look like names from A9, which have changed in B1.
  
 The easiest way to evaluate an expression from scratch seems to be as 
 follows:
  
 ScriptEngine engine = ScriptRuntime.Create().GetEngine(py);
 ScriptScope scope = engine.CreateScope();
 ScriptSource source = engine.CreateScriptSourceFromString(1 + 1, 
 SourceCodeKind.Expression);
 int result = source.Executeint(scope);

Oops - didn't read all of your message. I'm using B1 and my code seems 
*pretty* similar except for the useful addition of SourceCodeKind - thanks.

Michael


 On Sat, Mar 29, 2008 at 10:00 AM, Michael Foord 
 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:

 Hello guys,

 I'm trying to do some simple examples of hosting with IronPython
 2. Boy
 you made things more complicated than IronPython 1. :-)

 Unfortunately the DLR hosting spec document is out of date. I have a
 couple of questions (but will keep exploring).

 The simplest use case is just to evaluate an expression and return
 a result.

 The hosting spec document mention 'ScriptRuntime.Execute(text)'. This
 may or may not be the right way to evaluate an expression, but in any
 case it has been removed.

 An alternative is:

engine = PythonEngine.CurrentEngine # a ScriptEngine
unit = engine.CreateSourceUnitFromString(code, id)
result = unit.Execute()

 Which is straightforward enough, however I can't see a way to set
 TrueDivision using this technique.  (What is the 'id' by the way?)

 I can see that TrueDivision is a setting on
 IronPython.Runtime.ModuleOptions and IronPython.Runtime.PythonModule.
 Can I set this on the engine somehow?

 All the alternative seem to lead down a rabbit warren of 'create this
 object - which requires this object - which you construct from another
 object - which...'. I don't know which path to follow down the rabbit
 hole...

 :-)

 Any suggestions to save me from madness?

 Michael
 ___
 Users mailing list
 Users@lists.ironpython.com mailto: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
   

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


Re: [IronPython] IP 2 Hosting

2008-03-29 Thread Michael Foord
Curt Hagenlocher wrote:
 On Sat, Mar 29, 2008 at 10:32 AM, Michael Foord
 [EMAIL PROTECTED] wrote:
   
 In the old days a beta used to mean the API was fixed and it was only
 bugfixes that would go in... 0.5 wink
 

 heh

 It seems to me that B1 is more consistent with the various published
 DLR hosting specs than A9 was -- which suggests that the API churn for
 the Microsoft.Scripting namespace is dying down.
   

Cool - I was just being rude.

Any ideas on switching on TrueDivision for the scope?

Michael



 --
 Curt Hagenlocher
 [EMAIL PROTECTED]
 ___
 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


Re: [IronPython] IP 2 Hosting

2008-03-29 Thread Curt Hagenlocher
On Sat, Mar 29, 2008 at 10:51 AM, Michael Foord
[EMAIL PROTECTED] wrote:

 Cool - I was just being rude.

Hey, I feel your pain!  I'd swear that I've rewritten more hosting
code than I've written...

 Any ideas on switching on TrueDivision for the scope?

This is what I was able to puzzle out.  I have no idea how correct it is.
ScriptSource source = engine.CreateScriptSourceFromString(import
foo, SourceCodeKind.Statements);
ScriptScope scriptScope = runtime.ExecuteSourceUnit(source);
Scope scope = scriptScope.GetVariableScope(foo);
PythonModule extension =
(PythonModule)scope.GetExtension(scope.Language.ContextId);
extension.TrueDivision = true;

It looks like you can set this globally by doing something like this:
((IronPython.PythonEngineOptions)engine.Options).DivisionOptions =
IronPython.PythonDivisionOptions.New;

--
Curt Hagenlocher
[EMAIL PROTECTED]
___
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] IP 2 Hosting

2008-03-29 Thread Michael Foord


((IronPython.PythonEngineOptions)engine.Options).DivisionOptions = 
IronPython.PythonDivisionOptions.New;

This worked!

Thanks - it is for a simple embedding example which is a calculator. The 
winforms UI builds up expressions and the '=' button evaluates them with 
the Python engine. :-)

Michael


Curt Hagenlocher wrote:
 On Sat, Mar 29, 2008 at 10:51 AM, Michael Foord
 [EMAIL PROTECTED] wrote:
   
 Cool - I was just being rude.
 

 Hey, I feel your pain!  I'd swear that I've rewritten more hosting
 code than I've written...

   
 Any ideas on switching on TrueDivision for the scope?
 

 This is what I was able to puzzle out.  I have no idea how correct it is.
 ScriptSource source = engine.CreateScriptSourceFromString(import
 foo, SourceCodeKind.Statements);
 ScriptScope scriptScope = runtime.ExecuteSourceUnit(source);
 Scope scope = scriptScope.GetVariableScope(foo);
 PythonModule extension =
 (PythonModule)scope.GetExtension(scope.Language.ContextId);
 extension.TrueDivision = true;

 It looks like you can set this globally by doing something like this:
 ((IronPython.PythonEngineOptions)engine.Options).DivisionOptions =
 IronPython.PythonDivisionOptions.New;

 --
 Curt Hagenlocher
 [EMAIL PROTECTED]
 ___
 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


Re: [IronPython] Snippets in Trackback

2008-03-29 Thread Curt Hagenlocher
The snippets represent executable code that's generated dynamically by the
DLR from your Python source.  Do you have a small piece of sample code that
reproduces the failure?

On Sat, Mar 29, 2008 at 1:28 PM, Davy Mitchell [EMAIL PROTECTED]
wrote:

 Hi All,

 IPY2.0 B1 Vista SP1

 I keep seeing reference to 'Snippets' in IP Tracebacks on different
 bits of code. Can't find anything on codeplex so assume it *probably*
 something wrong this end.
 I don't have a 'Snippets' module AFAIK.

 Typical example
 C:\Code\OSProjectsipy wpf5.py
 Traceback (most recent call last):
  File Snippets, line unknown, in Initialize
  File PresentationFramework, line unknown, in Load

 Is it just me or :-)

 --
 Davy Mitchell
 Blog - http://www.latedecember.co.uk/sites/personal/davy/
 Twitter - http://twitter.com/daftspaniel
 Skype - daftspaniel needgod.com
 ___
 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