Treating Java classes as builtins with Jython

Em Smith
2008-12-12
2013-03-15
  • Em Smith

    Em Smith - 2008-12-12

    I'm using Pydev to develop in Jython, using a set of pre-built Java classes saved in JARs. I've added the JARs to my PYTHONPATH in my Jython interpreter, so I can import from them with regular Python import statements.

    However, I'd like to have them available for use and code completion WITHOUT needing to import them. I see that Pydev has precisely this feature: a list of forced builtin libs. The only problem is that this seems to only work with Python modules. Is there any way to add Java classes/JARs to the forced builtin libs?

    Thanks!

     
    • Em Smith

      Em Smith - 2008-12-17

      No ideas?

      OK, what if I wrote a python module that did all the JAR imports I wanted? How would I add that python module to the forced builtin libs?

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2008-12-17

        Sorry for the delay...

        I didn't understand how are you using them without importing it... can you explain better your use case?

        Cheers,

        Fabio

         
        • Em Smith

          Em Smith - 2008-12-26

          The Jython scripts will be uploaded into an environment where these JARs have already been imported. My scripts will have access to those objects without me adding an import statement (in fact, if I add import statements now, it will break when I upload it to the environment).

          However, when I'm developing in Pydev, I want code completion to be able to see those objects. (I could add import statements while developing in Pydev, but I'd have to remove them every time I upload to the environment.) That's why I figure the forced builtins list is a good idea: It will let me use code completion for those objects, but I won't have to put import statements in my code. How might I do this?

           
          • Fabio Zadrozny

            Fabio Zadrozny - 2008-12-29

            Actually, I think that your best choice would be using Pydev Extensions -- it already has a context insensitive code-completion that does what you want (and as you don't want imports, you can disable it's auto-import when the code-completion is performed at window > preferences > pydev > pydev extensions > auto imports), but note that will still only bring you the top-level classes correctly, not the internal tokens of each class (methods and attributes).

            Note that you should also disable the code-analysis for undefined variables (because tokens will come from the imports without needing any imports -- or you could disable code-analysis altogether).

            The auto-imports were not really done for that (you'd other problems if you put all your classes there, as Pydev expects those to be modules, so, you still have to import them -- the other choice would actually be doing the code-completion engine return your clasess when the builtins are requested, but that's not straightforward).

            Cheers,

            Fabio

             
    • Em Smith

      Em Smith - 2008-12-26

      The Jython scripts will be uploaded into an environment where these JARs have already been imported. My scripts will have access to those objects without me adding an import statement (in fact, if I add import statements now, it will break when I upload it to the environment).

      However, when I'm developing in Pydev, I want code completion to be able to see those objects. (I could add import statements while developing in Pydev, but I'd have to remove them every time I upload to the environment.) That's why I figure the forced builtins list is a good idea: It will let me use code completion for those objects, but I won't have to put import statements in my code. How might I do this?

       

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks