Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

IronPython support

cko
2007-10-20
2013-03-15
  • cko
    cko
    2007-10-20

    Can anyone confirm that IronPython can be used as an interpreter with PyDev? I am unable to get code completion work for .Net modules/classes (despite of several posts saying that it is possible). Only modules from the CPython installation work.

    I am using PyDev 1.3.9, IronPython 1.1 and Python 2.4.4 (previously I tried Python 2.5, but had problem with BaseException). Executing ipy.exe tests/test_pyserver.py results in one failed test out of the two, but the same happens with python.exe.

    At first I suspected problems related to the fact that modules representing .Net namespaces (such as System) have no sourcefiles.
    More exactly, inspector.getfile(System) is a list of strings instead of a simple string (as it is the case for CPython modules). I modified importsTipper.py so that it does not try to use the files of .Net assemblies (as they are of no use anyhow), but it did not help.

     
    • cichlasoma
      cichlasoma
      2007-10-21

      i also wasn´t abble to get code completion work for IronPython and for jython either.
      i´ve given an example for jython in "several bugs(?)" thread and would be VERY greatful for any help. :-(

       
      • Fabio Zadrozny
        Fabio Zadrozny
        2007-10-21

        As I said, IronPython is currently unsupported... (although as I said, I've seen reports of people being able to use it).

        As for jython, the current version is lacking a bit with the java integration, but I'm currently working on that -- so, currently, when referencing java projects you must add a python nature to that project and specify the path to the source folders as if they were python source folders... and reference it as a regular module. The code-completion will work through a shell, so, if you change the java code, the pydev code-completion might not be up-to-date... You have to kill the shell (ctrl+2+kill) to be able to have it get the latest version... I'm working to provide a better support, but I'm still unsure if it will make the next version.

        Cheers,

        Fabio

         
    • Fabio Zadrozny
      Fabio Zadrozny
      2007-10-21

      IronPython is not officially supported (never tried to use it myself), but I've also heard from people being able to use it as if it was a regular python interpreter... So in theory, if you put the .net modules you're interested in in the forced builtins (see http://fabioz.com/pydev/manual_101_interpreter.html for details), if the interpreter is able to provide a level of introspection similar to python, it should work... But as I said, I've never tried it...

      Cheers,

      Fabio

       
      • cko
        cko
        2007-10-22

        Hi Fabio,

        Thank you a lot! I added "System" to the list of forced built-ins, and after a few hours of fighting I managed to get import tips and code completion work for this module.

        IronPython has introspection capabilities similar to CPython and possibly better than Jython.
        E.g. .Net XML documentation are accessible via the __doc__ attribute or inspect.getdoc().

        However, I had to modify one of the PyDev Python sourcefiles: in importsTipper.py my version of GetFile looks like this:

        def GetFile(mod):
            f = None
            try:
                f = inspect.getsourcefile(mod) or inspect.getfile(mod)
            except:
                if hasattr(mod,'__file__'):
                    f = mod.__file__
                    try:
                        if f.lower(f[-4:]) in ['.pyc', '.pyo']:
                            filename = f[:-4] + '.py'
                            if os.path.exists(filename):
                                f = filename
                    except:
                        f = None
                        pass #on IronPython mod.__file__ is a list, not a string
                   
            return f

        (The code above works because instead of returning null, inspect.getsourcefile() throws an exception on IP)

         
        • cko
          cko
          2007-10-22

          Unfortunately, the workaround above is not so good. After trying to use Winforms, I discovered that there are IronPython modules that do have a string __file__ attribute, such as System.Windows and System.Windows.Forms.
          So I can't get code completion for these, and I am not able to hack importsTipper.GetFile to ignore these.

          Would it be possible to modify the Java side so that it ignores @@COMPLETION messages that have nonexistent files as the first argument?

          BTW, I also experienced problems with Unicode characters. Seemingly, the guys writing the .Net documentation were not afraid of using e.g. \theta when documenting System.Math.Atan().
          Do unicode strings work when using CPython?

           
          • cko
            cko
            2007-10-22

            Sorry, no need to modify anything on the Java side. I noticed it only now that importsTippet.GetFile does check for file existence, when inspector fails to fetch the file.

             
    • cichlasoma
      cichlasoma
      2007-10-21

      thanks!
      yet, what about code completion support for java core libraries?
      (doesn´t work fo me, i copy the example i posted earlier:)

      (pydev project type set to jython:)

      import javax.swing
      from javax.swing import *

      #b=JB/ctrl+space -> JButton - ok/
      b=JButton()
      #b./nothing offered, ctrl+space -> "BEEP"/
      #JButton./nothing offered, ctrl+space -> "BEEP"/

       
    • cichlasoma
      cichlasoma
      2007-10-22

      couldn't anybody comment on my example, please?
      I don't know whether i'm doing a very silly mistake or whether it should work in fact...