Commit d847dbfe authored by Erik Bray's avatar Erik Bray

Adds a fix for issue #318, including a regression test. This also fixes...

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

--HG--
branch : distribute
extra : rebase_source : 476550766b7b756dced040ad4356b7685d6f062a
parent 9ebbe014
......@@ -264,6 +264,7 @@ class Distribution(_Distribution):
def fetch_build_egg(self, req):
"""Fetch an egg needed for building"""
try:
cmd = self._egg_fetcher
cmd.package_index.to_scan = []
......@@ -287,7 +288,7 @@ class Distribution(_Distribution):
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
......
......@@ -166,12 +166,12 @@ else:
_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"""
......
......@@ -38,7 +38,7 @@ def makeSetup(**args):
try:
return setuptools.setup(**args)
finally:
distutils.core_setup_stop_after = None
distutils.core._setup_stop_after = None
class DependsTests(unittest.TestCase):
......
......@@ -12,6 +12,7 @@ import urlparse
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
......@@ -110,7 +111,9 @@ class TestEasyInstallTest(unittest.TestCase):
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)
......@@ -247,7 +250,7 @@ class TestUserInstallTest(unittest.TestCase):
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, ]:
......@@ -262,6 +265,50 @@ class TestUserInstallTest(unittest.TestCase):
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):
......@@ -319,30 +366,41 @@ 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
......
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