Issue1112

classification
Title: Shebang handlers must be compiled (sys.executable)
Type: crash Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, fwierzbicki, pjenvey, saper, zyasoft
Priority: low Keywords:

Created on 2008-08-28.00:42:55 by pjenvey, last changed 2015-03-12.00:40:21 by zyasoft.

Messages
msg3452 (view) Author: Philip Jenvey (pjenvey) Date: 2008-08-28.00:42:54
Jython's runner (sys.executable) is a .sh, or .bat file on Windows. On 
POSIX a .sh file cannot be used as a shebang line interpreter, meaning:

#!/path/to/jython

does not work

One partial workaround is to have distutils (and setuptools) change the 
interpreter to:

#!/usr/bin/env /path/to/jython

We're getting this workaround applied to both because it's dead simple 
and allows most scripts to work, but this solution has its own problem: 
it doesn't work when extra arguments to the interpreter are used. I.e. 
on various platforms (like Linux IIRC, and some others), this does not 
work:

#!/usr/bin/env /path/to/jython -S

There exists a similar issue on Windows for setuptools -- as setuptools 
installs scripts with an accompanying .exe file to facilitate easily 
running scripts on Windows as you would on POSIX. This helper .exe 
doesn't work for the same reason, because our sys.executable is a .bat.

The fullproof solution here is to make the runner a native executable on 
all platforms. This wouldn't be too bad to accomplish for Windows as we 
could just ship a precompiled .exe. 

However shipping pre-compiled executables for the various POSIX 
platforms would be a big pain. Having the Jython installer detect a 
compiler and compile one on the spot would also be a big pain, and 
basically creates a recommended dependency of a C compiler. We'd rather 
keep Jython's sole dependency the JRE.

JRuby and Groovy share this issue, though I've seen some JRuby tutorials 
recommend use of ruby's -S argument to run scripts, which totally avoids 
the issue. -S is a little like Python's -m but searches PATH instead of 
sys.path:

  -S              look for the script using PATH environment variable

MRI/YARV also have this option so it isn't too foreign to JRuby users.
msg3453 (view) Author: Philip Jenvey (pjenvey) Date: 2008-08-28.01:31:41
Related info:

discussion between PJE and I on this:

http://www.nabble.com/Shebang-lines-on-Jython-td16730414.html

workaround for setuptools:

http://bugs.python.org/setuptools/issue27
msg4578 (view) Author: Philip Jenvey (pjenvey) Date: 2009-04-23.06:14:04
On a related note I've noticed java.lang.Process seems to always return 0 
as the exitValue() when executing a .bat file. This ends up breaking our 
test_cmd_line, and any other test running sys.executable and expecting a 
non 0 return code
msg4766 (view) Author: Philip Jenvey (pjenvey) Date: 2009-05-31.03:20:34
The .bat file problem I mentioned above is now fixed, it was ticket #1352
msg4881 (view) Author: Philip Jenvey (pjenvey) Date: 2009-07-03.22:35:28
JRuby is also pondering the native executable solution. Groovy has one 
already:

http://groovy.codehaus.org/Native+Launcher
msg5252 (view) Author: Philip Jenvey (pjenvey) Date: 2009-10-21.20:05:56
Opened an issue for creating a native command line launcher for Windows in 
#1491
msg7057 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2012-04-14.19:41:35
Linux >=2.6.28 allows to use scripts as interpreters in shebangs.
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=bf2a9a39639b8b51377905397a5005f444e9a892
msg7061 (view) Author: Marcin Cieślak (saper) Date: 2012-04-15.20:22:52
here is a pretty nice reference to the whole #! problem:

http://www.in-ulm.de/~mascheck/various/shebang/
msg7845 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-27.18:05:19
Philip, can we close this and track #1491 for a final solution?
msg9630 (view) Author: Jim Baker (zyasoft) Date: 2015-03-11.23:45:36
Fixed as of https://hg.python.org/jython/rev/5d62f637a8d1, along with the fix for #1491
History
Date User Action Args
2015-03-12 00:40:21zyasoftsetstatus: closed
2015-03-11 23:45:36zyasoftsetstatus: open -> (no value)
resolution: remind -> fixed
messages: + msg9630
nosy: + zyasoft
2014-05-22 00:03:26zyasoftsetresolution: remind
2013-02-27 18:05:19fwierzbickisetmessages: + msg7845
2012-04-15 20:22:52sapersetnosy: + saper
messages: + msg7061
2012-04-14 19:41:35Arfreversetnosy: + Arfrever
messages: + msg7057
2009-10-21 20:05:56pjenveysetmessages: + msg5252
2009-07-03 22:35:29pjenveysetmessages: + msg4881
2009-05-31 03:20:35pjenveysetmessages: + msg4766
2009-04-23 06:14:55pjenveysetmessages: + msg4578
2009-03-03 18:33:34fwierzbickisetnosy: + fwierzbicki
2008-08-28 01:31:50pjenveysetmessages: + msg3453
2008-08-28 00:42:55pjenveycreate