From: Oti <oh...@gm...> - 2007-11-29 20:08:20
|
Hi all, hopefully a bit of background information can shed a light on this The prepending of '.' in sys.path was removed here: http://jython.svn.sourceforge.net/viewvc/jython?view=rev&revision=3109 referring to this bug: http://sourceforge.net/tracker/index.php?func=detail&aid=1599012&group_id=12867&atid=112867 I'd go with David, saying you can add the current directory if you really need to: sys.path.insert(0, os.getcwd()) Best wishes, Oti. On Nov 29, 2007 7:33 PM, <Mar...@am...> wrote: > > I found the difference. In Jython 2.1, inside PySystemState#initPath, it > looks like this: > > private static PyList initPath(Properties props) { > PyList path = new PyList(); > if (!Py.frozen) { > addPaths(path, props.getProperty("python.prepath", ".")); > > Whereas in Jython 2.2. it looks like this: > > PyList path = new PyList(); > if (!Py.frozen) { > addPaths(path, props.getProperty("python.prepath", "")); > > I'm assuming that the default value of an empty string (in the Jython 2.2 > code) does not get stuck onto the path because the tokenizing of an empty > string does nothing. I'm thinking this is probably a bug. > > Mark. > ---------------------------------------------------------- > > > > > > Mar...@am... > Sent by: jyt...@li... > > 11/29/2007 01:26 PM > > To David Niergarth <dn...@hd...> > > cc David Handy <Dav...@sa...>, "jyt...@li..." > <jyt...@li...> > > Subject Re: [Jython-users] Current Directory No Longer on sys.path? > > > > > > > > > David Handy wrote: > > > Yes, it looks like in Jython 2.1, the current directory was put in as > > > the second item sys.path. It also looks like CPython 2.4 put the > current > > > directory as the 3rd item in sys.path. > > > > I see it as the second item in CPython 2.4. In CPython 2.4.4, it > > doesn't appear > > at all so the change must have happened somewhere in the development > > of the 2.4 > > series. I didn't realize the current directory was being added explicitly > in > > earlier versions; it seems redundant with '' (read on). > > > > That's the thing - I don't have '' in my sys.path. However, I should have > mentioned my use case. I am embedding an interpreter in Eclipse, not > running Jython from the command line. So I just ran Jython 2.2 from the > command line and I see now that there is in fact a '' at the beginning. > (Weird. I didn't know that '' was the equivalent of '.' - is this specific > to Jython, or is it some generally accepted convention I was not aware of)? > So, this prompted me to look into why there was no '' element in my embedded > interpreter. I pretty quickly found that the full path to a script passed > on the command line or '' is inserted by the class org.python.util.jython > (as confirmed by David's latest email) like so: > > // was there a filename on the command line? > if (opts.filename != null) { > String path = new java.io.File(opts.filename).getParent(); > if (path == null) > path = ""; > Py.getSystemState().path.insert(0, new PyString(path)); > . > . > else { > // if there was no file name on the command line, then "" is > // the first element on sys.path. This is here because if > // there /was/ a filename on the c.l., and say the -i option > // was given, sys.path[0] will have gotten filled in with the > // dir of the argument filename. > Py.getSystemState().path.insert(0, new PyString("")); > . > . > > > OK...I am not sure I follow the second comment here, but it appears then > that to maintain this behaviour I will need to manually insert either '' or > '.' into my sys.path in Jython 2.2 (if I am creating/embedding my own > interpreter). However, that still does not answer the question as to why I > was seeing '.' in my sys.path before - when I am fairly certain I did not > place it there (see below). > > > > > But CPython 2.5.1 does not put > > > the current directory in sys.path at all. Nor does Jython 2.2. > > > > Yes, but in all cases (python 2.1 thru 2.5 and jython 2.2), the first > item in > > sys.path is '', which I always took to be the equivalent of '.' in the > shell. > > Here's verification: > > > > (%:~/tmp)- cat > test.py > > x = 1 > > y = 2 > > > > (%:~/tmp)- jython > > Jython 2.2.1 on java1.6.0_03 > > Type "copyright", "credits" or "license" for more information. > > >>> import sys > > >>> sys.path > > ['', '/home/dn/apps/jython2.2.1/Lib', '__classpath__'] > > >>> sys.path.pop(0) > > '' > > >>> sys.path > > ['/home/dn/apps/jython2.2.1/Lib', '__classpath__'] > > >>> import mytest > > Traceback (innermost last): > > File "<console>", line 1, in ? > > ImportError: no module named mytest > > >>> sys.path.insert(0, '') > > >>> sys.path > > ['', '/home/dn/apps/jython2.2.1/Lib', '__classpath__'] > > >>> import mytest > > >>> mytest.x, mytest.y > > (1, 2) > > > > > > Mar...@am... wrote: > > > Sure enough, if it check out sys.path in our Jython 2.1-based > > > product, the first entry in sys.path is ".", but it is not there > > > in our Jython 2.2-based product. > > > > In any case, this doesn't seem to address Mark's problem. I don't see '.' > in > > sys.path for any version of python or jython. Are you talking about > importing > > jython modules from jython or something else? And I do seem to be able to > > import jython modules from the current directory with jython 2.2. > > > > Well, this is the odd part. I am quite certain I did not put '.' on my > sys.path in Jython 2.1, but it is there - both in a command line console app > we have (that also creates an embedded interpreter), as well as in my > embedded Eclipse interpreter. Here is my command line app: > > >>> import sys > >>> sys.path > ['.', > 'C:\\PROGRA~1\\AMIS\\SIGNAK~1\\eclipse\\plugins\\com.amis.jython_2.1.0.v20070712\\Lib', > 'C:\\PROGRA~1\\AMIS\\SIGNAK~1\\\\scripts', 'C:\\Documents and > Settings\\Paul\\scripts'] > > In this case, I am calling Jython via java with > -Dpython.path=%EDK_HOME%\scripts;%HOMEDRIVE%%HOMEPATH%\scripts. I can see > these items as the last two items in sys.path, but something is sticking the > first two items in there. I assume the Lib dir is coming from my setting of > python.home, but I don't know where '.' is coming from. > > > And my Eclipse-based interpreter: > > >>>import sys > >>>sys.path > ['C:\\Documents and Settings\\Paul\\workspace\\Test\\scripts', '.', > 'C:\\Program Files\\AMIS\\SignaKlara Tools > 4\\eclipse\\plugins\\com.amis.jython_2.1.0.v20070712\\Lib', 'C:\\Documents > and Settings\\Paul\\scripts', 'C:\\Program Files\\AMIS\\SignaKlara Tools > 4\\scripts'] > > This looks right because I am inserting the first element manually, and the > rest matches the behvaiour I see in my command line console (well...aside > from the order - I need to fix that). Both of these cases simply create and > embed an InteractiveConsole. I am not sure where the '.' is coming from > however. I guess I'll go back in time in our CVS tree and try to see if > Jython 2.1 is doing this somewhere. The only difference I see right now in > how I initialize Jython is that I do a > PySystemState.initialize(System.getProperties()...), whereas the jython > command line class initializes it like > PySystemState.initialize(PySystemState.getBaseProperties(),...). > > Thanks for the responses. > Mark. > > AMI Semiconductor - "Silicon Solutions for the Real World" > NOTICE: > This electronic message contains information that may be confidential or > privileged. The information is intended for the use of the individual or > entity named above. If you are not the intended recipient, please be aware > that any disclosure, copying, distribution or use of the contents of this > information is prohibited. If you received this electronic message in error, > please notify the sender and delete the copy you received. > > ------------------------------------------------------------------------- > SF.Net email is sponsored by: The Future of Linux Business White Paper > from Novell. From the desktop to the data center, Linux is going > mainstream. Let it simplify your IT future. > > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4_______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > > > AMI Semiconductor - "Silicon Solutions for the Real World" > NOTICE: > This electronic message contains information that may be confidential or > privileged. The information is intended for the use of the individual or > entity named above. If you are not the intended recipient, please be aware > that any disclosure, copying, distribution or use of the contents of this > information is prohibited. If you received this electronic message in error, > please notify the sender and delete the copy you received. > > > ------------------------------------------------------------------------- > SF.Net email is sponsored by: The Future of Linux Business White Paper > from Novell. From the desktop to the data center, Linux is going > mainstream. Let it simplify your IT future. > http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > > |