# HG changeset patch # User Paul Boddie # Date 1106433267 -3600 # Node ID 1afe376ec3fdb4799821449e2401af449e3dba34 # Parent 9812fa1e481627293e4c239dfca9935532e29d9d Updated the documentation. diff -r 9812fa1e4816 -r 1afe376ec3fd README.txt --- a/README.txt Fri Jan 21 18:22:28 2005 +0100 +++ b/README.txt Sat Jan 22 23:34:27 2005 +0100 @@ -1,3 +1,21 @@ +This file contains some information on the essential concepts and principles +involved in the use of this software. + +Installation +------------ + +Usually, I issue this command first: + +python setup.py build + +The following should, in any case, be sufficient: + +python setup.py install + +I don't think distutils supports uninstall, but the installation just adds the +java and javaclass packages to your site-packages directory and the +runclass.py program to the same bin directory that python resides in. + Class Search Paths ------------------ @@ -26,17 +44,14 @@ Importing Classes ----------------- -The classhook.py import hook needs to be made available before imports from -Java classes and libraries (.jar files) can take place. This can be done -by either... +In Python, the following statement should be enough to enable Java class +import: - * Running the classhook.py file directly and then using the interactive - interpreter: + import javaclass.classhook - python -i classhook.py - - * Putting classhook.py in sys.path or PYTHONPATH and importing the - classhook module before any code importing Java classes and packages. +(Other modules reside in the javaclass package, so it is possible to access +them without changing Python's import mechanisms, should such modification be +undesirable or unnecessary.) Importing Non-package Classes ----------------------------- @@ -65,23 +80,12 @@ tests directory would be run as follows: cd tests - python ../runclass.py MainTest hello world - - If runclass.py is executable and on the PATH, then the following can be - used instead: - - cd tests runclass.py MainTest hello world * Classes residing in packages can be run by ensuring that the packages are registered on the PYTHONPATH (see "Class Search Paths" above). Then, the testpackage.MainTest class (for example) would be run as follows: - python runclass.py testpackage.MainTest hello world - - If runclass.py is executable and on the PATH, then the following can be - used instead: - runclass.py testpackage.MainTest hello world Accessing Python Libraries from Java @@ -95,30 +99,32 @@ 1. Compile the skeleton classes: - javac examples/Qt/qtjava/QWidget.java + javac examples/Tkinter/tkjava/*.java 2. Compile the Java classes which use the wrapped Python libraries: - javac -classpath examples/Qt examples/Qt/WidgetTest.java + javac -classpath examples/Tkinter examples/Tkinter/Application.java 3. Run the wrap.py tool on the directory where the skeleton class files reside, providing the name of the Python package or module being wrapped. This converts the directory into a Python package: - PYTHONPATH=. python tools/wrap.py examples/Qt/qtjava qt + python tools/wrap.py examples/Tkinter/tkjava Tkinter - Since the Java class files, if left in the processed directory, would - be detected and imported using the classhook.py import hook, and since - this would result in two conflicting implementations being imported - (with possibly the non-functional Java classes being made available - instead of the generated wrapper classes), the wrap.py tool removes all - processed class files, leaving only Python source files in the - processed directory. + Since the Java class files, if left in the processed directory, would be + detected and imported using the special import hook, and since this would + result in two conflicting implementations being imported (with possibly the + non-functional Java classes being made available instead of the generated + wrapper classes), the wrap.py tool removes all processed class files, + leaving only Python source files in the processed directory. 4. The Java classes which use the wrapped Python libraries can now be - imported and used as described above. The wrapper package (qtjava in + imported and used as described above. The wrapper package (tkjava in the above example) needs to reside in sys.path or PYTHONPATH, as must - the wrapped library (qt in the above example). + the wrapped library (Tkinter in the above example). + + cd examples/Tkinter + runclass.py Application Issues ------ diff -r 9812fa1e4816 -r 1afe376ec3fd docs/index.html --- a/docs/index.html Fri Jan 21 18:22:28 2005 +0100 +++ b/docs/index.html Sat Jan 22 23:34:27 2005 +0100 @@ -15,7 +15,10 @@ into Python, without the need for a Java virtual machine, so that the classes may be instantiated, accessed, run and manipulated just like Python classes, and that the resulting objects and methods can be accessed and manipulated -just like Python objects and methods.

+just like Python objects and methods. It should be possible to run compiled +Java programs with the Python interpreter and not notice that it isn't the +Java virtual machine being used - given sufficient library support for the +program concerned, of course.

Quick Examples

@@ -97,20 +100,26 @@

20050401

+

Getting Started

+ +

See the README.txt file in the distribution directory.

+

Motivation

Pick one of the following:

Limitations

@@ -129,7 +138,69 @@ files (and .jar archives). Generally, anyone who is anyone in the Python pantheon has largely recommended against doing anything with the bytecode, despite noble efforts to make exciting things happen by - transforming it, optimising it, and so on - + transforming it, optimising it, and so on. (Instead, there's been more + emphasis on lots of runtime baggage for things which could be done by + analysis of the code with modified bytecode being produced as a result, + and let's not get started on some of the syntactical enhancements.) + Consequently, stability might be an issue for some configurations, + especially since CPython doesn't fail particularly graciously with badly + behaved bytecode. +
  • Some of the translation from Java to Python bytecode takes a few + liberties. For example, Java exceptions are handled in ways reminiscent + of a 1980s microcomputer assembly language, whereas Python bytecode has + higher level constructs for exceptions; this translation can probably be + done incorrectly, triggering some kind of bytecode misbehaviour, and we + all know what happens then.
  • +
  • At the Python level, not all things seem totally right. For example, + Java bytecode instructions are used to instantiate and then initialise + exceptions just like other objects, and while Python can support this + with new-style objects, Python won't let you use new-style objects as + exceptions. Consequently, when Java exceptions appear in Python programs, + they will be wrapped in old-style exceptions and have to be handled + specially.
  • +
  • In order to support method dispatch properly, special names are used + for the translated methods which include the type information found in + the bytecode; things like main___java__lang__String_array_ + and setValue____I_ appear when you look inside classes and + objects. When implementing libraries in Python for Java programs, such + method naming conventions have to be used because the original code is + very specific about which method is being invoked, and for specialised + versions of __init__ it becomes necessary to do a + setattr to add such methods into classes because of various + "name mangling" measures in the Python compilation process. Now, many + people might start advocating decorators at this point, but not everyone + is running the very latest stuff from python.org, and decorators won't + help you target a specific specialised method anyway.
  • +
  • Imported and translated bytecode is not written out or cached. This + means that a fair amount of work happens every time you need to import + Java classes, although the generation of .pyc files could be introduced + provided that it captured the slightly different import semantics of + Java; for example, you can import classes belonging to a package from + several places on the PYTHONPATH, and this is something that generally + isn't allowed/supported with the classic Python module import + mechanisms.
  • + + +

    Suggestions for Python Improvements

    +