Commits

Anonymous committed 7dea3f1

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

Comments (0)

Files changed (3)

 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
   can drive an installation that doesn't patch a global setuptools.
 * Reviewed unladen-swallow specific change from
 * Issue 65: cli.exe and gui.exe are now generated at build time,
   depending on the platform in use.
 
-* Issue 67: Fixed doc typo (PEP 381/382) 
+* Issue 67: Fixed doc typo (PEP 381/382)
 
 * Distribute no longer shadows setuptools if we require a 0.7-series
   setuptools.  And an error is raised when installing a 0.7 setuptools with
   This closes http://bitbucket.org/tarek/distribute/issue/16 and
   http://bitbucket.org/tarek/distribute/issue/18.
 
-* zip_ok is now False by default. This closes 
+* zip_ok is now False by default. This closes
   http://bugs.python.org/setuptools/issue33.
 
 * Fixed invalid URL error catching. http://bugs.python.org/setuptools/issue20.

setuptools/command/easy_install.py

     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

setuptools/tests/test_easy_install.py

 """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):
         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)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.