Re: [IronPython] [wingide-users] Using Wing IDE with IronPython - autocomplete for .NET objects (PI file generator)

2009-04-30 Thread Michael Foord

Hello all,

Another update to the PI file generator for .NET objects.

This one adds return type annotations for methods. It means that if you 
do something like:


   from System import Guid
   g = Guid.NewGuid()

Wing knowsthat g is a Guid and provides the correct auto-complete 
members for it. This is *great*. See previous instructions on how to use 
the script. It now takes quite a *long* time to generate all 90 PI 
files. :-)


There is a caveat with this currently:

Many methods return types that are defined in other namespaces 
(especially types defined in System). Because those types are in another 
PI file, Wing doesn't recognise them. I'll work out how to fix this 
(from System import * at the top of each PI file might catch most cases).


Secondly return types can currently return things like Array[int]()  the 
indexing will cause Wing to effectively ignore the return type - so I 
should change this to Array().


Still - getting there step-by-step and this is already enormously useful 
to me. I'm currently using a truly horrible regular expression to pull 
the return type out of the docstring...


I'll write this all up into a proper 'HOWTO: IronPython in Wing' once I 
have time.


All the best,

Michael

Michael Foord wrote:

Hello all,

Attached is an updated script for generating PI files to provide 
autocomplete on standard .NET objects.


It now handles all the standard .NET member types (including static 
properties, enumeration fields, indexers, events and so on).


It also recurses into sub-namespaces generating new pi-files for all 
of them.


This script is hardcoded to add references to, and then generate PI 
files for:


   System
   System.Data
   System.Drawing
   System.Windows.Forms

It generates 90 pi files (90 namespaces) taking up 24mb! The 
autocomplete it provides is awesome though. :-)


I had to do a fair bit of violence to the standard generate_pi.py 
script so I *doubt* it is desirable to merge it back in. Obviously 
very happy for this to be included with Wing if you want, or merged if 
you think it is worth it. Is it ok for me to offer this for download 
from my site? If I make further changes I will email this list.


The big thing to add is the return type for methods.

Is it possible to specify return types for properties? (Currently any 
attribute without an obvious parallel in Python I have turned into a 
property in the PI files).


The only real caveat with the current script (that I am aware of - bug 
reports and contributions welcomed) is that None is a common 
enumeration field member. This is invalid syntax in Python, so I 
rename these to None_.


There are quite a few minor changes sprinkled through the code - plus 
the __main__ part of the script is very different. I have tried to 
mark changes with a # CHANGE: comment, but it should be relatively 
amenable to diffing anyway...


For reference I was using IronPython 2.0.1, with .NET 3.5 installed 
and Wing 3.2beta 1.


All the best,

Michael Foord

Michael Foord wrote:

Hello all,

I've created a modified version of the 'generate_pi.py' which 
generates the interface files for .NET libraries. It is attached.


At the moment it generates PI files for the following assemblies / 
namespaces (hardwired at the bottom of the code):


   System
   System.Data
   System.Drawing
   System.Windows.Forms

To run it, create a new directory and add this to the 'Interface File 
Path' (File menu - Preferences - Source Analysis - Advanced - 
Insert).


Then from the command line switch to this directory (if you are on 
Vista you will need to run cmd with admin privileges due to a defect 
explained below). Execute the command:


   ipy generate_pi_for_net.py

This generates the pi files. It doesn't work *as well* on 64 bit 
windows because the .NET XML help files (or whatever they are called) 
are in a different location so the docstrings are not always 
available - which is why I am not just distributing the pi files yet.


The script doesn't yet understand static properties on classes - so 
it actually *fetches* static properties rather than looking at the 
descriptor (which is available in the class __dict__ so should be 
easy to fix). This is what causes inadvertent registry lookups etc 
and therefore requires admin privileges.


It doesn't yet understand multiple overloads. This may require a 
change to Wing or may not matter.


It isn't yet able to do anything with the information about return 
types - which would allow Wing to know the type of objects returned 
by methods. This may be easy to add?


It is late so I am going to bed. At some point I will explain the 
simple changes I  had to make to the standard generate_pi.py script 
(although they are mostly straightforward). I will also do further 
work on it as it will be very useful to me...


