Code completion from DLLs

Alex
2010-05-17
2013-03-15
  • Alex

    Alex - 2010-05-17

    I'm trying to get code completion from a DLL in pydev.  The DLL is definitely in my path (so there is no 'Unresolved import' warning), and if I open a console (CTRL+ALT+ENTER) and import it there, I get code completion when I press '.'.  In the main IDE however there is no code completion, and what is more calls to methods on the module are underlined in red.  I did try adding the module name to the forced builtins, but it seemed to have no effect and I wasn't 100% sure what I was doing, so I took it back out.

    Apologies if I ask about something which has already been solved somewhere, I have looked around these forums and Googled, and the only advice I can find is 'make sure the dlls are in your PYTHONPATH' and 'upgrade PyDev', both of which I've done.

    Thanks in advance for your help.

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2010-05-17

    Just to be sure, the directory that contains the dll is in the pythonpath (and not the dll itself), right?

    Now, to help determine the cause, can you go through the following steps:

    1. Use ctrl+2+kill (this is the clear your caches)
    2 Go to window > preferences > pydev > logging and check 'enable logging for code completion?'

    3. Create an empty file and write the code to get completions in the dll

    E.g.:
    import mydll
    mydll.| <- request completion here

    And paste the results…

    Cheers,

    Fabio

    p.s.: This has to be with the latest version (which had some code added to help diagnose this kind of stuff)

     
  • Alex

    Alex - 2010-05-18

    Three messages created in error log.

    Pydev version:  1.5.7.2010050621

    Exception Stack Trace:
    java.lang.RuntimeException: The shell is still not connected, so, it is an invalid state to try to write to it.
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.write(AbstractShell.java:749)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getTheCompletions(AbstractShell.java:902)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.internalChangePythonPath(AbstractShell.java:894)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getImportCompletions(AbstractShell.java:850)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.setTokens(CompiledModule.java:127)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.<init>(CompiledModule.java:83)
    at org.python.pydev.editor.codecompletion.revisited.SystemModulesManager.getBuiltinModule(SystemModulesManager.java:303)
    at org.python.pydev.editor.codecompletion.revisited.SystemModulesManager.getBuiltinModule(SystemModulesManager.java:1)
    at org.python.pydev.editor.codecompletion.revisited.ProjectModulesManager.getModuleAndRelatedModulesManager(ProjectModulesManager.java:271)
    at org.python.pydev.editor.codecompletion.revisited.ProjectModulesManager.getModule(ProjectModulesManager.java:251)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getModule(AbstractASTManager.java:397)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getBuiltinMod(AbstractASTManager.java:938)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getBuiltinComps(AbstractASTManager.java:922)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getBuiltinCompletions(AbstractASTManager.java:904)
    at com.python.pydev.analysis.scopeanalysis.AbstractScopeAnalyzerVisitor.<init>(AbstractScopeAnalyzerVisitor.java:142)
    at com.python.pydev.analysis.visitors.OccurrencesVisitor.<init>(OccurrencesVisitor.java:66)
    at com.python.pydev.analysis.OccurrencesAnalyzer.analyzeDocument(OccurrencesAnalyzer.java:44)
    at com.python.pydev.analysis.OccurrencesAnalyzer.analyzeDocument(OccurrencesAnalyzer.java:38)
    at com.python.pydev.analysis.builder.AnalysisBuilderRunnable.doAnalysis(AnalysisBuilderRunnable.java:235)
    at com.python.pydev.analysis.builder.AbstractAnalysisBuilderRunnable.run(AbstractAnalysisBuilderRunnable.java:145)
    at org.python.pydev.core.concurrency.RunnableAsJobsPoolThread$1.run(RunnableAsJobsPoolThread.java:97)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

    Session Data:
    eclipse.buildId=M20090917-0800
    java.version=1.5.0_04
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_GB
    Framework arguments:  -product org.eclipse.epp.package.java.product
    Command-line arguments:  -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.java.product

    Exception Stack Trace:
    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.read(AbstractShell.java:663)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.read(AbstractShell.java:732)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getCompletions(AbstractShell.java:962)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getTheCompletions(AbstractShell.java:904)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getImportCompletions(AbstractShell.java:854)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.setTokens(CompiledModule.java:127)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.<init>(CompiledModule.java:83)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.<init>(CompiledModule.java:71)
    at org.python.pydev.editor.codecompletion.revisited.modules.AbstractModule.createModule(AbstractModule.java:242)
    at org.python.pydev.editor.codecompletion.revisited.ModulesManager.getModule(ModulesManager.java:580)
    at org.python.pydev.editor.codecompletion.revisited.ProjectModulesManager.getRelativeModule(ProjectModulesManager.java:244)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getModule(AbstractASTManager.java:410)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findModuleFromPath(AbstractASTManager.java:1396)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findOnImportedMods(AbstractASTManager.java:1244)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findOnImportedMods(AbstractASTManager.java:1177)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findTokensOnImportedMods(AbstractASTManager.java:1066)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.internalGenerateGetCompletionsForModule(AbstractASTManager.java:637)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getCompletionsForModule(AbstractASTManager.java:499)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getCompletionsForModule(AbstractASTManager.java:470)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getCompletionsForToken(AbstractASTManager.java:360)
    at org.python.pydev.editor.codecompletion.PyCodeCompletion.doTokenCompletion(PyCodeCompletion.java:294)
    at org.python.pydev.editor.codecompletion.PyCodeCompletion.getCodeCompletionProposals(PyCodeCompletion.java:124)
    at org.python.pydev.editor.codecompletion.PythonCompletionProcessor.getPythonProposals(PythonCompletionProcessor.java:228)
    at org.python.pydev.editor.codecompletion.PythonCompletionProcessor.computeCompletionProposals(PythonCompletionProcessor.java:152)
    at org.python.pydev.editor.simpleassist.SimpleAssistProcessor.computeCompletionProposals(SimpleAssistProcessor.java:198)
    at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals(ContentAssistant.java:1832)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals(CompletionProposalPopup.java:556)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$16(CompletionProposalPopup.java:553)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup$2.run(CompletionProposalPopup.java:488)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals(CompletionProposalPopup.java:482)
    at org.eclipse.jface.text.contentassist.ContentAssistant$2.run(ContentAssistant.java:376)
    at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
    at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3855)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3476)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1311)

    Session Data:
    eclipse.buildId=M20090917-0800
    java.version=1.5.0_04
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_GB
    Framework arguments:  -product org.eclipse.epp.package.java.product
    Command-line arguments:  -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.java.product

    Exception Stack Trace:
    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.read(AbstractShell.java:663)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.read(AbstractShell.java:732)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getCompletions(AbstractShell.java:962)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getTheCompletions(AbstractShell.java:904)
    at org.python.pydev.editor.codecompletion.shell.AbstractShell.getImportCompletions(AbstractShell.java:854)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.setTokens(CompiledModule.java:127)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.<init>(CompiledModule.java:83)
    at org.python.pydev.editor.codecompletion.revisited.modules.CompiledModule.<init>(CompiledModule.java:71)
    at org.python.pydev.editor.codecompletion.revisited.modules.AbstractModule.createModule(AbstractModule.java:242)
    at org.python.pydev.editor.codecompletion.revisited.ModulesManager.getModule(ModulesManager.java:580)
    at org.python.pydev.editor.codecompletion.revisited.ProjectModulesManager.getRelativeModule(ProjectModulesManager.java:244)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.getModule(AbstractASTManager.java:410)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findModuleFromPath(AbstractASTManager.java:1396)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findOnImportedMods(AbstractASTManager.java:1244)
    at org.python.pydev.editor.codecompletion.revisited.AbstractASTManager.findOnImportedMods(AbstractASTManager.java:1177)
    at com.python.pydev.analysis.visitors.ImportChecker.visitImportToken(ImportChecker.java:152)
    at com.python.pydev.analysis.visitors.ImportChecker.visitImportToken(ImportChecker.java:133)
    at com.python.pydev.analysis.visitors.Scope.addImportTokens(Scope.java:168)
    at com.python.pydev.analysis.scopeanalysis.AbstractScopeAnalyzerVisitor.visitImport(AbstractScopeAnalyzerVisitor.java:445)
    at org.python.pydev.parser.jython.ast.Import.accept(Import.java:59)
    at org.python.pydev.parser.jython.ast.Module.traverse(Module.java:66)
    at com.python.pydev.analysis.scopeanalysis.AbstractScopeAnalyzerVisitor.traverse(AbstractScopeAnalyzerVisitor.java:179)
    at com.python.pydev.analysis.visitors.OccurrencesVisitor.traverse(OccurrencesVisitor.java:227)
    at org.python.pydev.parser.jython.ast.VisitorBase.visitModule(VisitorBase.java:8)
    at org.python.pydev.parser.jython.ast.Module.accept(Module.java:59)
    at com.python.pydev.analysis.OccurrencesAnalyzer.analyzeDocument(OccurrencesAnalyzer.java:50)
    at com.python.pydev.analysis.OccurrencesAnalyzer.analyzeDocument(OccurrencesAnalyzer.java:38)
    at com.python.pydev.analysis.builder.AnalysisBuilderRunnable.doAnalysis(AnalysisBuilderRunnable.java:235)
    at com.python.pydev.analysis.builder.AbstractAnalysisBuilderRunnable.run(AbstractAnalysisBuilderRunnable.java:145)
    at org.python.pydev.core.concurrency.RunnableAsJobsPoolThread$1.run(RunnableAsJobsPoolThread.java:97)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

    Session Data:
    eclipse.buildId=M20090917-0800
    java.version=1.5.0_04
    java.vendor=Sun Microsystems Inc.
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_GB
    Framework arguments:  -product org.eclipse.epp.package.java.product
    Command-line arguments:  -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.java.product

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2010-05-18

    Seems there's a problem communicating with the shell… Do you have some firewall enabled that may be preventing the communication?

    Cheers,

    Fabio

     
  • Alex

    Alex - 2010-05-19

    I am fairly sure I do not, though this is on my office machine so there's the usual rubbish loaded on there.  If something were blocking would it not also block completion in the console or does that work differently?

    I went through my running processes and killed pretty much everything running and tried again, but same problem.

    Is there any way to confirm if something's blocking the communication?

     
  • harryp

    harryp - 2010-05-28

    am having a similar issue - code completion in the console is ok, but only once the module imports… code-completion in the editor doesn't work at all.

    sample:
    in Editor:

    from Library.<-- no suggestions
    from Library.Button import Button  <-unresolved import, underlined in red

    in eclipse console:
    from Library.<-- no suggestions
    from Library.Button import Button <-OK
    Button.<- code completion ok.

    that's the Resolver One API btw.

    logs from code-completion logging:

    AbstractShell: connecting…
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
    AbstractShell: attempts: 0
    AbstractShell: maxAttempts: 20
    AbstractShell: finishedForGood: false
    AbstractShell: connecting attept…1
    AbstractShell: serverSocket.accept()!
    AbstractShell: socketToRead.setSoTimeout(5000)
    AbstractShell: connected!
        AbstractShell: Code completion shell error:
        AbstractShell: ERROR:
        AbstractShell: Traceback (most recent call last):
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\pycompletionserver.py", line 310, in run
        defFile, comps = importsTipper.GenerateTip(data, log)
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\importsTipper.py", line 78, in Find
        mod = _imp(name, log)
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\importsTipper.py", line 57, in _imp
        return _old_imp(initial_name, log)
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\importsTipper.py", line 34, in _imp
        raise ImportError(s)
    ImportError: Unable to import module: Library - sys.path:

    Log:Unable to import module: Library - sys.path:
    Traceback (most recent call last):
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\importsTipper.py", line 18, in _imp
        return __import__(name)
    ImportError: No module named Library

        AbstractShell: 
        AbstractShell: -1
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
        AbstractShell: Code completion shell error:
        AbstractShell: ERROR:
        AbstractShell: Traceback (most recent call last):
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\pycompletionserver.py", line 322, in run
        (f, line, col), foundAs = importsTipper.Search(data)
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\importsTipper.py", line 93, in Find
        mod = getattr(mod, comp)
    AttributeError: 'module' object has no attribute 'Button'

    Log:
        AbstractShell: 
        AbstractShell: -1
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
    AbstractShell: Synchronizing on shells…
    AbstractShell: Getting shell related to:IronPython id:1 interpreter: C:\Program Files (x86)\IronPython 2.6\ipy.exe
        AbstractShell: Code completion shell error:
        AbstractShell: ERROR:
        AbstractShell: Traceback (most recent call last):
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\pycompletionserver.py", line 322, in run
        (f, line, col), foundAs = importsTipper.Search(data)
      File "C:\Users\Harry\Desktop\eclipse\plugins\org.python.pydev_1.5.7.2010050621\PySrc\importsTipper.py", line 93, in Find
        mod = getattr(mod, comp)
    AttributeError: 'module' object has no attribute 'Button'

    etc etc…

    thanks in advance for any help!

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2010-06-01

    It seems that the problem is that it cannot import 'Library'. This may happen if your pythonpath is not correct… or sometimes you have some environment variable that's not correct (pydev will inherit the env. variables from the launched eclipse, so, the shell that started eclipse must be correct).

    Another case may be that you just compiled the library, in which case you may have to do ctrl+2+kill to have it clear the caches and start a new shell for doing that analysis.

    Cheers,

    Fabio

     
  • harryp

    harryp - 2010-06-03

    Hey Fabio,

    I think the problem is that the DLL isn't compiled C#, it's compiled python.

    It's definitely on the pythonpath - I've even tried moving the dll into the same folder as my .py file.  And the library imports ok, and can be introspected at the console. Other c# dlls do seem to work in the editor, so it seems to be a specific problem with this dll (and a few others)

    but i did just find out from the developers that Library.dll isn't C#, it's ironpython-compiled python code.  Could that be the problem?  Is introspecting this sort of dll meant to be possible in pydev?

     
  • harryp

    harryp - 2010-06-03

    another theory on why it's not working:  the dll has a number of dependencies, on other dlls and on parts of the windows api (system.data, system.drawing…)…  so before i can import it, i have to:

    clr.AddReference('Library')
    clr.AddReference('Utils') #another dll
    clr.AddReference('System.Data')
    clr.AddReference('System.Drawing')
    from Library.Workbook import Workbook

    could it be that it's these dependencies that are tripping over the autocomplete-interpreter?  Is there any way of forcing them to be loaded?  I've tried putting them in forced builtins, but no cigar…

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2010-06-03

    Try adding that in org.python.pydev_xxx/PySrc/importsTipper.py, in line 39, right after the check:

    if sys.platform == 'cli':

    Then do a ctrl+2+kill and request a new completion to know if it works… If it doesn't, is there any chance that I could have access to that dll (and dependencies) so that I can do some tests here?

    Cheers,

    Fabio

     
  • harryp

    harryp - 2010-06-03

    crashes eclipse ;-)

    my importTipper now reads:

    if sys.platform == 'cli':
    import clr
    clr.AddReference('Library')
    clr.AddReference('Utils') #another dll
    clr.AddReference('System.Data')
    clr.AddReference('System.Drawing')
        IS_IPY = True
        _old_imp = _imp
        def _imp(name, log=None):

    no problems re accessing the DLL.  they're from the Resolver One spreadsheet app, available from http://www.resolversystems.com/download/

    email / im me on harry dott percival att gmail dott com if you need.  i really appreciate your efforts!

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks