Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_meta: produce informative error when a dist is not found #2608

Merged
merged 5 commits into from
Mar 22, 2021
Merged

build_meta: produce informative error when a dist is not found #2608

merged 5 commits into from
Mar 22, 2021

Conversation

layday
Copy link
Member

@layday layday commented Mar 16, 2021

Summary of changes

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.

Pull Request Checklist

layday added 2 commits March 16, 2021 19:06
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.
@layday
Copy link
Member Author

layday commented Mar 16, 2021

See pypa/packaging.python.org#838 (and subsequently pypa/packaging-problems#467 and pypa/packaging-problems#468) which motivated this change.

file, = matching
return file
try:
return next(matching)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, the code would check for exactly one match. Now it only checks for at least one match (and ignores all but the first). Could that silently swallow errors?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose, if multiple distributions would be built somehow or if the folder already had a distribution in it but then all bets are off anyway.

Comment on lines 107 to 109
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()`.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hanging indents and use of first/second person. Remove 'Distribution was possibly not built', as that's mainly redundant with no distribution was found.

Suggested change
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()`.')

Comment on lines 453 to 456
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()`.')):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify match to avoid over-matching the expected text. Just assert on the gist of the message.

Suggested change
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.')):

Copy link
Member

@jaraco jaraco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a few changes requested.

Comment on lines +107 to +109
raise ValueError(
'No distribution was found. Ensure that `setup.py` '
'is not empty and that it calls `setup()`.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be raise ValueError(...) from None, to simplify the output? The original ValueError from unpacking the tuple is not interesting to anyone and adding noise, since it's literally the only thing done here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again, somehing else might raise a ValueError since the generator isn't consumed before it's unpacked and ValueError is so ubiquitous that I'm a little wary of erasing it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like to convert the generator to a list comprehension and then raise from None, I think that'd be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the generator is created on the line above, there currently should be no way to for it to be exhausted before it hits this point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, hence it might raise an unrelated value error in the try block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see what you mean.

henryiii added a commit to henryiii/setuptools that referenced this pull request Apr 1, 2021
Followup to pypa#2608. Makes sure an unrelated ValueError is not caught by the try/except, then removes the extra exception printout. Also moves the msg to the line above to avoid a double message printout in the traceback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants