summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2013-08-14 08:57:10 +0200
committerAnthon van der Neut <anthon@mnt.org>2013-08-14 08:57:10 +0200
commitb81da7052b0905d141a5d37ac048eac7c7ed475e (patch)
tree987e61c0481ca2263b7788d5b6d35a74bac6def3
parent21363d12a59d1f51a17c4d42b4b6ee007ca57222 (diff)
downloadtox-b81da7052b0905d141a5d37ac048eac7c7ed475e.tar.gz
issue_1_empty_setup_py: fix for issue #1: Empty setup.py leads to very obscure error
This was caused by no dist directory being created and listing that directory raising an exception. - added some test for setup.py: - empty - only start of line comment - some code, but no setup() - on error finding the dist - check if empty or comment only setup.py: msg that setup.py is empty - msg to check 'python setup.py sdist' by hand
-rw-r--r--tests/test_z_cmdline.py48
-rw-r--r--tox/_cmdline.py22
2 files changed, 69 insertions, 1 deletions
diff --git a/tests/test_z_cmdline.py b/tests/test_z_cmdline.py
index 5c94251..d7f99b6 100644
--- a/tests/test_z_cmdline.py
+++ b/tests/test_z_cmdline.py
@@ -269,6 +269,54 @@ def test_skip_sdist(cmd, initproj):
result = cmd.run("tox", )
assert result.ret == 0
+def test_minimal_setup_py_empty(cmd, initproj):
+ initproj("pkg123-0.7", filedefs={
+ 'tests': {'test_hello.py': "def test_hello(): pass"},
+ 'setup.py': """
+ """
+ ,
+ 'tox.ini': ''
+
+ })
+ result = cmd.run("tox", )
+ assert result.ret == 1
+ result.stdout.fnmatch_lines([
+ "*ERROR*empty*",
+ ])
+
+def test_minimal_setup_py_comment_only(cmd, initproj):
+ initproj("pkg123-0.7", filedefs={
+ 'tests': {'test_hello.py': "def test_hello(): pass"},
+ 'setup.py': """\n# some comment
+
+ """
+ ,
+ 'tox.ini': ''
+
+ })
+ result = cmd.run("tox", )
+ assert result.ret == 1
+ result.stdout.fnmatch_lines([
+ "*ERROR*empty*",
+ ])
+
+def test_minimal_setup_py_non_functional(cmd, initproj):
+ initproj("pkg123-0.7", filedefs={
+ 'tests': {'test_hello.py': "def test_hello(): pass"},
+ 'setup.py': """
+ import sys
+
+ """
+ ,
+ 'tox.ini': ''
+
+ })
+ result = cmd.run("tox", )
+ assert result.ret == 1
+ result.stdout.fnmatch_lines([
+ "*ERROR*check setup.py*",
+ ])
+
def test_sdist_fails(cmd, initproj):
initproj("pkg123-0.7", filedefs={
'tests': {'test_hello.py': "def test_hello(): pass"},
diff --git a/tox/_cmdline.py b/tox/_cmdline.py
index 7b39250..42a3f80 100644
--- a/tox/_cmdline.py
+++ b/tox/_cmdline.py
@@ -321,7 +321,27 @@ class Session:
action.popen([sys.executable, setup, "sdist", "--formats=zip",
"--dist-dir", self.config.distdir, ],
cwd=self.config.setupdir)
- return self.config.distdir.listdir()[0]
+ try:
+ return self.config.distdir.listdir()[0]
+ except py.error.ENOENT:
+ # check if empty or comment only
+ data = []
+ with open(str(setup)) as fp:
+ for line in fp:
+ if line and line[0] == '#':
+ continue
+ data.append(line)
+ if not ''.join(data).strip():
+ self.report.error(
+ 'setup.py is empty'
+ )
+ raise SystemExit(1)
+ self.report.error(
+ 'No dist directory found. Please check setup.py, e.g with:\n'\
+ ' python setup.py sdist'
+ )
+ raise SystemExit(1)
+
def make_emptydir(self, path):
if path.check():