Skip to content

Commit aa71b8e

Browse files
Volcyygaborbernat
authored andcommitted
Provide friendlier error for missing setup.py. (tox-dev#650)
* Provide friendlier error for missing setup.py * Added a test case for missing setup.py. Closes tox-dev#331.
1 parent 305d71a commit aa71b8e

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Ionel Maries Cristian
2424
Ionel Maries Cristian
2525
Itxaka Serrano
2626
Jannis Leidel
27+
Johannes Christ
2728
Josh Smeaton
2829
Julian Krause
2930
Krisztian Fekete

changelog/331.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Running ``tox`` without a ``setup.py`` now has a more friendly error message and gives troubleshooting suggestions - by @Volcyy.

tests/test_z_cmdline.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import platform
23

34
import py
@@ -454,6 +455,21 @@ def test_sdist_fails(cmd, initproj):
454455
])
455456

456457

458+
def test_no_setup_py_exits(cmd, initproj):
459+
initproj("pkg123-0.7", filedefs={
460+
'tox.ini': """
461+
[testenv]
462+
commands=python -c "2 + 2"
463+
"""
464+
})
465+
os.remove("setup.py")
466+
result = cmd.run("tox", )
467+
assert result.ret
468+
result.stdout.fnmatch_lines([
469+
"*ERROR*No setup.py file found*"
470+
])
471+
472+
457473
def test_package_install_fails(cmd, initproj):
458474
initproj("pkg123-0.7", filedefs={
459475
'tests': {'test_hello.py': "def test_hello(): pass"},

tox/session.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,17 @@ def _copyfiles(self, srcdir, pathlist, destdir):
403403
def _makesdist(self):
404404
setup = self.config.setupdir.join("setup.py")
405405
if not setup.check():
406-
raise tox.exception.MissingFile(setup)
406+
self.report.error(
407+
"No setup.py file found. The expected location is:\n"
408+
" %s\n"
409+
"You can\n"
410+
" 1. Create one:\n"
411+
" https://packaging.python.org/tutorials/distributing-packages/#setup-py\n"
412+
" 2. Configure tox to avoid running sdist:\n"
413+
" http://tox.readthedocs.io/en/latest/example/general.html"
414+
"#avoiding-expensive-sdist" % setup
415+
)
416+
raise SystemExit(1)
407417
action = self.newaction(None, "packaging")
408418
with action:
409419
action.setactivity("sdist-make", setup)

0 commit comments

Comments
 (0)