From: Syver E. <sy...@cy...> - 2001-02-05 02:32:32
|
Greetings jython-users list readers, I come in peace! (This is my first posting you know ;-) Very cool to layer python on top of java. I have a minor patch to suggest for jythonc that tripped me up some time, while simultaneously fooling around with the classpath (new to java). jythonc in it's current incarnation doesn't seem to handle long filenames too well, or actually it's kindof javac's fault. When compiling from a directory whose path consists of spaces javac trips up when it is fed the current directory in the classpath. The following quick and dirty fix makes it work fine on my machine: As you can see the only thing it does is enclose all the paths in the classpath with "" so that javac won't trip up on directory names that looks like this: h:\my documents\tools\python source From javac.py in tools: def fixClasspath(cpath): temp = [] for each in cpath: temp.append('"' + each + '"') return temp From the function definition compile <snip> # new: # Classpath: # 1. python.jythonc.classpath property # + # 2. java.class.path property # + # 3. sourcedir # + # 4. sys.path if cpath is None: sep = java.io.File.pathSeparator cpath = [] part = sys.registry.getProperty("python.jythonc.classpath") if part != None: cpath.extend(part.split(sep)) part = getClasspath() if part != None: cpath.extend(part.split(sep)) if sourcedir: cpath.append(sourcedir) cpath.extend(sys.path) cpath = fixClasspath(cpath) # fix by Syver Enstad 5. feb. 2001 cpath = sep.join(cpath) cmd.extend([cpathopt, cpath]) cmd.extend(files) print 'Compiling with args:', cmd |
From: Mats W. <ma...@la...> - 2001-02-06 18:06:36
|
I'm looking for a nice illustrative diagram of what Jython "does" - in other words, how this piece works together with a "normal" Java environment. I've a simplified Java sketch that goes like this (rendered very roughly into text form): Application: [[ .java sources ]] ==> (( javac compiler )) ==> [[ .class files ]] || || Java Libraries: [[ java classes: .jar files ]] <==> (( JVM )) || || Native Operating System How would I fold Jython, and Jythonc, into the same simplified terms (without getting wildly inaccurate): Or even better - does anyone know of an existing diagram that would make my efforts redundant? Thanks, Mats |
From: D-Man <ds...@ri...> - 2001-02-07 19:00:42
|
I don't have a diagram, but maybe an explanation will help: Jython is a collection of Java classes that work together. This collection of classes (found in jython.jar) can be used in several ways : as an interactive console, an interpreter for python code, and a library that Java classes can use . Since jython is written in Java, it requires a JVM to run. I think the 3 most common ways of using jython are as a python interpreter that can be run on any system with a working JVM, a bridge that allows an application to be written as a combination of Python and Java code, or as an embedded interpreter that will allow your Java application to be extended/customized by users via python code. If you simply use it as a python interpreter, you will not see much difference between CPython and Jython. The main difference is that CPython has several C libraries/extension modules you can access from the Python code and Jython can access any Java library. If you use it to combine Python and Java sources in a single application you will find that Jython allows your python code to access any Java objects and work with them as if they were Python objects. With a certain amount of care, your java code will be able to work with Python objects as if they are Java objects. (The care is that Python can do things that Java can't, and vice versa -- think of free standing functions or static data/methods) When you use jythonc, your python code in parsed, and then some Java code is generated. The generated Java code is little more than a class that makes method calls into the Jython interpreter/library to accomplish what you coded. It can also generate methods whose signatures match what a Java class would expect so that Java code can call the methods without realizing that the class was written in Python. In the simplest view, Jython is just a Java library written in Java that runs in a JVM. HTH, -D On Tue, Feb 06, 2001 at 11:06:26AM -0700, Mats Wichmann wrote: | | I'm looking for a nice illustrative diagram of what Jython | "does" - in other words, how this piece works together with | a "normal" Java environment. | | I've a simplified Java sketch that goes like this | (rendered very roughly into text form): | | | Application: | [[ .java sources ]] ==> (( javac compiler )) ==> [[ .class files ]] | || | || | Java Libraries: [[ java classes: .jar files ]] <==> (( JVM )) | || | || | Native Operating System | | | How would I fold Jython, and Jythonc, into the same | simplified terms (without getting wildly inaccurate): | | | Or even better - does anyone know of an existing diagram | that would make my efforts redundant? | | Thanks, | | Mats |
From: Mats W. <ma...@la...> - 2001-02-07 23:04:06
|
At 02:01 PM 02/07/2001 -0500, D-Man wrote: Thanks. I believe it will help a bit... but I'm still in need of producing a diagram and I guess the rule is that if you REALLY understand it yourself that is not so hard. Sigh. >In the simplest view, Jython is just a Java library written in Java<br> >that runs in a JVM. Yes, this is what my first-cut Jython picture shows... a class file (Jython) that runs in the JVM and calls on "standard" Java classes. What I hadn't worked out how to pictorially include was what happens when it's run as an interpreter...or what it would look like when Python modules are imported and called. Mats |
From: D-Man <ds...@ri...> - 2001-02-07 23:49:31
|
On Wed, Feb 07, 2001 at 04:03:36PM -0700, Mats Wichmann wrote: | At 02:01 PM 02/07/2001 -0500, D-Man wrote: | | Thanks. I believe it will help a bit... but I'm still in need You're welcome. | of producing a diagram and I guess the rule is that if you | REALLY understand it yourself that is not so hard. Sigh. | | >In the simplest view, Jython is just a Java library written in Java<br> | >that runs in a JVM. | | Yes, this is what my first-cut Jython picture shows... a class file | (Jython) that runs in the JVM and calls on "standard" Java classes. | What I hadn't worked out how to pictorially include was what happens | when it's run as an interpreter...or what it would look like when | Python modules are imported and called. | How do you have these Python modules? If you compiled them with jythonc --all --jar then they are java bytecodes in a jar file right next to the jython implementation's bytecodes. You would just need to include that jar in the classpath. This is good for distributing your code -- your users don't have to know anything except to have the jar in the classpath. If your Python modules are simply in *.py files, then you must include the directory they are in in the PYTHONPATH system property. I haven't dealt with this yet. If the python code is in the current directory you won't have any trouble. ex: $ jython ./myscript.py If you are embedding the interpreter in a java app, then it is up to you to find the python code (that your users have written) and feed it to the interpreter. -D |
From: <bc...@wo...> - 2001-02-07 17:16:16
|
[Syver Enstad] >Greetings jython-users list readers, I come in peace! (This is my first >posting you know ;-) Very cool to layer python on top of java. > >I have a minor patch to suggest for jythonc that tripped me up some time, >while simultaneously fooling around with the classpath (new to java). > >jythonc in it's current incarnation doesn't seem to handle long filenames >too well, or actually it's kindof javac's fault. When compiling from a >directory whose path consists of spaces javac trips up when it is fed the >current directory in the classpath. > >The following quick and dirty fix makes it work fine on my machine: >As you can see the only thing it does is enclose all the paths in the >classpath with "" so that javac won't trip up on directory names that looks >like this: Thanks for reporting this problem. A slightly different patch have been checked into CVS. regards, finn |