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
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.

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/
    $ 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
    $ 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 = [
    USER_BASE: '/home/user/.local' (exists)
    USER_SITE: '/home/user/.local/lib/jython2.7/site-packages' (doesn't exist)

    $ JYTHONPATH="." java -jar /path/to/jython/jython-standalone-2.7.2.jar -m site
    sys.path = [

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 = [
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,
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