From: Jack A. <ef...@bi...> - 2001-01-19 03:14:33
|
Hi, I remember a mail to a jpython list last year asking if you could call python modules from jpython. For the case where the python module was written in python, then you need to port from python to jython. But if the python module is an "extension module" -- ie. is written in C (or has a C interface), then it's pretty hard. I'm between jobs at the moment and to keep my brain busy, I've prototyped 'cyphon', a jython module that allows you to call *native* python modules. To give you a use case: Jython 2.0alpha2 on java1.2 (JIT: NONE) Type "copyright", "credits" or "license" for more information. >>> import cyphon >>> string = cyphon.string >>> print string.find('abcde','d') 3 or more usefully: Jython 2.0alpha2 on java1.2 (JIT: NONE) Type "copyright", "credits" or "license" for more information. >>> import cyphon >>> cyphon.os.getenv('PATH') 'DEBUG;C:\\JYTHON' cyphon achieves this by using JNI to embed python in jython: import cyphon # dynamically loads python.dll string = cyphon.string # calls PyImport_ImportModule("string") Now, cyphon would be really useful for using python extension modules like MetaKit or wxPython (to name a couple of extensions that I have an interest in). The complications I forsee are: - inheriting from native python classes - passing callback jython functions to native python functions but I'm sure that these can be resolved. Anyway, having proved to myself that I can get this far, I've lost motivation to complete it. If there's a demand for cyphon, I may polish it up a bit or if anyone can tell me the most convenient way to publish it, let me know. (it's only a few source files) Jack. |
From: Brendan J S. <bre...@ct...> - 2001-01-19 04:46:13
|
Jack Andrews wrote: > Anyway, having proved to myself that I can get this far, I've lost > motivation to complete it. If there's a demand for cyphon, I may polish > it up a bit or if anyone can tell me the most convenient way to publish > it, let me know. (it's only a few source files) Put it on sourceforge as an opensource project. Anyone interested can be added as a developer or even a maintainer. Brendan Simon. |
From: Ype K. <yk...@xs...> - 2001-01-19 19:38:10
|
Jack, you wrote: (snip) >I'm between jobs at the moment and to keep my brain busy, I've >prototyped 'cyphon', a jython module that allows you to call *native* >python modules. To give you a use case: > > Jython 2.0alpha2 on java1.2 (JIT: NONE) > Type "copyright", "credits" or "license" for more information. > >>> import cyphon > >>> string = cyphon.string > >>> print string.find('abcde','d') > 3 > >or more usefully: > > Jython 2.0alpha2 on java1.2 (JIT: NONE) > Type "copyright", "credits" or "license" for more information. > >>> import cyphon > >>> cyphon.os.getenv('PATH') > 'DEBUG;C:\\JYTHON' > >cyphon achieves this by using JNI to embed python in jython: > import cyphon # dynamically loads python.dll > string = cyphon.string # calls PyImport_ImportModule("string") Sounds like you have doing the opposite of the java for python jpe project. python.dll: would this port to Unix? That is: is most of it written in python? Did you perform reflection on the types to get from jython to C? > >Now, cyphon would be really useful for using python extension modules >like MetaKit or wxPython (to name a couple of extensions that I have an >interest in). The complications I forsee are: > - inheriting from native python classes > - passing callback jython functions to native python functions >but I'm sure that these can be resolved. Some of this has probably been solved (or is being solved) in jpe. I have not seen the source for jpe yet. Thinking of it, cyphon might make an interesting alternative to jpe. >Anyway, having proved to myself that I can get this far, I've lost >motivation to complete it. If there's a demand for cyphon, I may polish >it up a bit or if anyone can tell me the most convenient way to publish >it, let me know. (it's only a few source files) I'm certainly interested in using it under Unix, but that will take work. Would anyone have an idea how much? You might ask Finn Buck to distribute the source as an experimental Jython module. Regards, Ype |
From: <bc...@wo...> - 2001-01-19 20:23:03
|
[Ype on the pairing of Jython and CPython through JNI] >You might ask Finn Buck to distribute the source as an experimental >Jython module. It would have to an *outstandingly* useful module before I will even consider adding JNI code to the core Jython distribution. Neither jnios nor jTkinter can ever fulfill the requirement for inclusion. OTOH if some basic support or hooks in jython could make the integration easier or more complete, it is certainly worth considering. regards, finn |
From: Robert W. B. <rb...@di...> - 2001-01-22 14:21:46
|
Freezing servlet applications have resulted in difficulty with the javaos module. The simple scenario is I need to use os.stat(file), but all frozen applications return the error: AttributeError: class 'org.python.modules.os' has no attribute 'stat' When using jythonc, i've tried: jythonc -a -j app.jar jyDispatch.py jythonc -a -j app.jar jyDispatch.py javaos os re string others... jythonc -c -j app.jar jyDispatch.py javaos etc.... jythonc -a -A c:\jython-2.0\lib\javaos -j app.jar jyDispatch.py os All result in the above AttributeError. I've assumed stat requires os + javaos- does it? How do I freeze an application so that I can use it? Which jythonc line above was closest? More on the servlet: I'm using Tomcat 3.2, Sun jdk 1.2.2, Win98 and Linux Context is jython and jython.jar + app.jar are in $TOMCAT_HOME/webapps/jython/WEB-INF/lib so that they can be *.war-ified easily. Thank you in advance for any suggestions. -Robert |
From: <bc...@wo...> - 2001-01-22 20:41:55
|
[Robert W. Bill] >Freezing servlet applications have resulted in difficulty with >the javaos module. The simple scenario is I need to use >os.stat(file), but all frozen applications return the error: > > AttributeError: class 'org.python.modules.os' has no attribute 'stat' > >When using jythonc, i've tried: > > jythonc -a -j app.jar jyDispatch.py > jythonc -a -j app.jar jyDispatch.py javaos os re string others... > jythonc -c -j app.jar jyDispatch.py javaos etc.... > jythonc -a -A c:\jython-2.0\lib\javaos -j app.jar jyDispatch.py os > >All result in the above AttributeError. > >I've assumed stat requires os + javaos- does it? Yes. >How do I freeze an application so that I can use it? When I just tried to freeze this little module I got an NPE: import os print os.stat This is an unintended sideeffect on a hack I added to satisfy site.py's use of the os module. It occur when sys.prefix is None which typically happens for frozen applications. Changing the module to: import sys sys.prefix = "." import os print os.stat and it runs as expected. I compiled the module with the simple: jythonc.bat -j app.jar -a app.py I'm not 100% sure this is the situation you are seeing, but please give it a try. regards, finn |
From: Elisabeth u. A. H. <e.h...@ed...> - 2001-01-23 02:08:46
|
> [Ype on the pairing of Jython and CPython through JNI] > I like this idea, too. However, I don't like the solution of loading python.dll and then having CPython do the work for the imported module. Instead, I propose a C-Java-brigde via JNI in both directions: For Jython as suggested. For the C-extension module providing wrappers for the functions declared in python.h that delegate the work back to Jython via JNI (using proxies for allocated objects). This should also solve the callback and subclassing problems. Regards, Andreas |
From: Joseph S. B. I. <jo...@ba...> - 2001-01-20 03:04:03
|
Hi, I'm trying to replace some installation shell scripts with jython scripts, but I'm getting stuck fairly early on. In particular, I need to implement a copy of files from one directory to another, but os.shutil.copytree appears to be unimplemented, as does os.execv (my fallback). Am I just doing something wrong, or are these functions really missing? And if so, how would you solve the problem of needing to copy a tree of files? Thanks much, - Joe |