Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Spring Python does NOT run on Jython

  1. #1
    Join Date
    Aug 2006
    Posts
    382

    Default 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 http://bugs.python.org/setuptools/issue27, 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:
    Code:
    jython easy_install amara
    ...we will NOT have jython support.
    Last edited by gregturn; Nov 5th, 2009 at 11:49 AM.
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

  2. #2

    Default 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

    -Frank

  3. #3

    Default link for sys.executable

    More on sys.executable in Jython can be found here: http://article.gmane.org/gmane.comp....hon.devel/4068

  4. #4
    Join Date
    Aug 2006
    Posts
    382

    Default

    That step didn't help me. I even have my jython script updated with those settings, but it still fails to populate sys.executable.
    Code:
    [springpython@web35 Amara-1.2a2]$ java -Dpython.executable="$0" -Dpython.home="/home/springpython/jython2.5b0" -classpath "$CP" org.python.util.jython setup.py install
    sys.executable = None
    Traceback (most recent call last):
      File "setup.py", 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/__init__.py", line 2, in <module>
      File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/extension.py", line 2, in <module>
      File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/dist.py", line 5, in <module>
      File "/home/springpython/jython2.5b0/Lib/site-packages/setuptools-0.6c9-py2.5.egg/setuptools/command/install.py", line 2, in <module>
      File "/home/springpython/jython2.5b0/Lib/distutils/command/install.py", line 15, in <module>
        from distutils.sysconfig import get_config_vars
      File "/home/springpython/jython2.5b0/Lib/distutils/sysconfig.py", line 30, in <module>
        argv0_path = os.path.dirname(os.path.abspath(sys.executable))
      File "/home/springpython/jython2.5b0/Lib/posixpath.py", line 413, in abspath
        if not isabs(path):
      File "/home/springpython/jython2.5b0/Lib/posixpath.py", line 51, in isabs
        return s.startswith('/')
    AttributeError: 'NoneType' object has no attribute 'startswith'
    [springpython@web35 Amara-1.2a2]$
    My jython script is now
    Code:
    #!/bin/sh
    
    CP=/home/springpython/jython2.5b0/jython-complete.jar
    if [ ! -z $CLASSPATH ]
    then
      CP=$CP:$CLASSPATH
    fi
    java -Dpython.executable="$0" -Dpython.home="/home/springpython/jython2.5b0" -classpath "$CP" org.python.util.jython "$@"
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

  5. #5
    Join Date
    Aug 2006
    Posts
    382

    Default

    Okay, I don't know what happened, but I tried jython setup.py 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:
    Code:
    [springpython@web35 Amara-1.2a2]$ jython setup.py 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/bindery.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/trimxml.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/domtools.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/binderytools.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/dateutil_standins.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/binderyxpath.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/pyxml_standins.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/saxtools.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/flextyper.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/__init__.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    copying build/lib/amara/scimitar.py -> build/bdist.java1.6.0_10-rc2/egg/amara
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/bindery.py to bindery$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/trimxml.py to trimxml$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/domtools.py to domtools$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/binderytools.py to binderytools$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/dateutil_standins.py to dateutil_standins$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/binderyxpath.py to binderyxpath$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/pyxml_standins.py to pyxml_standins$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/saxtools.py to saxtools$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/flextyper.py to flextyper$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/__init__.py to __init__$py.class
    byte-compiling build/bdist.java1.6.0_10-rc2/egg/amara/scimitar.py 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 setup.py
    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
    Reading http://pypi.python.org/simple/4Suite-XML/
    Reading http://4suite.org/
    Reading ftp://ftp.4suite.org/4Suite/
    Best match: 4Suite-XML 1.0.2
    Downloading http://pypi.python.org/packages/source/4/4Suite-XML/4Suite-XML-1.0.2.zip#md5=b5515baa72c1b88613af71d2af0a539a
    Processing 4Suite-XML-1.0.2.zip
    Running 4Suite-XML-1.0.2/setup.py -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:
    Code:
    [springpython@web35 4Suite-XML-1.0.2]$ jython setup.py 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.
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

  6. #6

    Default 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 heapq.py for an excellent example for how to do this) but that is far from the norm.

  7. #7
    Join Date
    Apr 2009
    Posts
    2

    Default Spring Python DOES run on Jython

    dummy post to get url posting privileges:

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

  8. #8
    Join Date
    Apr 2009
    Posts
    2

    Default 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:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <objects xmlns="http://www.springframework.org/springpython/schema/objects"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/springpython/schema/objects
        http://springpython.webfactional.com/schema/context/spring-python-context-1.0.xsd">
    
    	<!-- a python module -->
        <object id="pythonTest" class="py.org.seminode.springpythononjython.test.Test" />
        
        <!-- a java bean -->
        <object id="javaTest" class="org.seminode.springpythononjython.Test" />
    
    </objects>
    And it works:

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

    Regards,
    Andreas

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

  9. #9
    Join Date
    Aug 2006
    Posts
    382

    Default Excellent work!

    Andreas,

    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 http://forum.springsource.org/showthread.php?t=60588 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.

    Thanks,
    Greg
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

  10. #10
    Join Date
    Aug 2006
    Posts
    382

    Default

    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!
    Greg L. Turnquist (@gregturn), SpringSource/VMware
    Project Lead: Spring Python and author of Spring Python 1.1 and Python Testing Cookbook.
    Listen to Pond Jumpers, the international podcast for open source developers.
    These comments are my own personal opinions, and do not reflect those of my company.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •