Message10063
I've made some decent progress with this, committed #2058 locally, and implemented the optional methods. I'm not entirely sure what to test for, as I have no reference semantics when using a ClasspathPyImporter directly. (There is no direct CPython counterpart.) The requirement as I see it is to work correctly with import, -m (runpy) and pkgutil (which runpy uses) so that's what my tests look like.
At the moment I can do this:
>jar tf rlib.jar
META-INF/
META-INF/MANIFEST.MF
data/
data/r.dat
data/__init__.py
>java -cp rlib.jar;dist\jython-dev.jar;dist\javalib\* org.python.util.jython
Jython 2.7.0+ (default:67f36ecd9103+, May 16 2015, 00:30:35)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, pkgutil
>>> from java.lang import System
>>> 'rlib.jar' in System.getProperty('java.class.path').split(';')
True
>>> i = pkgutil.get_importer('__pyclasspath__/')
>>> i.is_package('data')
True
>>> i.get_code('data')
<code object <module> at 0x2, file "__pyclasspath__/data/__init__.py", line 0>
>>> import data
Init data package
>>> i.get_data('data\\r.dat')
'some data'
>>> i.get_data('data\\r.dat')
''
That last bit is clearly wrong, and stems from re-using the cached InputStream from "entries". This puzzles me: why do we have that cache if it contains things we can only use once?
zipimporter avoids this by re-opening the entire archive and finding the resource again. I'll emulate that, and same for get_source. They could usefully share code, but it all seems a bit fragile to do in one step.
The entries cache is still there in zipimporter, and up it looks up modules in it, but then it doesn't use the result. I wonder if these open streams are behind the 100% unlink() failure I get from test_zipimporter?
It seems like a part of the code that could benefit from a cache, but not quite the one we have. My impression generally of Jython's import mechanism is that it contains some good stuff, but we lost our way. I can see that CPython wandered a long time before settling, so it's hardly surprising. It has to be revisited for Jy3 anyway: chance to re-think? |
|
Date |
User |
Action |
Args |
2015-05-16 10:01:53 | jeff.allen | set | messageid: <1431770513.77.0.556856329427.issue1879@psf.upfronthosting.co.za> |
2015-05-16 10:01:53 | jeff.allen | set | recipients:
+ jeff.allen, fwierzbicki, zyasoft, darjus, conflatedauto |
2015-05-16 10:01:53 | jeff.allen | link | issue1879 messages |
2015-05-16 10:01:51 | jeff.allen | create | |
|