From: <Mat...@i2...> - 2002-01-23 20:53:15
|
Shouldn't the following be equivalent? I can't seem to get the jreload version to work. start jython with some.jar in cp, then: from org import somepackage OR start jython with no classpath: import jreload ls = jreload.makeLoadSet('myls', ["/path/to/some.jar"]) from myls import org from org import somepackage ImportError: cannot import name somepackage The goal here is to have a script be able to use the same import lines, regardless of wether its being called from the command line using the correct classpath, or from another script which sets up its classpath/namespace via jreload. Matt |
From: Samuele P. <ped...@bl...> - 2002-01-24 20:51:25
|
Hi. > Shouldn't the following be equivalent? I can't seem to get the jreload > version to work. No they are not equivalent. So the error you get is not a bug, although I see what you want to achieve so see below. > start jython with some.jar in cp, then: > > from org import somepackage if I do: import org org2 = org from org2 import somepackage it fails, same story below. > OR start jython with no classpath: > > import jreload > ls = jreload.makeLoadSet('myls', ["/path/to/some.jar"]) > from myls import org > from org import somepackage > ImportError: cannot import name somepackage from p.k.g import something p.k.g referes to the packages namespace, nothing to do with the current local/global scope. from myls.org import somepackage works but - I know - is not what you want. If you know a point in the package hierarchy in your jar that is disjunct from the hiearchy on classpath and sys.path (NB typically org is not such a point <wink>), e.g. org.iMnotToBeFoundAlongClassPathAndSysPath org.empire.iMjustInTheJar you can do the following: import sys import jreload ls = jreload.makeLoadSet('someJarLS', ["/path/to/some.jar"]) sys.modules['org.iMnotToBeFoundAlongClassPathAndSysPath']=ls.org.iMnotToBeFound AlongClassPathAndSysPath sys.modules['org.empire.iMjustInTheJar']=ls.org.empire.iMjustInTheJar then from org.empire.iMjustInTheJar import somepackage from org.iMnotToBeFoundAlongClassPathAndSysPath import somepackage will work but from org import iMnotToBeFoundAlongClassPathAndSysPath will not. Btw if you play the trick with a point not disjunct, you will get some major troubles. [Yup it is a hack, but the limitations of jreload come from the fact that it allows reloading, sys.path and classpath don't.] regards, Samuele Pedroni. |