diff options
| -rw-r--r-- | changelog.d/2608.change.rst | 2 | ||||
| -rw-r--r-- | setuptools/build_meta.py | 8 | ||||
| -rw-r--r-- | setuptools/tests/test_build_meta.py | 14 |
3 files changed, 22 insertions, 2 deletions
diff --git a/changelog.d/2608.change.rst b/changelog.d/2608.change.rst new file mode 100644 index 00000000..d469f15e --- /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 b9e8a2b3..3c45db72 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -101,8 +101,12 @@ def _file_with_extension(directory, extension): f for f in os.listdir(directory) if f.endswith(extension) ) - file, = matching - return file + try: + return next(matching) + except StopIteration: + raise ValueError('No distribution was found. The distribution was ' + 'possibly not built. Ensure that your `setup.py` ' + 'is not empty and that it calls `setup()`.') def _open_setup_script(setup_script): diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py index f33a6968..f776b09d 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -3,6 +3,7 @@ import shutil import tarfile import importlib from concurrent import futures +import re import pytest from jaraco import path @@ -442,6 +443,19 @@ class TestBuildMetaBackend: 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. The distribution was ' + 'possibly not built. Ensure that your `setup.py` ' + 'is not empty and that it calls `setup()`.')): + getattr(build_backend, build_hook)("temp") + class TestBuildMetaLegacyBackend(TestBuildMetaBackend): backend_name = 'setuptools.build_meta:__legacy__' |