All the best,

Michael



_
Wing IDE users list

Re: [IronPython] [wingide-users] Using Wing IDE with IronPython - autocomplete for .NET objects (PI file generator)

2009-04-29 Thread Michael Foord

Hello all,

Attached is an updated script for generating PI files to provide 
autocomplete on standard .NET objects.


It now handles all the standard .NET member types (including static 
properties, enumeration fields, indexers, events and so on).


It also recurses into sub-namespaces generating new pi-files for all of 
them.


This script is hardcoded to add references to, and then generate PI 
files for:


   System
   System.Data
   System.Drawing
   System.Windows.Forms

It generates 90 pi files (90 namespaces) taking up 24mb! The 
autocomplete it provides is awesome though. :-)


I had to do a fair bit of violence to the standard generate_pi.py script 
so I *doubt* it is desirable to merge it back in. Obviously very happy 
for this to be included with Wing if you want, or merged if you think it 
is worth it. Is it ok for me to offer this for download from my site? If 
I make further changes I will email this list.


The big thing to add is the return type for methods.

Is it possible to specify return types for properties? (Currently any 
attribute without an obvious parallel in Python I have turned into a 
property in the PI files).


The only real caveat with the current script (that I am aware of - bug 
reports and contributions welcomed) is that None is a common enumeration 
field member. This is invalid syntax in Python, so I rename these to None_.


There are quite a few minor changes sprinkled through the code - plus 
the __main__ part of the script is very different. I have tried to mark 
changes with a # CHANGE: comment, but it should be relatively amenable 
to diffing anyway...


For reference I was using IronPython 2.0.1, with .NET 3.5 installed and 
Wing 3.2beta 1.


All the best,

Michael Foord

Michael Foord wrote:

Hello all,

I've created a modified version of the 'generate_pi.py' which 
generates the interface files for .NET libraries. It is attached.


At the moment it generates PI files for the following assemblies / 
namespaces (hardwired at the bottom of the code):


   System
   System.Data
   System.Drawing
   System.Windows.Forms

To run it, create a new directory and add this to the 'Interface File 
Path' (File menu - Preferences - Source Analysis - Advanced - 
Insert).


Then from the command line switch to this directory (if you are on 
Vista you will need to run cmd with admin privileges due to a defect 
explained below). Execute the command:


   ipy generate_pi_for_net.py

This generates the pi files. It doesn't work *as well* on 64 bit 
windows because the .NET XML help files (or whatever they are called) 
are in a different location so the docstrings are not always available 
- which is why I am not just distributing the pi files yet.


The script doesn't yet understand static properties on classes - so it 
actually *fetches* static properties rather than looking at the 
descriptor (which is available in the class __dict__ so should be easy 
to fix). This is what causes inadvertent registry lookups etc and 
therefore requires admin privileges.


It doesn't yet understand multiple overloads. This may require a 
change to Wing or may not matter.


It isn't yet able to do anything with the information about return 
types - which would allow Wing to know the type of objects returned by 
methods. This may be easy to add?


It is late so I am going to bed. At some point I will explain the 
simple changes I  had to make to the standard generate_pi.py script 
(although they are mostly straightforward). I will also do further 
work on it as it will be very useful to me...


All the best,

Michael



_
Wing IDE users list
http://wingware.com/lists/wingide



--
http://www.ironpythoninaction.com/

 generate_pi.py -- Generate Python interface by inspecting a module
  at runtime

Copyright (c) 2001-2008, Archaeopteryx Software, Inc.  All rights reserved.

Written by John P. Ehresman and Stephan R.A. Deibel

Simple utility to generate a python interface file from inspecting a module
at run time.  First argument is the name of the module.  Subsequent arguments
are name:expression pairs -- a class with given name will be created in the
interface file with methods  attributes matching the methods  attributes
of the object that results from the expression. The expression will be 
evaluated within the context of the module. The interface will be written
to stdout.

This contains some code specific to Python standard library code because it
parses the docstring standards used there to determine information about
return values. However, it works also with code that does not contain those
type hints in docstrings (but return value type cannot be determined).



# IMPORTANT:  This code has to run under all Python versions!

