aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsetuptools/command/easy_install.py11
-rw-r--r--setuptools/tests/test_easy_install.py28
2 files changed, 24 insertions, 15 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index c2928c77..bf648384 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -1592,11 +1592,6 @@ def _first_line_re():
return re.compile(first_line_re.pattern.decode())
-def get_script_header(script_text, executable=sys_executable, wininst=False):
- executable = "python.exe" if wininst else nt_quote_arg(executable)
- return ScriptWriter.get_header(script_text, executable)
-
-
def auto_chmod(func, arg, exc):
if func is os.remove and os.name == 'nt':
chmod(arg, stat.S_IWRITE)
@@ -1887,6 +1882,11 @@ class ScriptWriter(object):
return writer._gen_args(dist, header)
@classmethod
+ def get_script_header(cls, script_text, executable=sys_executable, wininst=False):
+ executable = "python.exe" if wininst else nt_quote_arg(executable)
+ return cls.get_header(script_text, executable)
+
+ @classmethod
def _gen_args(cls, dist, header=None):
"""
Yield write_script() argument tuples for a distribution's entrypoints
@@ -2016,6 +2016,7 @@ class WindowsExecutableLauncherWriter(WindowsScriptWriter):
# for backward-compatibility
get_script_args = ScriptWriter.get_script_args
+get_script_header = ScriptWriter.get_script_header
def get_win_launcher(type):
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index b42d2c07..5d1068ea 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -23,7 +23,7 @@ from setuptools.compat import StringIO, BytesIO, urlparse
from setuptools.sandbox import run_setup
from setuptools.command.easy_install import (
easy_install, fix_jython_executable, nt_quote_arg,
- get_script_header, is_sh, ScriptWriter,
+ is_sh, ScriptWriter,
)
from setuptools.command.easy_install import PthDistributions
from setuptools.command import easy_install as easy_install_pkg
@@ -425,15 +425,22 @@ class TestScriptHeader:
)
def test_get_script_header(self):
expected = '#!%s\n' % nt_quote_arg(os.path.normpath(sys.executable))
- assert get_script_header('#!/usr/local/bin/python') == expected
+ actual = ScriptWriter.get_script_header('#!/usr/local/bin/python')
+ assert actual == expected
+
expected = '#!%s -x\n' % nt_quote_arg(os.path.normpath(sys.executable))
- assert get_script_header('#!/usr/bin/python -x') == expected
- candidate = get_script_header('#!/usr/bin/python',
+ actual = ScriptWriter.get_script_header('#!/usr/bin/python -x')
+ assert actual == expected
+
+ actual = ScriptWriter.get_script_header('#!/usr/bin/python',
executable=self.non_ascii_exe)
- assert candidate == '#!%s -x\n' % self.non_ascii_exe
- candidate = get_script_header('#!/usr/bin/python',
+ expected = '#!%s -x\n' % self.non_ascii_exe
+ assert actual == expected
+
+ actual = ScriptWriter.get_script_header('#!/usr/bin/python',
executable=self.exe_with_spaces)
- assert candidate == '#!"%s"\n' % self.exe_with_spaces
+ expected = '#!"%s"\n' % self.exe_with_spaces
+ assert actual == expected
@pytest.mark.xfail(
compat.PY3 and os.environ.get("LC_CTYPE") in ("C", "POSIX"),
@@ -453,7 +460,8 @@ class TestScriptHeader:
f.write(header)
exe = str(exe)
- header = get_script_header('#!/usr/local/bin/python', executable=exe)
+ header = ScriptWriter.get_script_header('#!/usr/local/bin/python',
+ executable=exe)
assert header == '#!/usr/bin/env %s\n' % exe
expect_out = 'stdout' if sys.version_info < (2,7) else 'stderr'
@@ -461,14 +469,14 @@ class TestScriptHeader:
with contexts.quiet() as (stdout, stderr):
# When options are included, generate a broken shebang line
# with a warning emitted
- candidate = get_script_header('#!/usr/bin/python -x',
+ candidate = ScriptWriter.get_script_header('#!/usr/bin/python -x',
executable=exe)
assert candidate == '#!%s -x\n' % exe
output = locals()[expect_out]
assert 'Unable to adapt shebang line' in output.getvalue()
with contexts.quiet() as (stdout, stderr):
- candidate = get_script_header('#!/usr/bin/python',
+ candidate = ScriptWriter.get_script_header('#!/usr/bin/python',
executable=self.non_ascii_exe)
assert candidate == '#!%s -x\n' % self.non_ascii_exe
output = locals()[expect_out]