Spyder REPL / Autocompletion does not "See" into .NET / CLR .dll's

455 views
Skip to first unread message

lcorrigan

unread,
Feb 22, 2012, 3:02:00 PM2/22/12
to spyder
I'm using Python(x,y) 2.7.2.1 on Windows 7 and XP.
I have a package I've created called loadrack, which has a series of
RF lab equipment .dll's written in C# .NET 2.0. I use the Python .NET
package with these, to use them within python (not IronPython). My
top level package adds the paths to all the sub-package folders
(including loadrack, where the .dlls and clr/python .NET stuff is
located.

So far, I'm able to import the top level package and 'see' all the
members in all levels of the classes from the top down from within
Pythonwin and IPython consoles, but not from within Spyder. I've
upgraded my pythonxy to the latest Spyder but to no avail.

The key to my structure and linkage to .NET classes, is the clr import
call that the loadrack package makes, and uses to add references in
the clr to all the .dll's.

Ex: In IPython Console:
In [5]: import testlib
In [6]: testlib.loadrack.pm_agU2000A.Calibrate() #; It 'see's all the
way down to the object's available methods.

From Spyder editor, the furthest I can get is:
import testlib
testlib.loadrack.pm_agU2000A. #; It doesn't show any levels deeper /
no calls into the actual lib.

An interesting point, is that normally from IPython, I'm able to see
higher level testlib.clr module,
but Spyder editor doesn't show the clr item.

Pythonwin for editing seems to get me what I need, but there are so
many other cool features of Spyder that I couldn't resist looking into
this deeper.
Any ideas why Spyder doesn't see the clr or anything that the clr item
makes calls into? I've not found how Pythonwin magically does it
all....

Carlos Córdoba

unread,
Feb 22, 2012, 4:13:28 PM2/22/12
to spyd...@googlegroups.com
Please follow the advice I gave to Manfred in this thread

https://groups.google.com/forum/?fromgroups#!topic/spyderlib/hID2tHGW57w

This is something we plan to fix for 2.2

HTH,
Carlos

El 22/02/12 15:02, lcorrigan escribió:

lcorrigan

unread,
Feb 23, 2012, 9:12:03 AM2/23/12
to spyd...@googlegroups.com
That worked great, thanks a bunch Carlos!

Denis Akhiyarov

unread,
Mar 5, 2017, 2:53:32 PM3/5/17
to spyder
@lcorrigan were you able to get code completion for Python.NET with live objects in Spyder? If yes, can you share the changes that you made?

For Spyder 3.0 I do not see this setting for extension_modules or ROPE_PREFS in spyderlib/widgets/sourcecode/codeeditor.py

Thanks,
Denis

Carlos Córdoba

unread,
Mar 5, 2017, 2:57:25 PM3/5/17
to spyd...@googlegroups.com
Hi Denis,

We never managed to implement this change. Would you like to create a pull request for it?


Cheers,
Carlos

El 05/03/17 a las 14:53, Denis Akhiyarov escribió:
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To post to this group, send email to spyd...@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

Denis Akhiyarov

unread,
Mar 5, 2017, 3:17:32 PM3/5/17
to spyder
I just tried adding this in rope_plugin.py, but code completion on live .NET/CLR objects is still not working in IDE. In console it works of course.

#TODO: The following preferences should be customizable in the future
ROPE_PREFS = {'ignore_syntax_errors': True,
              'ignore_bad_imports': True,
              'soa_followed_calls': 2,
              'extension_modules': ["clr"],
              }


Dave Hirschfeld

unread,
Mar 7, 2017, 10:55:24 PM3/7/17
to spyder

On Monday, 6 March 2017 06:17:32 UTC+10, Denis Akhiyarov wrote:
I just tried adding this in rope_plugin.py, but code completion on live .NET/CLR objects is still not working in IDE. In console it works of course.

#TODO: The following preferences should be customizable in the future
ROPE_PREFS = {'ignore_syntax_errors': True,
              'ignore_bad_imports': True,
              'soa_followed_calls': 2,
              'extension_modules': ["clr"],
              }




On Sunday, March 5, 2017 at 1:57:25 PM UTC-6, Carlos Córdoba wrote:
Hi Denis,

We never managed to implement this change. Would you like to create a pull request for it?


Cheers,
Carlos

El 05/03/17 a las 14:53, Denis Akhiyarov escribió:
@lcorrigan were you able to get code completion for Python.NET with live objects in Spyder? If yes, can you share the changes that you made?

For Spyder 3.0 I do not see this setting for extension_modules or ROPE_PREFS in spyderlib/widgets/sourcecode/codeeditor.py

Thanks,
Denis

On Thursday, February 23, 2012 at 8:12:03 AM UTC-6, lcorrigan wrote:
That worked great, thanks a bunch Carlos!
--

For a hacky workaround you can force introspection by iterating over the types in the assembly:


In [1]: import clr


In [2]: import System


In [3]: clr.AddReference('System.Data')

Out[3]: <System.Reflection.RuntimeAssembly at 0xd2de4e0>

In [4]: dir(System.Data)

Out[4]:

['__class__',

'__delattr__',

'__delete__',

'__dir__',

'__doc__',

'__eq__',

'__file__',

'__format__',

'__ge__',

'__getattribute__',

'__gt__',

'__hash__',

'__init__',

'__le__',

'__lt__',

'__module__',

'__name__',

'__ne__',

'__new__',

'__reduce__',

'__reduce_ex__',

'__repr__',

'__set__',

'__setattr__',

'__sizeof__',

'__str__',

'__subclasshook__']


In [5]: def getattrdot(obj, name, *default):

   ...:     first, *rest = name.split('.', 1)

   ...:     obj = getattr(obj, first, *default)

   ...:     if not rest:

   ...:         return obj

   ...:     return getattrdot(obj, *rest, *default)

   ...:


In [6]: def AddReference(name):

   ...:     import clr

   ...:     assembly = clr.AddReference(name)

   ...:     pymodule = getattrdot(clr, name)

   ...:     print("Loaded '{}'".format(name))

   ...:     print("Introspecting types...")

   ...:     for t in assembly.GetTypes():

   ...:         getattr(pymodule, t.Name, None)

   ...:


In [7]: AddReference('System.Data')

Loaded 'System.Data'

Introspecting types...


In [8]: dir(System.Data)

Out[8]:

['AcceptRejectRule',

'CommandBehavior',

'CommandType',

'ConflictOption',

'ConnectionState',

'Constraint',

'ConstraintCollection',

'ConstraintException',

'DBConcurrencyException',

'DataColumn',

'DataColumnChangeEventArgs',

'DataColumnChangeEventHandler',

'DataColumnCollection',

'DataException',

'DataRelation',

'DataRelationCollection',

'DataRow',

'DataRowAction',

'DataRowBuilder',

'DataRowChangeEventArgs',

'DataRowChangeEventHandler',

'DataRowCollection',

'DataRowState',

'DataRowVersion',

'DataRowView',

'DataSet',

'DataSetDateTime',

'DataSetSchemaImporterExtension',

'DataSysDescriptionAttribute',

'DataTable',

'DataTableClearEventArgs',

'DataTableClearEventHandler',

'DataTableCollection',

'DataTableNewRowEventArgs',

'DataTableNewRowEventHandler',

'DataTableReader',

'DataView',

'DataViewManager',

'DataViewRowState',

'DataViewSetting',

'DataViewSettingCollection',

'DbType',

'DeletedRowInaccessibleException',

'DuplicateNameException',

'EvaluateException',

'FillErrorEventArgs',

'FillErrorEventHandler',

'ForeignKeyConstraint',

'IColumnMapping',

'IColumnMappingCollection',

'IDataAdapter',

'IDataParameter',

'IDataParameterCollection',

'IDataReader',

'IDataRecord',

'IDbCommand',

'IDbConnection',

'IDbDataAdapter',

'IDbDataParameter',

'IDbTransaction',

'ITableMapping',

'ITableMappingCollection',

'InRowChangingEventException',

'InternalDataCollectionBase',

'InvalidConstraintException',

'InvalidExpressionException',

'IsolationLevel',

'KeyRestrictionBehavior',

'LoadOption',

'MappingType',

'MergeFailedEventArgs',

'MergeFailedEventHandler',

'MissingMappingAction',

'MissingPrimaryKeyException',

'MissingSchemaAction',

'NoNullAllowedException',

'OperationAbortedException',

'ParameterDirection',

'PropertyAttributes',

'PropertyCollection',

'ReadOnlyException',

'RowNotInTableException',

'Rule',

'SchemaSerializationMode',

'SchemaType',

'SerializationFormat',

'SqlDbType',

'StateChangeEventArgs',

'StateChangeEventHandler',

'StatementCompletedEventArgs',

'StatementCompletedEventHandler',

'StatementType',

'StrongTypingException',

'SyntaxErrorException',

'TypedDataSetGenerator',

'TypedDataSetGeneratorException',

'UniqueConstraint',

'UpdateRowSource',

'UpdateStatus',

'VersionNotFoundException',

'XmlReadMode',

'XmlWriteMode',

'__class__',

'__delattr__',

'__delete__',

'__dir__',

'__doc__',

'__eq__',

'__file__',

'__format__',

'__ge__',

'__getattribute__',

'__gt__',

'__hash__',

'__init__',

'__le__',

'__lt__',

'__module__',

'__name__',

'__ne__',

'__new__',

'__reduce__',

'__reduce_ex__',

'__repr__',

'__set__',

'__setattr__',

'__sizeof__',

'__str__',

'__subclasshook__']


In [9]:


 

Kimtruc Nguyen

unread,
Mar 8, 2017, 10:37:59 AM3/8/17
to spyder
Dear Carlos,

I have problem with "print" or show information of a dictionary 
my code:
gmm = bob.learn.em.GMMMachine(5,2)
 
and when I want to print gmm,, the fields of gmm are not represented in the variable explorer, and on the IPython console as follows:
<bob.learn.em.GMMMachine at 0x7ff1bb22fd50>

Is that the same problem with this topic. 
Because I also can not use of  Qt4 and Qt5 
Please help me to solve this problem.

I am quite new in python and spyder, so I am so sorry for my stupid question.
Thank you and best regards.
Truc


Denis Akhiyarov

unread,
Mar 8, 2017, 10:37:59 AM3/8/17
to spyd...@googlegroups.com
Actually I'm getting pretty good code completion with pythonnet in ptipython console or PTVS.
But for more complicated cases the dir() and .NET Reflection are very useful.

The question related more to the IDE experience when the code is not executed, but introspected by the IDE analyzer.

Here is a more detailed github issue if anyone wants to use the current workarounds:


--
You received this message because you are subscribed to a topic in the Google Groups "spyder" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spyderlib/pkymMOxVfLw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spyderlib+unsubscribe@googlegroups.com.

Carlos Córdoba

unread,
Mar 8, 2017, 11:16:05 AM3/8/17
to spyd...@googlegroups.com

What type of object is gmm? I mean, the thing is the Variable Explorer can only show certain types of objects (like Dataframes and Numpy arrays), so if gmm is not one of them, then it won't be shown properly.


El 07/03/17 a las 13:42, Kimtruc Nguyen escribió:
--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages