[Python-Dev] Re: [Jython-dev] Using PyChecker in Jython

Samuele Pedroni Samuele Pedroni <pedroni@inf.ethz.ch>
Fri, 1 Jun 2001 16:18:20 +0200 (MET DST)


Hi.

[Neal Norwitz]
> Hello!
> 
> I have created a program PyChecker to perform Python source code checking.
> (http://pychecker.sourceforge.net).
> 
> PyChecker is implemented in C Python and does some "tricky" things.
> It doesn't currently work in Jython due to the module dis (disassemble code)
> not being available in Jython.
> 
> Is there any fundamental problem with getting PyChecker to work under Jython?
> 
> Here's a high-level overview of what PyChecker does:
> 
> 	imp.find_module()
> 	imp.load_module()
> 	for each object in dir(module): 
> 		# object can be a class, function, imported module, etc.
> 		for each instruction in disassembled byte code:
> 			# handle each instruction appropriately
> 
> This hides a lot of details, but I do lots of things like getting the code 
objects from the classes, methods, and
> functions, look at the arguments
> in functions, etc.
> 
> Is it possible to make work in Jython?  Easy?
> 
> Thanks for any guidance,
> Neal
It would be great - really - but about easy?

As easy as making PyChecker working on source code without using dis and without 
importing/executing modules and their top defs, I think there will be no
dis support on jython side (we produce java bytecode and getting "back"
to python vm bytecode would be very tricky, not very elegant, etc. ) any time
soon <wink>.

Seriously, two possible workaround hacks (they are also not very easy),

this is just after small brainstorming and ignoring the concrete needs
and code of PyChecker:

+) more elegant one, but maybe still too difficult or requiring too much work:

let PyChecker run under CPython even when checking jython code,
jython code can compile down to py vm bytecode but then does not run: why?

java classes imports and the jython specific builtin modules (not so many)

So one needs to implement a sufficient amount of python (an import hook, etc) 
code that does the minimal partial evalution required and the required amount of 
loading&introspection on java, jython specific stuff in order to have 
the imports work and PyChecher feeded with the things it needs.

This means dealing with the java class format, or a two passes approach:
run the code under jython in order to gather the information needed to load
it succesfully under python. If the top level code contains conditionals
that depend on jython stuff this could be hard, but one can ignore that 
(at least for starting). Clearly the main PyChecker loop would require
some adaptation, and maybe include some logic to check some jython specific
stuff (subclassing from java, etc).

*) let an adapted PyChecker run under jython, obtain someway the needed
py vm bytecode stream from a source -> py vm bytecode compiler written in python
(such a thing exists - if I remember well) .

And similar ideas ...

regards, Samuele Pedroni.