Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Advanced Scripting Environment (EASE) » import vs include
import vs include [message #1835707] Thu, 10 December 2020 18:49 Go to next message
Axel RICHARD is currently offline Axel RICHARDFriend
Messages: 43
Registered: September 2010
Location: France
Member
Hello,

I do some tests with EASE and PyDev and its really powerful! Kudos to the team!

Let's say I have two Python scripts in the same folder.

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)


and Test.py. In Test.py I want to call fct_readme().

The first approach:
import scripts.AddReadMe
scripts.AddReadMe.fct_readme()

leads to an error when executed with Run As > EASE Script (ImportError: No module named scripts.AddReadMe)

The second approach:
include('script://AddReadMe.py')
fct_readme()

is well executed with Run As > EASE Script.

The problem with the second approach is that PyDev shows errors for the include(...) statement and the fct_readme() call.

Is it possible to have no editor error with PyDev editor with the second approach, or better have no execution error with the first approach?
Any pointers to solve one or both problems will be appreciated.

Thank you,


Axel Richard
Obeo

[Updated on: Thu, 10 December 2020 18:50]

Report message to a moderator

Re: import vs include [message #1835848 is a reply to message #1835707] Tue, 15 December 2020 06:24 Go to previous message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
In python each module comes with its own scope. For the java <-> python bridge to work EASE injects some stuff to the global scope of your main script. This allows your python script to connect to java, load modules, etc. In a custom module this is all missing, therefore you are not able to use EASE features there. So I guess making EASE work within a python module will not be an easy task.

The PyDev environment now analyses python code, but cannot see the dynamic injections that will be done by EASE at runtime. Thats the reason why you get error markers on your code. Also fixing these things would be some major effort to be done in PyDev and currently there is no one stepping forward to do this.

Christian
Previous Topic:Build UIs with unease!
Next Topic:EASE UI module takes over context menus?
Goto Forum:
  


Current Time: Thu Apr 25 12:44:28 GMT 2024

Powered by FUDForum. Page generated in 0.03041 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top