The bug tracker for setuptools 0.7 or higher is on BitBucket



Title [PATCH] Fix shebang lines for Jython on POSIX
Priority critical Status resolved
Superseder Nosy List pje, pjenvey
Assigned To Keywords

Created on 2008-07-16.00:33:39 by pjenvey, last changed 2008-09-24.16:45:12 by pje.

File name Uploaded Type Edit Remove
jython-shebang-fix3_r65963.diff pjenvey, 2008-08-28.01:17:08 text/plain
jython-shebang-fix_r61342.diff pjenvey, 2008-07-16.00:33:39 text/plain
msg178 (view) Author: pje Date: 2008-09-24.16:45:11
Fixed in trunk and branch.
msg147 (view) Author: pjenvey Date: 2008-08-28.01:17:08
woops, -fix2 was an old version. we want -fix3
msg146 (view) Author: pjenvey Date: 2008-08-28.01:04:44
Here's a new patch that doesn't apply the workaround when there's arguments 
(whether those arguments were in the script, or due to the fact that there's non 
ascii chars involved, requiring -x) and emits a warning message about it to 

With some tests

The warning ends up looking like:

$ jython develop
running develop
running egg_info
writing dependency_links to scripted.egg-info/dependency_links.txt
writing scripted.egg-info/PKG-INFO
writing top-level names to scripted.egg-info/top_level.txt
writing entry points to scripted.egg-info/entry_points.txt
reading manifest file 'scripted.egg-info/SOURCES.txt'
writing manifest file 'scripted.egg-info/SOURCES.txt'
running build_ext
Creating /Users/pjenvey/src/java/jython-trunk-clean3/jython-trunk-
clean3/Lib/site-packages/scripted.egg-link (link to .)
scripted 0.0dev is already the active version in easy-install.pth
WARNING: Unable to adapt shebang line for Jython, the following script is NOT 
         see for more information.
Installing script to /Users/pjenvey/src/java/jython-trunk-

Installed /Users/pjenvey/src/python/scripted
Processing dependencies for scripted==0.0dev
Finished processing dependencies for scripted==0.0dev
msg119 (view) Author: pjenvey Date: 2008-08-21.22:56:24
We briefly discussed this on the distutils-sig thread. I know this is a hack -- 
but the alternatives are especially sucky for us.

Building a customized Jython exe for the many platforms out there would be a big 
pain. We don't even have the time and resources for making a custom Windows exe 
for the 2.5 release (my guess is we won't get it until at least 2.5.1 =[ )

Otherwise the thought of our installer detecting a compiler and compiling one on 
the spot makes me want to cry. Requiring a C compiler for such an integral usage 
of Jython kills one of our platform's main features: easily ran anywhere, all 
you need is a JRE.

What if I made the patch emit a big warning and not apply the hack if extra 
arguments are detected? That way the majority of scripts work and those that are 
incompatible with the hack at least fail in a less mysterious fashion. This 
would be a huge improvement over the current situation and a big win for the 
Jython 2.5 release.

Plus the patch is future proof; if we start providing native sys.executable's in 
the future, setuptools would adapt since it looks for the shebang line magic.

Please consider compromising on correctness here. The work required to do this 
right for every platform is such a multitude more than this fix
msg106 (view) Author: pje Date: 2008-08-21.19:38:25
This patch is broken when there are options supplied on the #! line, for
operating systems that don't support multiple options to a #! interpreter.

More specifically, if the original script does e.g. "#!/usr/bin/jython -S",
changing it to "#!/usr/bin/env /usr/bin/jython -S" will cause 'env' to see two
arguments: "/usr/bin/jython -S", and the original script name.  This will not
work, since "/usr/bin/jython -S" is not a filename.

Note too that this means the -x hack for skipping the unicode stuff isn't going
to work either.

I don't know what to suggest, but for the greatest compatibility with existing
scripts and platforms, I think Jython is going to have to include a
platform-specific launcher for sys.executable, and not just on Windows.  :(
msg60 (view) Author: pjenvey Date: 2008-07-16.00:33:39
Jython's sys.executable is a shell script on POSIX (and .bat on Windows) and 
thus can't be used as a shebang line interpreter.

The following patch works around this by calling sys.executable via /usr/bin/env 
in shebang lines on platforms where sys.platform.startswith('java') and 
sys.executable's MAGIC is '#!'.

Jython on Windows is a separate issue -- Jython probably has to ship a .exe to 
solve the problem there. This fix doesn't apply to Windows because 
sys.executable's MAGIC is not '#!' there.

Marking as a higher priority because installed scripts on Jython aren't 
executable without this fix

Original distutils-sig discussion:
Date User Action Args
2008-09-24 16:45:12pjesetstatus: chatting -> resolved
messages: + msg178
2008-08-28 01:17:20pjenveysetfiles: - jython-shebang-fix2_r65963.diff
2008-08-28 01:17:08pjenveysetfiles: + jython-shebang-fix3_r65963.diff
messages: + msg147
2008-08-28 01:04:44pjenveysetfiles: + jython-shebang-fix2_r65963.diff
messages: + msg146
2008-08-21 22:56:25pjenveysetmessages: + msg119
2008-08-21 19:38:25pjesetstatus: unread -> chatting
nosy: + pje
messages: + msg106
2008-07-16 00:33:39pjenveycreate