diff options
author | phillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771> | 2008-09-24 16:42:20 +0000 |
---|---|---|
committer | phillip.eby <phillip.eby@6015fed2-1504-0410-9fe1-9d1591cc4771> | 2008-09-24 16:42:20 +0000 |
commit | 516654d05cd391a37ea1f696da66a8b247af90c5 (patch) | |
tree | d17f456c229f16fc7768c23e0941498231e2cada /setuptools/command | |
parent | b76269a6866c5b47ec72b837a27ae0d1ef65d1ea (diff) | |
download | python-setuptools-516654d05cd391a37ea1f696da66a8b247af90c5.tar.gz |
Fix for http://bugs.python.org/setuptools/issue27 (Jython shebang
lines)
git-svn-id: http://svn.python.org/projects/sandbox/trunk/setuptools@66596 6015fed2-1504-0410-9fe1-9d1591cc4771
Diffstat (limited to 'setuptools/command')
-rwxr-xr-x | setuptools/command/easy_install.py | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 48fdc8e..0f7709a 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1415,8 +1415,7 @@ def get_script_header(script_text, executable=sys_executable, wininst=False): options = '' if match: options = match.group(1) or '' - if options: - options = ' '+options + if options: options = ' '+options if wininst: executable = "python.exe" else: @@ -1430,7 +1429,8 @@ def get_script_header(script_text, executable=sys_executable, wininst=False): # else: punt, we can't do it, let the warning happen anyway else: options = ' -x' - hdr = "#!%(executable)s%(options)s\n" % locals() + executable = fix_jython_executable(executable, options) + hdr = "#!%(executable)s%(options)s\n" % locals() return hdr def auto_chmod(func, arg, exc): @@ -1465,14 +1465,14 @@ def is_python(text, filename='<string>'): else: return True - - - - - - - - +def is_sh(executable): + """Determine if the specified executable is a .sh (contains a #! line)""" + try: + fp = open(executable) + magic = fp.read(2) + fp.close() + except (OSError,IOError): return executable + return magic == '#!' def nt_quote_arg(arg): """Quote a command line argument according to Windows parsing rules""" @@ -1520,10 +1520,8 @@ def is_python_script(script_text, filename): """ if filename.endswith('.py') or filename.endswith('.pyw'): return True # extension says it's Python - if is_python(script_text, filename): return True # it's syntactically valid Python - if script_text.startswith('#!'): # It begins with a '#!' line, so check if 'python' is in it somewhere return 'python' in script_text.splitlines()[0].lower() @@ -1543,17 +1541,19 @@ def chmod(path, mode): except os.error, e: log.debug("chmod failed: %s", e) - - - - - - - - - - - +def fix_jython_executable(executable, options): + if sys.platform.startswith('java') and is_sh(executable): + # Workaround Jython's sys.executable being a .sh (an invalid + # shebang line interpreter) + if options: + # Can't apply the workaround, leave it broken + log.warn("WARNING: Unable to adapt shebang line for Jython," + " the following script is NOT executable\n" + " see http://bugs.jython.org/issue1112 for" + " more information.") + else: + return '/usr/bin/env %s' % executable + return executable def get_script_args(dist, executable=sys_executable, wininst=False): |