summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools')
-rwxr-xr-xsetuptools/command/easy_install.py10
-rw-r--r--setuptools/tests/test_easy_install.py36
2 files changed, 41 insertions, 5 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 195139c7..c83e4283 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -1591,16 +1591,18 @@ def get_script_args(dist, executable=sys_executable, wininst=False):
spec = str(dist.as_requirement())
header = get_script_header("", executable, wininst)
for group in 'console_scripts', 'gui_scripts':
- for name,ep in dist.get_entry_map(group).items():
+ for name, ep in dist.get_entry_map(group).items():
script_text = (
"# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n"
"__requires__ = %(spec)r\n"
"import sys\n"
"from pkg_resources import load_entry_point\n"
"\n"
- "sys.exit(\n"
- " load_entry_point(%(spec)r, %(group)r, %(name)r)()\n"
- ")\n"
+ "if __name__ == '__main__':"
+ "\n"
+ " sys.exit(\n"
+ " load_entry_point(%(spec)r, %(group)r, %(name)r)()\n"
+ " )\n"
) % locals()
if sys.platform=='win32' or wininst:
# On Windows/wininst, add a .py extension and an .exe launcher
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 583c072b..6ce20e42 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -1,9 +1,32 @@
"""Easy install Tests
"""
+import sys
import os, shutil, tempfile, unittest
-from setuptools.command.easy_install import easy_install
+from setuptools.command.easy_install import easy_install, get_script_args
from setuptools.dist import Distribution
+class FakeDist(object):
+ def get_entry_map(self, group):
+ if group != 'console_scripts':
+ return {}
+ return {'name': 'ep'}
+
+ def as_requirement(self):
+ return 'spec'
+
+WANTED = """\
+#!%s
+# EASY-INSTALL-ENTRY-SCRIPT: 'spec','console_scripts','name'
+__requires__ = 'spec'
+import sys
+from pkg_resources import load_entry_point
+
+if __name__ == '__main__':
+ sys.exit(
+ load_entry_point('spec', 'console_scripts', 'name')()
+ )
+""" % sys.executable
+
class TestEasyInstallTest(unittest.TestCase):
def test_install_site_py(self):
@@ -18,3 +41,14 @@ class TestEasyInstallTest(unittest.TestCase):
finally:
shutil.rmtree(cmd.install_dir)
+ def test_get_script_args(self):
+ dist = FakeDist()
+
+ old_platform = sys.platform
+ try:
+ name, script = get_script_args(dist).next()
+ finally:
+ sys.platform = old_platform
+
+ self.assertEquals(script, WANTED)
+