Commits

Erik Bray committed 4f7c0c7

Adds a fix for issue #318, including a regression test. This also fixes another test that was passing trivially due to *bug* in yet another test, ugh

Comments (0)

Files changed (4)

setuptools/dist.py

 
     def fetch_build_egg(self, req):
         """Fetch an egg needed for building"""
+
         try:
             cmd = self._egg_fetcher
             cmd.package_index.to_scan = []
             cmd = easy_install(
                 dist, args=["x"], install_dir=os.curdir, exclude_scripts=True,
                 always_copy=False, build_directory=None, editable=False,
-                upgrade=False, multi_version=True, no_report = True
+                upgrade=False, multi_version=True, no_report=True, user=False
             )
             cmd.ensure_finalized()
             self._egg_fetcher = cmd

setuptools/sandbox.py

     _EXCEPTIONS = []
 
 try:
-	from win32com.client.gencache import GetGeneratePath
-	_EXCEPTIONS.append(GetGeneratePath())
-	del GetGeneratePath
+    from win32com.client.gencache import GetGeneratePath
+    _EXCEPTIONS.append(GetGeneratePath())
+    del GetGeneratePath
 except ImportError:
-	# it appears pywin32 is not installed, so no need to exclude.
-	pass
+    # it appears pywin32 is not installed, so no need to exclude.
+    pass
 
 class DirectorySandbox(AbstractSandbox):
     """Restrict operations to a single subdirectory - pseudo-chroot"""

setuptools/tests/__init__.py

     try:
         return setuptools.setup(**args)
     finally:
-        distutils.core_setup_stop_after = None
+        distutils.core._setup_stop_after = None
 
 
 class DependsTests(unittest.TestCase):

setuptools/tests/test_easy_install.py

 import StringIO
 import distutils.core
 
+from setuptools.sandbox import run_setup, SandboxViolation
 from setuptools.command.easy_install import easy_install, get_script_args, main
 from setuptools.command.easy_install import  PthDistributions
 from setuptools.command import easy_install as easy_install_pkg
         old_wd = os.getcwd()
         try:
             os.chdir(dir)
-            main([])
+            reset_setup_stop_context(
+                lambda: self.assertRaises(SystemExit, main, [])
+            )
         finally:
             os.chdir(old_wd)
             shutil.rmtree(dir)
             cmd.local_index.scan([new_location])
             res = cmd.easy_install('foo')
             self.assertEqual(os.path.realpath(res.location),
-                             os.path.realpath(new_location))            
+                             os.path.realpath(new_location))
         finally:
             sys.path.remove(target)
             for basedir in [new_location, target, ]:
             else:
                 del os.environ['PYTHONPATH']
 
+    def test_setup_requires(self):
+        """Regression test for issue #318
+
+        Ensures that a package with setup_requires can be installed when
+        distribute is installed in the user site-packages without causing a
+        SandboxViolation.
+        """
+
+        test_setup_attrs = {
+            'name': 'test_pkg', 'version': '0.0',
+            'setup_requires': ['foobar'],
+            'dependency_links': [os.path.abspath(self.dir)]
+        }
+
+        test_pkg = os.path.join(self.dir, 'test_pkg')
+        test_setup_py = os.path.join(test_pkg, 'setup.py')
+        test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
+        os.mkdir(test_pkg)
+
+        f = open(test_setup_py, 'w')
+        f.write(textwrap.dedent("""\
+            import setuptools
+            setuptools.setup(**%r)
+        """ % test_setup_attrs))
+        f.close()
+
+        foobar_path = os.path.join(self.dir, 'foobar-0.1.tar.gz')
+        make_trivial_sdist(
+            foobar_path,
+            textwrap.dedent("""\
+                import setuptools
+                setuptools.setup(
+                    name='foobar',
+                    version='0.1'
+                )
+            """))
+
+        try:
+            reset_setup_stop_context(
+                lambda: run_setup(test_setup_py, ['install'])
+            )
+        except SandboxViolation:
+            self.fail('Installation caused SandboxViolation')
+
 
 class TestSetupRequires(unittest.TestCase):
 
         doesn't exist) and invoke installer on it.
         """
         def build_sdist(dir):
-            setup_py = tarfile.TarInfo(name="setup.py")
-            try:
-                # Python 3 (StringIO gets converted to io module)
-                MemFile = StringIO.BytesIO
-            except AttributeError:
-                MemFile = StringIO.StringIO
-            setup_py_bytes = MemFile(textwrap.dedent("""
-                import setuptools
-                setuptools.setup(
-                    name="distribute-test-fetcher",
-                    version="1.0",
-                    setup_requires = ['does-not-exist'],
-                )
-                """).lstrip().encode('utf-8'))
-            setup_py.size = len(setup_py_bytes.getvalue())
             dist_path = os.path.join(dir, 'distribute-test-fetcher-1.0.tar.gz')
-            dist = tarfile.open(dist_path, 'w:gz')
-            try:
-                dist.addfile(setup_py, fileobj=setup_py_bytes)
-            finally:
-                dist.close()
+            make_trivial_sdist(
+                dist_path,
+                textwrap.dedent("""
+                    import setuptools
+                    setuptools.setup(
+                        name="distribute-test-fetcher",
+                        version="1.0",
+                        setup_requires = ['does-not-exist'],
+                    )
+                """).lstrip())
             installer(dist_path)
         tempdir_context(build_sdist)
 
+
+def make_trivial_sdist(dist_path, setup_py):
+    """Create a simple sdist tarball at dist_path, containing just a
+    setup.py, the contents of which are provided by the setup_py string.
+    """
+
+    setup_py_file = tarfile.TarInfo(name='setup.py')
+    try:
+        # Python 3 (StringIO gets converted to io module)
+        MemFile = StringIO.BytesIO
+    except AttributeError:
+        MemFile = StringIO.StringIO
+    setup_py_bytes = MemFile(setup_py.encode('utf-8'))
+    setup_py_file.size = len(setup_py_bytes.getvalue())
+    dist = tarfile.open(dist_path, 'w:gz')
+    try:
+        dist.addfile(setup_py_file, fileobj=setup_py_bytes)
+    finally:
+        dist.close()
+
+
 def tempdir_context(f, cd=lambda dir:None):
     """
     Invoke f in the context