Robot framework with standalone jython

1,156 views
Skip to first unread message

pi

unread,
Mar 18, 2010, 11:03:01 PM3/18/10
to robotframework-users

Hello,

My automation group recently standardized using standalone version of
jython instead of standard, but standalone version does not do java
package caching, which makes it impossible to load java libraries.

Has anybody been able to solve this problem? Or does robot framework
support standalone jython?

My command line looks something like this:

java -classpath path/to/jar /path/robot/runner.py [options]
data_sources

Particular example, is using trying to import javalib in robot specs
(.tsv) settings section

Library org.robotframework.javalib.library.AnnotationLibrary com/
basistech/grail/lemmatization/**.class

Failure is:

Importing test library
'org.robotframework.javalib.library.AnnotationLibrary' failed:
ImportError: No module named robotframework

I know for sure, this works with standard jython installation, but it
is not an option I can use now.

Any help in this matter will be greatly appreciated

Pekka Klärck

unread,
Mar 19, 2010, 5:12:54 PM3/19/10
to bug...@gmail.com, robotframework-users
2010/3/19 pi <bug...@gmail.com>:

>
> My automation group recently standardized using standalone version of
> jython instead of standard, but standalone version does not do java
> package caching, which makes it impossible to load java libraries.
>
> Has anybody been able to solve this problem? Or does robot framework
> support standalone jython?

Are you sure it's not possible to use Java libraries from the
standalone Jython? I would be highly surprised about it because using
Java is the biggest reason to use Jython.

> My command line looks something like this:
>
> java -classpath path/to/jar /path/robot/runner.py [options]
> data_sources
>
> Particular example, is using trying to import javalib in robot specs
> (.tsv) settings section
>
> Library      org.robotframework.javalib.library.AnnotationLibrary       com/
> basistech/grail/lemmatization/**.class
>
> Failure is:
>
> Importing test library
> 'org.robotframework.javalib.library.AnnotationLibrary' failed:
> ImportError: No module named robotframework
>
> I know for sure, this works with standard jython installation, but it
> is not an option I can use now.

I'm not a Java expert myself, but I have enough experience to know
that most Java problems like this are somehow related to the
classpath. Are you sure you have AnnotationLibrary in classpath in
this case?


We have actually discussed packaging Robot Framework and Jython into a
standalone jar file that could be used without Python. This isn't too
high on the priority list for the core development team, but if
someone else is interested to look at this we are highly interested.

Cheers,
.peke


--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Pekka Klärck

unread,
Mar 22, 2010, 4:30:17 AM3/22/10
to Shark, robotframework-users
[Added rf-users back to Cc.]

2010/3/20 Shark <bug...@gmail.com>:


> On Fri, Mar 19, 2010 at 5:12 PM, Pekka Klärck <pekka....@gmail.com>
> wrote:
>> 2010/3/19 pi <bug...@gmail.com>:
>> >
>> > My automation group recently standardized using standalone version of
>> > jython instead of standard, but standalone version does not do java
>> > package caching, which makes it impossible to load java libraries.
>> >
>> > Has anybody been able to solve this problem? Or does robot framework
>> > support standalone jython?
>>
>> Are you sure it's not possible to use Java libraries from the
>> standalone Jython? I would be highly surprised about it because using
>> Java is the biggest reason to use Jython.
>>

> Yes, I am sure of it - jython standalone version ignores classpath and
> requires you to import each java package separately through interpreter

Sorry, I don't really get this. What do you mean with importing
separately through the interpreter? As I wrote, using Java is the main
use case of Jython, and I'm sure there is a way to get this done.

>> > My command line looks something like this:
>> >
>> > java -classpath path/to/jar /path/robot/runner.py [options]
>> > data_sources
>> >
>> > Particular example, is using trying to import javalib in robot specs
>> > (.tsv) settings section
>> >
>> > Library      org.robotframework.javalib.library.AnnotationLibrary
>> > com/
>> > basistech/grail/lemmatization/**.class
>> >
>> > Failure is:
>> >
>> > Importing test library
>> > 'org.robotframework.javalib.library.AnnotationLibrary' failed:
>> > ImportError: No module named robotframework
>> >
>> > I know for sure, this works with standard jython installation, but it
>> > is not an option I can use now.
>>
>> I'm not a Java expert myself, but I have enough experience to know
>> that most Java problems like this are somehow related to the
>> classpath. Are you sure you have AnnotationLibrary in classpath in
>> this case?
>

> jar containing AnnotationLibrary is in the path.
> Another reason I know this is not a classpath problem from me is because all
> this works fine with standard version of jython

Are you starting everything exactly the same way? As I wrote I'm not a
Java expert, but I know that it's pretty strict on how you need to set
the classpath. The specified classpath is, for example, ignored if you
use -jar option, and it could also be that CLASSPATH environment
variable isn't processed when you use -classpath option.


>> We have actually discussed packaging Robot Framework and Jython into a
>> standalone jar file that could be used without Python. This isn't too
>> high on the priority list for the core development team, but if
>> someone else is interested to look at this we are highly interested.
>

> This would be great!!! If I would know how I would help.

It would help if someone studied how packaging everything together
could be done in practice. This stuff ought to be explained pretty
well in the Jython Book (http://jythonbook.com) and especially in the
Jython/Java integration chapter:
http://jythonpodcast.hostjava.net/jythonbook/en/.99/JythonAndJavaIntegration.html

Pekka Klärck

unread,
Mar 22, 2010, 5:55:51 PM3/22/10
to Shark, robotframework-users
Sorry but I cannot help you more. I've never used the standalone
Jython myself and don't have time to try it out now. I'm again adding
rf-users back to Cc in case someone else could perhaps help you. You
might also want to ask for help regarding to the standalone Jython on
Jython mailing lists. Please also report back here if you got the
problem solved.

Cheers,
.peke

2010/3/22 Shark <bug...@gmail.com>:


>
>
> On Mon, Mar 22, 2010 at 4:30 AM, Pekka Klärck <pekka....@gmail.com>
> wrote:
>>
>> [Added rf-users back to Cc.]
>>
>> 2010/3/20 Shark <bug...@gmail.com>:
>> > On Fri, Mar 19, 2010 at 5:12 PM, Pekka Klärck <pekka....@gmail.com>
>> > wrote:
>> >> 2010/3/19 pi <bug...@gmail.com>:
>> >> >
>> >> > My automation group recently standardized using standalone version of
>> >> > jython instead of standard, but standalone version does not do java
>> >> > package caching, which makes it impossible to load java libraries.
>> >> >
>> >> > Has anybody been able to solve this problem? Or does robot framework
>> >> > support standalone jython?
>> >>
>> >> Are you sure it's not possible to use Java libraries from the
>> >> standalone Jython? I would be highly surprised about it because using
>> >> Java is the biggest reason to use Jython.
>> >>
>> > Yes, I am sure of it - jython standalone version ignores classpath and
>> > requires you to import each java package separately through interpreter
>>
>> Sorry, I don't really get this. What do you mean with importing
>> separately through the interpreter? As I wrote, using Java is the main
>> use case of Jython, and I'm sure there is a way to get this done.
>

> I am sure there is a way to get it done and I would be very interested to
> find out how is java used with standalone jython.
> Is there a use case of how to execute robot tests with standalone jython? My
> claim is that there is a difference in executions and I have not being able
> to figure out the magic to succeed through robot test case execution
> My command looks something like this
> java -classpath [classpath with all jars test libraries including standalone
> jython jar] org/python/util/jython /path/to/runner.py [options] DATA
> However,
> none of the jar are being imported (cached) by package manager from jython
> and so executing robotframework will report setting error, that some library
> cannot be imported
> In my case that library is javalib_core and is specified in test spec in
> settings section:
>  Library     org.robotframework.javalib.library.AnnotationLibrary
> /path/to/my/classes
> To workaround this problem it was suggested by some members if my team to
> use PythonInterpreter to import java packages:
> http://jython.sourceforge.net/docs/javadoc/org/python/util/PythonInterpreter.html
> This is an example what do I mean by separate interpreter (of course this
> did not work ;))
>
> Properties postProperties = new Properties();
>
>         postProperties.put("python.home", jythonHome);
>
>         postProperties.put(PySystemState.PYTHON_CACHEDIR,
> System.getProperty("java.io.tmpdir"));
>
>         postProperties.put(PySystemState.PYTHON_CACHEDIR_SKIP, "false");
>
>         PySystemState.initialize(null, postProperties);
>
>         PySystemState pySystemState = new PySystemState();
>
>         ClassLoader loader = getClass().getClassLoader();
>
>         System.out.println(loader);
>
> // this section tries to import javalib package to do the same thing what
> jython-standard was doing underneath
>
>         PythonInterpreter pi = new PythonInterpreter(new PyStringMap(),
> pySystemState);
>
>         StringReader reader = new StringReader("import
> org.robotframework.javalib.library");
>
>         PyCode autogenCode = pi.compile(reader);
>
>         pi.exec(autogenCode);
>
> // this section tries to execute runner.py script inside the python
> interperter
>
>         InputStreamReader genReader = new InputStreamReader(new
> FileInputStream(runner_script), "utf-8");
>
>         autogenCode = pi.compile(genReader);
>
>         pi.exec(autogenCode);

> I am not using jar option (calling it directly java -classpath [..]
> org.python.util.jython ....)

Shark

unread,
Mar 23, 2010, 10:26:11 AM3/23/10
to Pekka Klärck, robotframework-users
Added robot users in cc list

Here is how to reproduce issue with standalone jython installaton;

1) Download jython installer http://www.jython.org/
2) run java -jar jython_installer-2.5.1.jar 

this will give you standard java installation


4) extract example and drop my attached file (run_mode.sh) into javalib-core-example/robot-tests directory.This is a slightly modified script from original published the example (I just changed the way to run robot script)

5) run  ./run_mod.sh javalib-core-example1.html from javalib-core-example/robot-tests directory

you will need to set JYTHON and ROBOT variables (inside the script you will see the example)

In this mode everything should be successful.


NOW, install standalone jython ($ java -jar jython_installer-2.5.1.jar
then when you come to the "Installation type" page, select "Standalone".)

Now repeat step (5) with path to the standalone jython. You will see the error I have been talking about

Please let me know if you have any questions regarding reproducing the error

run_mod.sh

Pekka Klärck

unread,
Mar 24, 2010, 5:57:40 PM3/24/10
to Shark, robotframework-users
2010/3/23 Shark <bug...@gmail.com>:

> Here is how to reproduce issue with standalone jython installaton;
[snip]

I don't have time to try to reproduce this, but a fast search using
terms "jython standalone classpath" revealed that there really seems
to be issues related to scanning jar files when using the standalone
Jython. You can try the search yourself, but especially these bug
reports provide some interesting information:

http://bugs.jython.org/issue1422
http://bugs.jython.org/issue1778514

The latter one of these reports has actually been submitted by Juha
from our team 2,5 years ago, so apparently this isn't the first time
this problem is encountered with Robot Framework. The problem is
reported against Jython 2.2, but based on the former report there are
similar issues in 2.5 too.

The good news is that the reply by Charlie Groves gives me an idea
what you could try as a workaround. Instead of using CLASSPATH
environment variable to specify the jar files containing libraries,
pass them to RF using the --pythonpath command line option. RF will
then add those jars to sys.path internally, and according to Charlie
that ought to work.

Please report back if the proposed workaround actually works or you
find some other solution. We probably should also document this
problem in the installation instructions or somewhere else.

Shark

unread,
Mar 25, 2010, 10:54:52 AM3/25/10
to Pekka Klärck, robotframework-users
This is a workaround that worked for me:

I added one line of code to importing.py robot utlis inside _import method

        __import__(name) # my line, where name is equal to full package name
        imported = __import__(modname, {}, {}, fromlist) # previous line still needs to be kept

This worked like a charm.

Note, that previously I have tried both --pythonpath command line option as well as -Dpython.path  - none worked

Juha Rantanen

unread,
May 12, 2010, 9:55:53 AM5/12/10
to bug...@gmail.com, Pekka Klärck, robotframework-users
Hi,

Importing libraries with standalone Jython is now fixed [1]. Thanks
for pointing out the way to fix this.

[1] http://code.google.com/p/robotframework/issues/detail?id=515

Br,
Juha

2010/3/25 Shark <bug...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "robotframework-users" group.
> To post to this group, send email to robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to
> robotframework-u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/robotframework-users?hl=en.
>

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.

Reply all
Reply to author
Forward
0 new messages