-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add more helpful error message when metadata is malformed #695
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,12 @@ def check_dependency( | |
# dependency is not installed in the environment. | ||
yield (*ancestral_req_strings, normalised_req_string) | ||
else: | ||
if dist.version is None: | ||
# Malformed dist-info or some other form of metadata corruption | ||
# req.specifier.contains will raise TypeError, so let's do the same | ||
# with a more helpful error message | ||
msg = f'Package {req.name} has malformed metadata and no version information could be found' | ||
raise TypeError(msg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we shouldn't make this a warning instead and return this package as an unmet dependency. That should give more information to the user. As it stands, they would only see an error message about a specific bad dependency, instead of getting a list of all bad ones with the extra context of why this one was considered bad. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems fine to me, sounds reasonable to want all issues at the same time instead of potentially having to address one-by-one |
||
if req.specifier and not req.specifier.contains(dist.version, prereleases=True): | ||
# the installed version is incompatible. | ||
yield (*ancestral_req_strings, normalised_req_string) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
|
||
DEFAULT_BACKEND = { | ||
'build-backend': 'setuptools.build_meta:__legacy__', | ||
'requires': ['setuptools >= 40.8.0'], | ||
'requires': ['setuptools >= 40.8.0', 'wheel'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a regression. Why is it needed? |
||
} | ||
|
||
|
||
|
@@ -43,6 +43,8 @@ def from_name(cls, name): | |
return CircularMockDistribution() | ||
elif name == 'nested_circular_dep': | ||
return NestedCircularMockDistribution() | ||
elif name == 'malformed_dep': | ||
return MalformedMockDistribution() | ||
raise _importlib.metadata.PackageNotFoundError | ||
|
||
|
||
|
@@ -127,6 +129,11 @@ def read_text(self, filename): | |
""" | ||
).strip() | ||
|
||
class MalformedMockDistribution(MockDistribution): | ||
def read_text(self, filename): | ||
if filename == 'METADATA': | ||
return "" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('requirement_string', 'expected'), | ||
|
@@ -165,6 +172,12 @@ def test_check_dependency(monkeypatch, requirement_string, expected): | |
monkeypatch.setattr(_importlib.metadata, 'Distribution', MockDistribution) | ||
assert next(build.check_dependency(requirement_string), None) == expected | ||
|
||
def test_check_dependency_bad_metadata(monkeypatch): | ||
monkeypatch.setattr(_importlib.metadata, 'Distribution', MockDistribution) | ||
with pytest.raises(TypeError) as excinfo: | ||
next(build.check_dependency("malformed_dep==1.0.0"), None) | ||
assert "Package malformed_dep has malformed metadata and no version information could be found" in str(excinfo) | ||
|
||
|
||
def test_bad_project(package_test_no_project): | ||
# Passing a nonexistent project directory | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: so that the name is quoted: