diff --git a/changelog.d/2608.change.rst b/changelog.d/2608.change.rst new file mode 100644 index 0000000000..f966649ae7 --- /dev/null +++ b/changelog.d/2608.change.rst @@ -0,0 +1,2 @@ +Added informative error message to PEP 517 build failures owing to +an empty ``setup.py`` -- by :user:`layday` diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index b9e8a2b3fa..9dfb2f24b5 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -101,7 +101,12 @@ def _file_with_extension(directory, extension): f for f in os.listdir(directory) if f.endswith(extension) ) - file, = matching + try: + file, = matching + except ValueError: + raise ValueError( + 'No distribution was found. Ensure that `setup.py` ' + 'is not empty and that it calls `setup()`.') return file diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index f33a69688d..ab75a1896c 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -3,6 +3,7 @@ import tarfile import importlib from concurrent import futures +import re import pytest from jaraco import path @@ -442,6 +443,16 @@ def test_sys_argv_passthrough(self, tmpdir_cwd): with pytest.raises(AssertionError): build_backend.build_sdist("temp") + @pytest.mark.parametrize('build_hook', ('build_sdist', 'build_wheel')) + def test_build_with_empty_setuppy(self, build_backend, build_hook): + files = {'setup.py': ''} + path.build(files) + + with pytest.raises( + ValueError, + match=re.escape('No distribution was found.')): + getattr(build_backend, build_hook)("temp") + class TestBuildMetaLegacyBackend(TestBuildMetaBackend): backend_name = 'setuptools.build_meta:__legacy__'