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 setup.py develop
writing dependency_links to scripted.egg-info/dependency_links.txt
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'
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 http://bugs.jython.org/issue1112 for more information.
Installing scripted.py script to /Users/pjenvey/src/java/jython-trunk-
Processing dependencies for scripted==0.0dev
Finished processing dependencies for scripted==0.0dev
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
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. :(
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: http://www.nabble.com/Shebang-lines-on-