Differences between revisions 1 and 11 (spanning 10 versions)
Revision 1 as of 2006-11-16 15:22:00
Size: 1697
Comment:
Revision 11 as of 2007-01-04 17:51:02
Size: 2911
Editor: PaulDrummond
Comment: Questions (half!) answered
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Porting an existing Python module written in C into Java that Jython understands is a pretty straightforward task so it can serve as a good introduction to the Jython codebase. I'm going to explain how I'd go about porting the [http://www.python.org/doc/2.3.5/lib/module-csv.html csv] module here. Porting an existing Python module written in C into Java that Jython understands is a pretty straightforward task so it can serve as a good introduction to the Jython codebase. I'm going to explain how to go about porting the [http://www.python.org/doc/2.3.5/lib/module-csv.html csv] module here.
Line 5: Line 5:
# Declare your intention to implement the csv module on the Jython dev list so no one else starts working on it.
# Add a new class org.python.modules._csv.java in src.
# Add "_csv" to the builtinModules array in org.python.modules.Setup
# Run Lib/test/test_csv.py. Everything will fail since none of the csv methods are implemented yet. Now pick one of the simpler tests and start adding methods to csv to get it to work. _csv.java will be an implementation of the stuff in _csv.c from Python. All of csv_methods from _csv.c needs to be implemented as static methods in _csv.java. You can get an idea of how it's done from _codecs.java and _codecs.c or any of the module implementations in org.python.modules and their corresponding C implementation. As you add the methods to _csv.java, Jython will pick up on them and parts of the tests will start working.
# Keep adding pieces to _csv.java till the tests pass
# Submit a patch to the [http://www.jython.org/patches tracker].
# Revel in the glory of another implemented module
 1. Declare your intention to implement the csv module on the Jython dev list so no one else starts working on it.
 1. Add a new class org.python.modules._csv.java in src to mirror _csv.c from CPython.
 1. Add "_csv" to the builtinModules array in org.python.modules.Setup
 1. Run dist/Lib/test/test_csv.py. Everything will fail since none of the csv methods are implemented yet. Now pick one of the simpler tests and start adding methods to csv to get it to work. _csv.java will be an implementation of the stuff in _csv.c from Python. All of csv_methods from _csv.c needs to be implemented as static methods in _csv.java. You can get an idea of how it's done from _codecs.java and _codecs.c or any of the module implementations in org.python.modules and their corresponding C implementation. As you add the methods to _csv.java, Jython will pick up on them and parts of the tests will start working.
 1. Keep adding pieces to _csv.java till the tests pass
 1. Submit a patch to the [http://www.jython.org/patches tracker].
 1. Revel in the glory of another implemented module
Line 13: Line 13:
No one has taken csv yet, so it's available as a starting point. If you're not interested in comma separated values, run regrtest.py as described in the JythonDeveloperGuide. All of the skipped modules are unimplemented in Jython. Pick one of them and substitute its name for csv in the directions above. The table below contains modules implemented in C in Python that are missing in Jython. Feel free to grab one of them and get started. If none of them catch your fancy, run dist/Lib/test/regrtest.py. All of the skipped tests are for modules that are present in CPython but not in Jython, so they're fair game too. See the "Missing Modules" section of ../RegressionTestNotes for a list as of 20061123.

||Module||Difficulty||Desirability||Taken||
||csv||**||**||Y||
||math||**||***||N||
||select||****||****||N||
||tarfile||****||***||N||
||unicodedata||***||****||N||

== Comments ==
'''Why have you called the Java file _csv.java instead of just csv.java? Is there a convention here and if so, why don't all the classes follow the same convention.'''

''pdrummond'': Short answer: It's called `_csv` because that is what it's called in CPython!

Long answer: Hmmm. Will have to swat up on CPython's module naming conventions to answer this properly! I think CPython's general convention is "`<name>module.c`" so `csv` really should be "`csvmodule.c`" shouldn't it? I guess the underscore is necessary because there is a `csv.py` wrapper so the "csv" name is already taken, but I need to check this to be sure!

'''Will the `test_cvs.py` file automatically appear after a build or do we have to implement this ourself?'''

''pdrummond'': `test_csv.py` will appear auto-magically after a build in `dist/Lib/test` and it is a CPython test script.

CharlieGroves, incept: 2006-11-16

Porting an existing Python module written in C into Java that Jython understands is a pretty straightforward task so it can serve as a good introduction to the Jython codebase. I'm going to explain how to go about porting the [http://www.python.org/doc/2.3.5/lib/module-csv.html csv] module here.

  1. Declare your intention to implement the csv module on the Jython dev list so no one else starts working on it.
  2. Add a new class org.python.modules._csv.java in src to mirror _csv.c from CPython.
  3. Add "_csv" to the builtinModules array in org.python.modules.Setup
  4. Run dist/Lib/test/test_csv.py. Everything will fail since none of the csv methods are implemented yet. Now pick one of the simpler tests and start adding methods to csv to get it to work. _csv.java will be an implementation of the stuff in _csv.c from Python. All of csv_methods from _csv.c needs to be implemented as static methods in _csv.java. You can get an idea of how it's done from _codecs.java and _codecs.c or any of the module implementations in org.python.modules and their corresponding C implementation. As you add the methods to _csv.java, Jython will pick up on them and parts of the tests will start working.
  5. Keep adding pieces to _csv.java till the tests pass
  6. Submit a patch to the [http://www.jython.org/patches tracker].

  7. Revel in the glory of another implemented module

The table below contains modules implemented in C in Python that are missing in Jython. Feel free to grab one of them and get started. If none of them catch your fancy, run dist/Lib/test/regrtest.py. All of the skipped tests are for modules that are present in CPython but not in Jython, so they're fair game too. See the "Missing Modules" section of ../RegressionTestNotes for a list as of 20061123.

Module

Difficulty

Desirability

Taken

csv

**

**

Y

math

**

***

N

select

****

****

N

tarfile

****

***

N

unicodedata

***

****

N

Comments

Why have you called the Java file _csv.java instead of just csv.java? Is there a convention here and if so, why don't all the classes follow the same convention.

pdrummond: Short answer: It's called _csv because that is what it's called in CPython!

Long answer: Hmmm. Will have to swat up on CPython's module naming conventions to answer this properly! I think CPython's general convention is "<name>module.c" so csv really should be "csvmodule.c" shouldn't it? I guess the underscore is necessary because there is a csv.py wrapper so the "csv" name is already taken, but I need to check this to be sure!

Will the test_cvs.py file automatically appear after a build or do we have to implement this ourself?

pdrummond: test_csv.py will appear auto-magically after a build in dist/Lib/test and it is a CPython test script.

JythonDeveloperGuide/PortingPythonModulesToJython (last edited 2008-11-15 09:15:58 by localhost)