Issue1719528

classification
Title: -c doesn't put the empty string in sys.path
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, davidhandy
Priority: normal Keywords:

Created on 2007-05-15.19:16:24 by davidhandy, last changed 2007-07-07.23:39:20 by cgroves.

Messages
msg1599 (view) Author: David R. Handy (davidhandy) Date: 2007-05-15.19:16:24
Importing a package via the -c command-line option is not working for me in Jython 2.2b2. It does work from an interactive session and from a script. I am using the version of Jython installed by the official installer on Windows.

Example session in Command Prompt window:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\davhan>mkdir C:\temp2

C:\Documents and Settings\davhan>cd C:\temp2

C:\temp2>mkdir p1

C:\temp2>copy nul p1\__init__.py
        1 file(s) copied.

C:\temp2>jython
Jython 2.2b2 on java1.4.2_05
Type "copyright", "credits" or "license" for more information.
>>> import p1
>>> p1.__file__
'C:\\temp2\\p1\\__init__.py'
>>> ^Z


C:\temp2>jython -c "import p1"
Traceback (innermost last):
  File "<string>", line 1, in ?
ImportError: no module named p1

C:\temp2>

msg1600 (view) Author: David R. Handy (davidhandy) Date: 2007-05-15.20:28:04
A simpler way to describe the problem is that running Jython 2.2b2 with the -c option doesn't put an empty string (representing the current directory) in sys.path like it used to do.

C:\temp2>jython -c "import sys; print sys.path"
['C:\\home\\davhan\\tools\\jython2.2b2\\Lib', 'C:\\home\\davhan\\lib\\python', '
__classpath__', 'C:\\home\\davhan\\tools\\jython2.2b2']

C:\temp2>jython
Jython 2.2b2 on java1.4.2_05
Type "copyright", "credits" or "license" for more information.
>>> import sys; print sys.path
['', 'C:\\home\\davhan\\tools\\jython2.2b2\\Lib', 'C:\\home\\davhan\\lib\\python
', '__classpath__', 'C:\\home\\davhan\\tools\\jython2.2b2']
>>>
msg1601 (view) Author: David R. Handy (davidhandy) Date: 2007-06-26.14:26:33
This has a simple, one-line fix in jython.java which I have tested and have been using for weeks. I'll attempt to post my fix as an official "patch". I'm hope that the fix gets into Jython 2.2 soon.
msg1602 (view) Author: David R. Handy (davidhandy) Date: 2007-06-26.14:42:38
I posted patch 1743594 containing the fix.
msg1603 (view) Author: Charlie Groves (cgroves) Date: 2007-07-07.23:39:20
Fixed in r3284.  We were actually already adding "" to sys.path for the interactive interpreter right below your patch, so I just moved the exec of the command string to right after that.  That has the benefit of not adding '' twice if you use jython -i -c.  The patch definitely pointed me in the right direction though, so thanks for submitting it!
History
Date User Action Args
2007-05-15 19:16:24davidhandycreate