Commit 6ef67c96 authored by tarek's avatar tarek

Generated scripts now wraps their call in a __main__ section. Fixes #11

--HG--
branch : distribute
extra : rebase_source : d69b879d01ca2690826cdf9b7541e541ae8e0f5a
parent 9d29ae85
...@@ -6,6 +6,8 @@ CHANGES ...@@ -6,6 +6,8 @@ CHANGES
0.6.7 0.6.7
----- -----
* Issue 11: Generated scripts now wrap their call to the script entry point
in the standard "if name == 'main'"
* Added the 'DONT_PATCH_SETUPTOOLS' environment variable, so virtualenv * Added the 'DONT_PATCH_SETUPTOOLS' environment variable, so virtualenv
can drive an installation that doesn't patch a global setuptools. can drive an installation that doesn't patch a global setuptools.
* Reviewed unladen-swallow specific change from * Reviewed unladen-swallow specific change from
......
...@@ -1591,16 +1591,18 @@ def get_script_args(dist, executable=sys_executable, wininst=False): ...@@ -1591,16 +1591,18 @@ def get_script_args(dist, executable=sys_executable, wininst=False):
spec = str(dist.as_requirement()) spec = str(dist.as_requirement())
header = get_script_header("", executable, wininst) header = get_script_header("", executable, wininst)
for group in 'console_scripts', 'gui_scripts': 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 = ( script_text = (
"# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n" "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n"
"__requires__ = %(spec)r\n" "__requires__ = %(spec)r\n"
"import sys\n" "import sys\n"
"from pkg_resources import load_entry_point\n" "from pkg_resources import load_entry_point\n"
"\n" "\n"
"sys.exit(\n" "if __name__ == '__main__':"
"\n"
" sys.exit(\n"
" load_entry_point(%(spec)r, %(group)r, %(name)r)()\n" " load_entry_point(%(spec)r, %(group)r, %(name)r)()\n"
")\n" " )\n"
) % locals() ) % locals()
if sys.platform=='win32' or wininst: if sys.platform=='win32' or wininst:
# On Windows/wininst, add a .py extension and an .exe launcher # On Windows/wininst, add a .py extension and an .exe launcher
......
"""Easy install Tests """Easy install Tests
""" """
import sys
import os, shutil, tempfile, unittest 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 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): class TestEasyInstallTest(unittest.TestCase):
def test_install_site_py(self): def test_install_site_py(self):
...@@ -18,3 +41,14 @@ class TestEasyInstallTest(unittest.TestCase): ...@@ -18,3 +41,14 @@ class TestEasyInstallTest(unittest.TestCase):
finally: finally:
shutil.rmtree(cmd.install_dir) 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment