Search code examples
eclipsepydev

Support Eclipse EASE instructions in PyDev


I'm using Eclipse EASE (https://www.eclipse.org/ease/) with the EASE Python Engine. The problem is PyDev doesn't recognize EASE instructions. The goal is to get nor errors for the python modules and methods that have been imported through the include EASE instruction and the completion for the methods coming from such modules.

Let's say I have a first EASE Python module:

AddReadMe.py
------------

loadModule('/System/Resources')

def fct_readme():
    for iproject in getWorkspace().getProjects():
        if not iproject.isOpen():
            continue
        
        ifile = iproject.getFile("README.md")
        
        if not ifile.exists():
            contents = "# " + iproject.getName() + "\n\n" 
            if iproject.hasNature("org.eclipse.jdt.core.javanature"):
                contents += "A Java Project\n"
            elif iproject.hasNature("org.python.pydev.pythonNature"):
                contents += "A Python Project\n"
            writeFile(ifile, contents)

Then I have a 2nd EASE Python module:

AnotherModule.py
----------------

include('script://AddReadMe.py')
fct_readme()

The PyDev editor shows 2 errors: the first for the include statement and the second for the fct_readme(), and this is logical because PyDev doesn't know the EASE include instruction.

Is it possible to use some PyDev extensions points to support EASE? Which one(s)?

Best regards,


Solution

  • Well, there are 2 issues here:

    1. PyDev does code-analysis based on how you configure it, so, you probably need to do here is provide stubs for PyDev to be able to find the needed names in your namespace (in this case you'd need stubs for the System.Resources -- the AddReadMe doesn't need it as it should be able to find the actual sources in this case).
    2. PyDev has no way to know that some custom include() or loadModule() function actually does an import.

    One option here could be providing the builtin modules for PyDev in the form of predefined completions: https://www.pydev.org/manual_101_interpreter.html#PyDevInterpreterConfiguration-PredefinedCompletions (or create Python module stub-files).

    Then, to make it actually find that, do something as an import in an if False (so, PyDev will consider it in code-analysis even though it won't be executed):

    include('script://AddReadMe.py')
    if False:
        from AddReadMe import *
    
    
    loadModule('/System/Resources')
    if False:
        from System.Resources import *
    

    Note: Make sure that your sources are under a source module for the code-analysis/code-completion to work properly there (https://www.pydev.org/manual_101_project_conf2.html).