[Distutils] Shebang lines on Jython

Phillip J. Eby pje at telecommunity.com
Wed Apr 16 20:39:03 CEST 2008


At 11:00 AM 4/16/2008 -0700, Philip Jenvey wrote:
>Speaking of shebang lines, there's problems with setuptools shebang
>lines on Jython. Unfortunately it's going to require another patch or
>two to setuptools.
>
>The problem being that Jython's executable is a .sh or .bat file
>(that'll invoke java), and interpreters in shebang lines can't be
>interpreter files, i.e. another script. Running a .py script that
>shebangs the Jython .sh executable directly will result in something
>along the lines of a "test.py: line 2 import command not found" sh
>error.
>
>For posix, we'll just need to special case Jython on posix to make a
>shebang along the lines of:
>
>#!/usr/bin/env /opt/local/bin/jython
>
>Windows isn't as easy. setuptools' launcher.c similarly can't use
>a .bat file as the interpreter. A workaround would be to use cmd.exe /
>c in the same way we'll use /usr/bin/env on posix. launcher.c
>currently can't handle this, though, the problem being it can't
>correctly quote the cmd.exe /c line correctly.
>
>With:
>
>#!c:\windows\system32\cmd.exe /c c:\jython2.2\jython.bat
>
>launcher.c ends up calling:
>
>"c:\windows\system32\cmd.exe" "/c" "c:\jython2.2\jython.bat" "c:
>\scripts\myscript-script.py"
>
>when we need:
>
>"c:\windows\system32\cmd.exe" /c ""c:\jython2.2\jython.bat" "c:
>\scripts\myscript-script.py""
>
>which is another set of quotes around the entire /c arg, and yes no
>quotes around /c (I have no idea why "/c" doesn't work).
>
>I guess we would have to patch launcher.c to deal with this special
>situation or make a custom version for Jython. That's pretty awful --
>might anyone have a simpler way of handling this?

Make a jython.exe that either runs the batch file, or does the same 
things itself.  As you can see from launcher.c, it's not that hard to 
make one, and trivial to build it with the cygwin/MinGW tools.  And 
then make jython's sys.executable on Windows be that Jython.exe.

You can pretty much do the same thing for other platforms.  Yes, I 
know it means you'll have to compile something, but it beats the 
living tar out of trying to handle parameters and options in shebang 
lines.  Have a look at the chart on this page:

   http://www.in-ulm.de/~mascheck/various/shebang/

for some horror stories.



More information about the Distutils-SIG mailing list