Skip to content

Commit

Permalink
Merge pull request #2608 from layday/pep517-better-error-on-missing-dist
Browse files Browse the repository at this point in the history
build_meta: produce informative error when a dist is not found
  • Loading branch information
jaraco committed Mar 22, 2021
2 parents 99a9891 + e0655f6 commit 88b8b78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelog.d/2608.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added informative error message to PEP 517 build failures owing to
an empty ``setup.py`` -- by :user:`layday`
7 changes: 6 additions & 1 deletion setuptools/build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 11 additions & 0 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tarfile
import importlib
from concurrent import futures
import re

import pytest
from jaraco import path
Expand Down Expand Up @@ -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__'
Expand Down

0 comments on commit 88b8b78

Please sign in to comment.