aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Krull <f_krull@gmx.de>2016-06-26 01:48:30 +0200
committerFelix Krull <f_krull@gmx.de>2016-06-26 01:48:30 +0200
commit3132833570c90d52f6c2a422506732e82d772cdd (patch)
treed0b28765bd0f7fc9302e679353eeae67859cee8f
parent6f79ca2b726b2b92d007d09fb855f19ede5a1921 (diff)
downloadexternal_python_setuptools-3132833570c90d52f6c2a422506732e82d772cdd.tar.gz
external_python_setuptools-3132833570c90d52f6c2a422506732e82d772cdd.tar.bz2
external_python_setuptools-3132833570c90d52f6c2a422506732e82d772cdd.zip
Ensure shebang lines are correctly quoted if sys.executable contains spaces.
Fixes issue #398. This only special-cases sys.executable; if the --executable parameter is used, paths with spaces have to be quoted there explicitly. While this change also applies to Unix platforms, if sys.executable contains spaces on Unix, any shebang lines created with it aren't going to work either way, whether they are quoted or not.
-rwxr-xr-xsetuptools/command/easy_install.py11
-rwxr-xr-xsetuptools/command/install_scripts.py5
2 files changed, 15 insertions, 1 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 9ca1554e..d63fb529 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -1986,8 +1986,17 @@ class CommandSpec(list):
return self._render(self + list(self.options))
@staticmethod
+ def _strip_quotes(item):
+ _QUOTES = '"\''
+ for q in _QUOTES:
+ if item.startswith(q) and item.endswith(q):
+ return item[1:-1]
+ return item
+
+ @staticmethod
def _render(items):
- cmdline = subprocess.list2cmdline(items)
+ cmdline = subprocess.list2cmdline(
+ CommandSpec._strip_quotes(item.strip()) for item in items)
return '#!' + cmdline + '\n'
# For pbr compat; will be removed in a future version.
diff --git a/setuptools/command/install_scripts.py b/setuptools/command/install_scripts.py
index be66cb22..16234273 100755
--- a/setuptools/command/install_scripts.py
+++ b/setuptools/command/install_scripts.py
@@ -1,6 +1,7 @@
from distutils import log
import distutils.command.install_scripts as orig
import os
+import sys
from pkg_resources import Distribution, PathMetadata, ensure_directory
@@ -37,6 +38,10 @@ class install_scripts(orig.install_scripts):
if is_wininst:
exec_param = "python.exe"
writer = ei.WindowsScriptWriter
+ if exec_param == sys.executable:
+ # In case the path to the Python executable contains a space, wrap
+ # it so it's not split up.
+ exec_param = [exec_param]
# resolve the writer to the environment
writer = writer.best()
cmd = writer.command_spec_class.best().from_param(exec_param)