From 024b1e13b644cc9829d2a15cd5867920e11c9a9e Mon Sep 17 00:00:00 2001 From: layday Date: Tue, 16 Mar 2021 18:58:11 +0200 Subject: [PATCH 1/5] build_meta: produce informative error when a dist is not found Previously, when `build_sdist` or `build_wheel` were unable to build a distribution (and were therefore unable to find the distribution file), they would throw a ValueError: not enough values to unpack (expected 1, got 0) which did not offer any clues as to where the issue might lie. --- changelog.d/2608.change.rst | 2 ++ setuptools/build_meta.py | 8 ++++++-- setuptools/tests/test_build_meta.py | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 changelog.d/2608.change.rst diff --git a/changelog.d/2608.change.rst b/changelog.d/2608.change.rst new file mode 100644 index 0000000000..d469f15e2e --- /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..3c45db72fb 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 f33a69688d..f776b09d71 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,19 @@ 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. 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__' From 8f2cc7a1f6cfbfdd8fd07b92dc086b24f2d00e41 Mon Sep 17 00:00:00 2001 From: layday Date: Tue, 16 Mar 2021 19:10:19 +0200 Subject: [PATCH 2/5] fixup! build_meta: produce informative error when a dist is not found --- changelog.d/2608.change.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/2608.change.rst b/changelog.d/2608.change.rst index d469f15e2e..f966649ae7 100644 --- a/changelog.d/2608.change.rst +++ b/changelog.d/2608.change.rst @@ -1,2 +1,2 @@ Added informative error message to PEP 517 build failures owing to -an empty ``setup.py`` -- by :user:layday +an empty ``setup.py`` -- by :user:`layday` From f3ba2139eacd5d27d052f0659b5d7dc1413977b0 Mon Sep 17 00:00:00 2001 From: layday Date: Sun, 21 Mar 2021 19:36:14 +0200 Subject: [PATCH 3/5] fixup! fixup! build_meta: produce informative error when a dist is not found --- setuptools/build_meta.py | 6 +++--- setuptools/tests/test_build_meta.py | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 3c45db72fb..36fbc9e8a1 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -104,9 +104,9 @@ def _file_with_extension(directory, extension): 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()`.') + raise ValueError( + 'No distribution was found. Ensure that `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 f776b09d71..ab75a1896c 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -450,10 +450,7 @@ def test_build_with_empty_setuppy(self, build_backend, build_hook): 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()`.')): + match=re.escape('No distribution was found.')): getattr(build_backend, build_hook)("temp") From 2cec54e4f451d6318ad9fc18213d0f8f7d4aa669 Mon Sep 17 00:00:00 2001 From: layday Date: Sun, 21 Mar 2021 22:00:29 +0200 Subject: [PATCH 4/5] fixup! build_meta: produce informative error when a dist is not found --- setuptools/build_meta.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 36fbc9e8a1..de85685445 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -102,11 +102,13 @@ def _file_with_extension(directory, extension): if f.endswith(extension) ) try: - return next(matching) - except StopIteration: + file, = matching + except ValueError: raise ValueError( 'No distribution was found. Ensure that `setup.py` ' 'is not empty and that it calls `setup()`.') + else: + return file def _open_setup_script(setup_script): From e0655f6459c8ba7ee8a0befbaf55c0e89d25512a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 22 Mar 2021 08:44:55 -0400 Subject: [PATCH 5/5] Remove superfluous else. --- setuptools/build_meta.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index de85685445..9dfb2f24b5 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -107,8 +107,7 @@ def _file_with_extension(directory, extension): raise ValueError( 'No distribution was found. Ensure that `setup.py` ' 'is not empty and that it calls `setup()`.') - else: - return file + return file def _open_setup_script(setup_script):