aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2016-11-18 15:37:30 -0500
committerGitHub <noreply@github.com>2016-11-18 15:37:30 -0500
commit0c3bf692236350f5c2c2cab5b235e9b6d3518fcb (patch)
tree20dcac60a81b9b106192ecd21f841b0bacaaf648
parent3011dc8a2e831c47ef811a396292f854e95665ba (diff)
parent307c5445b50fa4f1759e8cc5c2b2920dce57ff0a (diff)
downloadexternal_python_setuptools-0c3bf692236350f5c2c2cab5b235e9b6d3518fcb.tar.gz
external_python_setuptools-0c3bf692236350f5c2c2cab5b235e9b6d3518fcb.tar.bz2
external_python_setuptools-0c3bf692236350f5c2c2cab5b235e9b6d3518fcb.zip
Merge pull request #842 from idgserpro/bootstrap
Meaningful message if corrupted setuptools.
-rwxr-xr-x[-rw-r--r--]ez_setup.py14
-rw-r--r--test_ez_setup.py16
2 files changed, 28 insertions, 2 deletions
diff --git a/ez_setup.py b/ez_setup.py
index 4ef3ee01..950e120d 100644..100755
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -40,6 +40,8 @@ DEFAULT_VERSION = LATEST
DEFAULT_URL = "https://pypi.io/packages/source/s/setuptools/"
DEFAULT_SAVE_DIR = os.curdir
+MEANINGFUL_INVALID_ZIP_ERR_MSG = 'Maybe {0} is corrupted, delete it and try again.'
+
def _python_cmd(*args):
"""
@@ -104,8 +106,16 @@ def archive_context(filename):
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
- with ContextualZipFile(filename) as archive:
- archive.extractall()
+ try:
+ with ContextualZipFile(filename) as archive:
+ archive.extractall()
+ except zipfile.BadZipfile as err:
+ if not err.args:
+ err.args = ('', )
+ err.args = err.args + (
+ MEANINGFUL_INVALID_ZIP_ERR_MSG.format(filename),
+ )
+ raise
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
diff --git a/test_ez_setup.py b/test_ez_setup.py
index 49a578ea..d35a5cb2 100644
--- a/test_ez_setup.py
+++ b/test_ez_setup.py
@@ -1,5 +1,9 @@
+from zipfile import BadZipfile
+
import py.path
+import pytest
+
import ez_setup
@@ -11,3 +15,15 @@ def test_download(tmpdir_cwd):
assert res.basename.endswith('.zip')
# file should be bigger than 64k
assert res.size() > 2**16
+
+
+def test_message_corrupted_setuptools(tmpdir_cwd):
+ cwd = py.path.local()
+ ez_setup.download_setuptools()
+ res, = cwd.listdir()
+ res.write('CORRUPT ME')
+ with pytest.raises(BadZipfile) as excinfo:
+ with ez_setup.archive_context(res.strpath):
+ pass
+ msg = ez_setup.MEANINGFUL_INVALID_ZIP_ERR_MSG.format(res.strpath)
+ assert msg in str(excinfo.value)