Issue2872

classification
Title: -m option does not search modules from current directory
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7.2
Milestone: Jython 2.7.3
process
Status: open Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, rad164
Priority: normal Keywords:

Created on 2020-04-18.05:46:25 by rad164, last changed 2020-04-25.06:14:49 by jeff.allen.

Messages
msg13024 (view) Author: (rad164) Date: 2020-04-18.05:48:40
2.7.2 does not search modules in current directory when called with -m option.  These modules are loaded on jython console and '-c' option.

    $ ls mymodule/
    __init__.py  __main__.py
    $ java -jar /path/to/jython/jython-standalone-2.7.2.jar -c 'import mymodule'
    (no errors)
    $ java -jar /path/to/jython/jython-standalone-2.7.2.jar -m mymodule
    /path/to/jython/bin/jython: No module named mymodule


I found that when jython is called with -m, it does not have current directroy ('') unless explicitly specified with JYTHONPATH.

    $ pwd
    /home/user/jythontest
    $ java -jar /path/to/jython/jython-standalone-2.7.2.jar -c 'import sys; print(sys.path)'
    ['', '/path/to/jython/Lib', '/path/to/jython/jython-standalone-2.7.2.jar/Lib', '__classpath__', '__pyclasspath__/']

    $ java -jar /path/to/jython/jython-standalone-2.7.2.jar -m site
    sys.path = [
        '/path/to/jython/Lib',
        '/path/to/jython/jython-standalone-2.7.2.jar/Lib',
        '__classpath__',
        '__pyclasspath__/',
    ]
    USER_BASE: '/home/user/.local' (exists)
    USER_SITE: '/home/user/.local/lib/jython2.7/site-packages' (doesn't exist)
    ENABLE_USER_SITE: True

    $ JYTHONPATH="." java -jar /path/to/jython/jython-standalone-2.7.2.jar -m site
    sys.path = [
        '/home/user/jythontest',
        '/path/to/jython/Lib',
        '/path/to/jython/jython-standalone-2.7.2.jar/Lib',
        '__classpath__',
        '__pyclasspath__/',
    ]

On 2.7.1, `-m site` shows current directory as the first item of sys.path.

    $ java -jar /path/to/jython/jython-standalone-2.7.1.jar -m site
    sys.path = [
        '/home/user/jythontest',
        '/path/to/jython/Lib',
        '/path/to/jython/jython-standalone-2.7.1.jar/Lib',
        '__classpath__',
        '__pyclasspath__/',
    ]
msg13038 (view) Author: Jeff Allen (jeff.allen) Date: 2020-04-25.06:14:49
I confirm I can reproduce this using the standalone JAR, thanks.

It imported correctly with the jython command as:

jython -m mymodule.main

except that that the __file__ attribute of main is not set. It seems to  be finding it by an unorthodox route (__pyclasspath__). So I think it is a general problem, albeit masked in the command-line form,
History
Date User Action Args
2020-04-25 06:14:49jeff.allensetnosy: + jeff.allen
messages: + msg13038
priority: normal
components: + Core
milestone: Jython 2.7.3
resolution: accepted
2020-04-18 05:48:40rad164setmessages: + msg13024
2020-04-18 05:46:25rad164create