Announcement Announcement Module
No announcement yet.
Spring Python does NOT run on Jython Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Python does NOT run on Jython

    UPDATED 11/5/2009: The topic discussed on the following thread has become moot. Spring Python 1.1 swapped out Amara's XML parser for ElementTree, so now it works perfectly on Jython. See http://blog.springpython.webfactiona...s-with-jython/ for a detailed example.
    ================================================== ================================================== ======================

    Well, it is with great sadness that I must report my attempt to run the Spring Python test suite against jython 2.5b0 failed. In fact, it didn't really get very far. It is a core issue involved with the tools used to install amara (or any easy_install based tool).

    It depends on a small variable called sys.executable, which for jython is empty, required to implement the "shebang". To read more, you can see, where the issue is known and tracked to some degree.

    I don't know if jython will solve this problem, but until I can find a way to execute:
    jython easy_install amara
    ...we will NOT have jython support.
    Last edited by gregturn; Nov 5th, 2009, 11:49 AM.

  • #2
    sys.executable in Jython

    sys.executable can be specified in Jython 2.5b0. The jython command generated by the installer and the one included in the dev build ([jython_home]/dist/bin/jython) should have one set. Apparently the spam filter is not allowing me to post urls, but I think I can follow up with one...

    Just do this on *nix:

    java -Dpython.executable="$0" org.python.util.jython

    This on Windows:

    java.exe -Dpython.executable="%0" org.python.util.jython



    • #3
      link for sys.executable

      More on sys.executable in Jython can be found here:


      • #4
        That step didn't help me. I even have my jython script updated with those settings, but it still fails to populate sys.executable.
        [[email protected] Amara-1.2a2]$ java -Dpython.executable="$0" -Dpython.home="/home/springpython/jython2.5b0" -classpath "$CP" org.python.util.jython install
        sys.executable = None
        Traceback (most recent call last):
          File "", line 7, in <module>
            from setuptools import setup, find_packages
          File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/", line 2, in <module>
          File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/", line 2, in <module>
          File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/", line 5, in <module>
          File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/command/", line 2, in <module>
          File "/home/springpython/jython2.5b0/Lib/distutils/command/", line 15, in <module>
            from distutils.sysconfig import get_config_vars
          File "/home/springpython/jython2.5b0/Lib/distutils/", line 30, in <module>
            argv0_path = os.path.dirname(os.path.abspath(sys.executable))
          File "/home/springpython/jython2.5b0/Lib/", line 413, in abspath
            if not isabs(path):
          File "/home/springpython/jython2.5b0/Lib/", line 51, in isabs
            return s.startswith('/')
        AttributeError: 'NoneType' object has no attribute 'startswith'
        [[email protected] Amara-1.2a2]$
        My jython script is now
        if [ ! -z $CLASSPATH ]
        java -Dpython.executable="$0" -Dpython.home="/home/springpython/jython2.5b0" -classpath "$CP" org.python.util.jython "[email protected]"


        • #5
          Okay, I don't know what happened, but I tried jython install inside the Amara directory, and started getting results, so disregard my last posting.

          However, things still didn't get much further. This is the output from trying to to install amara:
          [[email protected] Amara-1.2a2]$ jython install
          running install
          running bdist_egg
          running egg_info
          writing Amara.egg-info/PKG-INFO
          writing top-level names to Amara.egg-info/top_level.txt
          writing entry points to Amara.egg-info/entry_points.txt
          writing dependency_links to Amara.egg-info/dependency_links.txt
          writing requirements to Amara.egg-info/requires.txt
          reading manifest file 'Amara.egg-info/SOURCES.txt'
          writing manifest file 'Amara.egg-info/SOURCES.txt'
          installing library code to build/bdist.java1.6.0_10-rc2/egg
          running install_lib
          running build_py
          creating build/bdist.java1.6.0_10-rc2/egg
          creating build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          copying build/lib/amara/ -> build/bdist.java1.6.0_10-rc2/egg/amara
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to bindery$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to trimxml$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to domtools$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to binderytools$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to dateutil_standins$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to binderyxpath$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to pyxml_standins$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to saxtools$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to flextyper$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to __init__$py.class
          byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/ to scimitar$py.class
          creating build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          copying Amara.egg-info/PKG-INFO -> build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          copying Amara.egg-info/SOURCES.txt -> build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          copying Amara.egg-info/dependency_links.txt -> build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          copying Amara.egg-info/entry_points.txt -> build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          copying Amara.egg-info/requires.txt -> build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          copying Amara.egg-info/top_level.txt -> build/bdist.java1.6.0_10-rc2/egg/EGG-INFO
          zip_safe flag not set; analyzing archive contents...
          Unable to analyze compiled code on this platform.
          Please ask the author to include a 'zip_safe' setting (either True or False) in the package's
          creating 'dist/Amara-1.2a2-py2.5.egg' and adding 'build/bdist.java1.6.0_10-rc2/egg' to it
          removing 'build/bdist.java1.6.0_10-rc2/egg' (and everything under it)
          Processing Amara-1.2a2-py2.5.egg
          removing '/home/springpython/jython2.5b0/Lib/site-packages/Amara-1.2a2-py2.5.egg' (and everything under it)
          creating /home/springpython/jython2.5b0/Lib/site-packages/Amara-1.2a2-py2.5.egg
          Extracting Amara-1.2a2-py2.5.egg to /home/springpython/jython2.5b0/Lib/site-packages
          Amara 1.2a2 is already the active version in easy-install.pth
          Installing trimxml script to /home/springpython/jython2.5b0/bin
          Installing scimitar script to /home/springpython/jython2.5b0/bin
          Installing flextyper script to /home/springpython/jython2.5b0/bin
          Installed /home/springpython/jython2.5b0/Lib/site-packages/Amara-1.2a2-py2.5.egg
          Processing dependencies for Amara==1.2a2
          Searching for 4Suite-XML>=1.0
          Best match: 4Suite-XML 1.0.2
          Running 4Suite-XML-1.0.2/ -q bdist_egg --dist-dir /tmp/easy_install-VTNsWz/4Suite-XML-1.0.2/egg-dist-tmp-6KxXdd
          error: Setup script exited with error: in packages/Xml.pkg: unsupported package attribute: sys
          It seems it has trouble installing a followup package, 4Suite-XML. I pulled that down, and then tried to install it directly, and got the following stack trace:
          [[email protected] 4Suite-XML-1.0.2]$ jython install
          error: in packages/Xml.pkg: unsupported package attribute: sys
          Perhaps this is some issue with 4Suite. It appears to have some C extensions, and maybe that is too much for Jython.


          • #6
            Jython and C-extensions

            C-extensions are indeed too much for Jython to handle. More and more libraries and packages are including pure Python alternatives (see the standard lib for an excellent example for how to do this) but that is far from the norm.


            • #7
              Spring Python DOES run on Jython

              dummy post to get url posting privileges:

                 1. You are only allowed to post URLs to other sites after you have made 1 post or more.


              • #8
                Spring Python does run on Jython

                Hi Greg,

                i just got springpython working on jython. On jython it isn't possible to use c-bindings, so amara can't be used for xml-parsing. I tried to exchange amara with Element-Tree and with some changes i got a simple application-context up and running. Element-Tree is a pure python implementation which is required for jython but is also available as a python extension (c-implementation).

                On springpythononjython it is possible to get access to java classes. So it is of course possible to get a "bean" into your springpython application context like this:

                <?xml version="1.0" encoding="UTF-8"?>
                <objects xmlns=""
                	<!-- a python module -->
                    <object id="pythonTest" class="" />
                    <!-- a java bean -->
                    <object id="javaTest" class="org.seminode.springpythononjython.Test" />
                And it works:

                [create_object] <java package org.seminode.springpythononjython 0x3> --- class: Test
                Hello from spring java
                [create_object] <module '' from '/home/aschaeffer/dev/workspace/springpythononjython/src/python/py/org/seminode/springpythononjython/'> --- class: Test
                Hello from spring python

                During my current project i will finish the Element Tree based XMLConfig class and will contribute it during the next days.


                PS: As a nice gimmick: did you ever got springpython running as a java bean inside springframework? :-)
                It works...


                • #9
                  Excellent work!


                  I certainly appreciate your work here. That sounds like some excellent progress. Russ, Sylvain and I were discussing jython/ironpython/cpython and what should we shoot for on a separate thread. I would definitely like to hear your opinions about this.

                  See for that thread.

                  Regarding ElementTree, I haven't looked into it much. I fell in love with Amara for XML parsing. I will be very interested in seeing what your alternative looks like. I will also be debating whether we should go with a pure python parser for everything, or if having an ElementTree-based one is practical for jython-based solutions, while Amara better suits CPython solutions. There always pros and cons.

                  Regarding Spring Python-backed bean inside Spring Java, no I haven't done that. Are you referring to usage of jython, or instead of spring/java's ability to have script-based beans? Sounds intriguing. I guess I'm interesting in hearing a use case where it would be valuable to do that. I always have interoperability in the back of my mind.

                  BTW, if you have a patch to offer, I am always open to looking at opportunities for Spring Python.



                  • #10
                    Russ posted a follow-up
                    I can't help but wonder if it would be possible to essentially configure the Spring Python container with the parser of choice in this regard. We could effectively extract out the parser role, hide it behind and interface and then explicitly inject the desired parser depending on environmental constraints?

                    My response:
                    I was thinking along the same lines. I can see a couple of strategies for doing this. One would be some sort of strategy pattern, where you inject the parser, and there is an interface. Another would be to have separate parsers, with the end goal returning the same container.

                    The approach I'm thinking is to The first cut to having another XML parser would be to clone every test case built around XMLConfig, create another parser called ThisNewXMLConfigParser, and start parsing for the same end results. Considering that XMLConfig was built TDD-style, I'm confident that there are MANY permutations covered, so if all tests passed, I would also be confident in the new parser.

                    Then we could compare the two parsers and try to extract common functionality. Considering XMLParser is at least 90% based on the API of amara, I predict little that could be refactored beyond a simple switch. To me, it seems easier to create a separate class right next to XMLParser.

                    One smooth thing would be to actually embed simple detection of whether this is CPython or Jython, using XMLParser by default, and switching to ThisNewXMLParser should the need arise. That would minimize the need for developers to code based on environment. THAT would be the biggest benefit, in my book!


                    • #11
                      I won't discuss the default choice of XML parser, since I'm biased

                      But one idea is for the Spring Python project to host on the Web a config parser service (and make this easy to deploy/federate elsewhere). Another option is to freeze the parser component as a stand-alone command.
                      Last edited by uche; Apr 17th, 2009, 09:53 PM.


                      • #12
                        You mean so that people could transmit an XML document over the wire to us, we convert it into a container, and send it back. Hmm...I have to think about this. Seems like there might be some security risks involved, and with us being able to mix input formats together, not sure how to handle that.

                        However, freezing the parser as a command-line option would offer a more local option. I guess it would still depend on the user have the right stuff in place. If people are really contemplating jython, are they going to want it all "in a jarfile" when complete and not really care for that? Using a pure python parser would generate the necessary class files to pick up for deployment

                        I guess I look at things from the perspective of being able to build a simple web app on GAE, and using either the python solution, or the jython jar file option.


                        • #13
                          I was suggesting the remote service more as a tool for quick experimentation and such, to ease in new users not wanting to fiddle with CPython to use SP. Of course security issues would prevent using such a service for production, but really, if someone is going to seriously deploy on the SP framework for production, issues such as not wanting to use a code that includes C are probably the last worries.

                          The frozen option is precisely like the .jar you mention. It would be one drop-in file that does the job. The good old fashioned UNIX pipes way

                          I should mention that we are considering the options for Jython and .NET in Amara 2.x, but to be honest I'm not sure when we'll get to that.


                          • #14
                            I tried to exchange amara with Element-Tree and with some changes i got a simple application-context up and running. Element-Tree is a pure python implementation which is required for jython but is also available as a python extension (c-implementation).



                            dossier surendettement