import sys
import os
import string
import stat
try:
  import inspect
except:
  inspect = None

try:
  ascii_letters = 

Re: [IronPython] [wingide-users] Using Wing IDE with IronPython - autocomplete for .NET objects (PI file generator)

2009-04-29 Thread Cenovsky, Lukas
Would be nice to have something similar for vim :-)

--
-- Lukas
 

 -Original Message-
 From: users-boun...@lists.ironpython.com 
 [mailto:users-boun...@lists.ironpython.com] On Behalf Of Michael Foord
 Sent: Wednesday, April 29, 2009 4:45 PM
 To: Wing Users
 Cc: Discussion of IronPython
 Subject: Re: [IronPython] [wingide-users] Using Wing IDE with 
 IronPython - autocomplete for .NET objects (PI file generator)
 
 Hello all,
 
 Attached is an updated script for generating PI files to provide 
 autocomplete on standard .NET objects.
 
 It now handles all the standard .NET member types (including static 
 properties, enumeration fields, indexers, events and so on).
 
 It also recurses into sub-namespaces generating new pi-files 
 for all of 
 them.
 
 This script is hardcoded to add references to, and then generate PI 
 files for:
 
 System
 System.Data
 System.Drawing
 System.Windows.Forms
 
 It generates 90 pi files (90 namespaces) taking up 24mb! The 
 autocomplete it provides is awesome though. :-)
 
 I had to do a fair bit of violence to the standard 
 generate_pi.py script 
 so I *doubt* it is desirable to merge it back in. Obviously 
 very happy 
 for this to be included with Wing if you want, or merged if 
 you think it 
 is worth it. Is it ok for me to offer this for download from 
 my site? If 
 I make further changes I will email this list.
 
 The big thing to add is the return type for methods.
 
 Is it possible to specify return types for properties? (Currently any 
 attribute without an obvious parallel in Python I have turned into a 
 property in the PI files).
 
 The only real caveat with the current script (that I am aware 
 of - bug 
 reports and contributions welcomed) is that None is a common 
 enumeration 
 field member. This is invalid syntax in Python, so I rename 
 these to None_.
 
 There are quite a few minor changes sprinkled through the code - plus 
 the __main__ part of the script is very different. I have 
 tried to mark 
 changes with a # CHANGE: comment, but it should be relatively 
 amenable 
 to diffing anyway...
 
 For reference I was using IronPython 2.0.1, with .NET 3.5 
 installed and 
 Wing 3.2beta 1.
 
 All the best,
 
 Michael Foord
 
 Michael Foord wrote:
  Hello all,
 
  I've created a modified version of the 'generate_pi.py' which 
  generates the interface files for .NET libraries. It is attached.
 
  At the moment it generates PI files for the following assemblies / 
  namespaces (hardwired at the bottom of the code):
 
 System
 System.Data
 System.Drawing
 System.Windows.Forms
 
  To run it, create a new directory and add this to the 
 'Interface File 
  Path' (File menu - Preferences - Source Analysis - Advanced - 
  Insert).
 
  Then from the command line switch to this directory (if you are on 
  Vista you will need to run cmd with admin privileges due to 
 a defect 
  explained below). Execute the command:
 
 ipy generate_pi_for_net.py
 
  This generates the pi files. It doesn't work *as well* on 64 bit 
  windows because the .NET XML help files (or whatever they 
 are called) 
  are in a different location so the docstrings are not 
 always available 
  - which is why I am not just distributing the pi files yet.
 
  The script doesn't yet understand static properties on 
 classes - so it 
  actually *fetches* static properties rather than looking at the 
  descriptor (which is available in the class __dict__ so 
 should be easy 
  to fix). This is what causes inadvertent registry lookups etc and 
  therefore requires admin privileges.
 
  It doesn't yet understand multiple overloads. This may require a 
  change to Wing or may not matter.
 
  It isn't yet able to do anything with the information about return 
  types - which would allow Wing to know the type of objects 
 returned by 
  methods. This may be easy to add?
 
  It is late so I am going to bed. At some point I will explain the 
  simple changes I  had to make to the standard generate_pi.py script 
  (although they are mostly straightforward). I will also do further 
  work on it as it will be very useful to me...
 
  All the best,
 
  Michael
 
  
 --
 --
 
  _
  Wing IDE users list
  http://wingware.com/lists/wingide
 
 
 -- 
 http://www.ironpythoninaction.com/
 
 

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


Re: [IronPython] [wingide-users] Using Wing IDE with IronPython - autocomplete for .NET objects (PI file generator)

2009-04-29 Thread Michael Foord

Cenovsky, Lukas wrote:

Would be nice to have something similar for vim :-)

  


Go for it. :-)

Michael


--
-- Lukas
 

  

-Original Message-
From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Michael Foord

Sent: Wednesday, April 29, 2009 4:45 PM
To: Wing Users
Cc: Discussion of IronPython
Subject: Re: [IronPython] [wingide-users] Using Wing IDE with 
IronPython - autocomplete for .NET objects (PI file generator)


Hello all,

Attached is an updated script for generating PI files to provide 
autocomplete on standard .NET objects.


It now handles all the standard .NET member types (including static 
properties, enumeration fields, indexers, events and so on).


It also recurses into sub-namespaces generating new pi-files 
for all of 
them.


This script is hardcoded to add references to, and then generate PI 
files for:


System
System.Data
System.Drawing
System.Windows.Forms

It generates 90 pi files (90 namespaces) taking up 24mb! The 
autocomplete it provides is awesome though. :-)


I had to do a fair bit of violence to the standard 
generate_pi.py script 
so I *doubt* it is desirable to merge it back in. Obviously 
very happy 
for this to be included with Wing if you want, or merged if 
you think it 
is worth it. Is it ok for me to offer this for download from 
my site? If 
I make further changes I will email this list.


The big thing to add is the return type for methods.

Is it possible to specify return types for properties? (Currently any 
attribute without an obvious parallel in Python I have turned into a 
property in the PI files).


The only real caveat with the current script (that I am aware 
of - bug 
reports and contributions welcomed) is that None is a common 
enumeration 
field member. This is invalid syntax in Python, so I rename 
these to None_.


There are quite a few minor changes sprinkled through the code - plus 
the __main__ part of the script is very different. I have 
tried to mark 
changes with a # CHANGE: comment, but it should be relatively 
amenable 
to diffing anyway...


For reference I was using IronPython 2.0.1, with .NET 3.5 
installed and 
Wing 3.2beta 1.


All the best,

Michael Foord

Michael Foord wrote:


Hello all,

I've created a modified version of the 'generate_pi.py' which 
generates the interface files for .NET libraries. It is attached.


At the moment it generates PI files for the following assemblies / 
namespaces (hardwired at the bottom of the code):


   System
   System.Data
   System.Drawing
   System.Windows.Forms

To run it, create a new directory and add this to the 
  
'Interface File 

Path' (File menu - Preferences - Source Analysis - Advanced - 
Insert).


Then from the command line switch to this directory (if you are on 
Vista you will need to run cmd with admin privileges due to 
  
a defect 


explained below). Execute the command:

   ipy generate_pi_for_net.py

This generates the pi files. It doesn't work *as well* on 64 bit 
windows because the .NET XML help files (or whatever they 
  
are called) 

are in a different location so the docstrings are not 
  
always available 


- which is why I am not just distributing the pi files yet.

The script doesn't yet understand static properties on 
  
classes - so it 

actually *fetches* static properties rather than looking at the 
descriptor (which is available in the class __dict__ so 
  
should be easy 

to fix). This is what causes inadvertent registry lookups etc and 
therefore requires admin privileges.


It doesn't yet understand multiple overloads. This may require a 
change to Wing or may not matter.


It isn't yet able to do anything with the information about return 
types - which would allow Wing to know the type of objects 
  
returned by 


methods. This may be easy to add?

It is late so I am going to bed. At some point I will explain the 
simple changes I  had to make to the standard generate_pi.py script 
(although they are mostly straightforward). I will also do further 
work on it as it will be very useful to me...


All the best,

Michael


  

--
--


_
Wing IDE users list
http://wingware.com/lists/wingide
  

--
http://www.ironpythoninaction.com/





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



--
http://www.ironpythoninaction.com/

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