File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 5555class PackageNotFoundError (ModuleNotFoundError ):
5656 """The package was not found."""
5757
58+ def __str__ (self ):
59+ tmpl = "No package metadata was found for {self.name}"
60+ return tmpl .format (** locals ())
61+
62+ @property
63+ def name (self ):
64+ name , = self .args
65+ return name
66+
5867
5968class EntryPoint (
6069 PyPy_repr ,
Original file line number Diff line number Diff line change 22 importlib_metadata NEWS
33=========================
44
5+ v1.7.0
6+ ======
7+
8+ * ``PathNotFoundError `` now has a custom ``__str__ ``
9+ mentioning "package metadata" being missing to help
10+ guide users to the cause when the package is installed
11+ but no metadata is present. Closes #124.
12+
513v1.6.1
614======
715
Original file line number Diff line number Diff line change @@ -35,6 +35,18 @@ def test_for_name_does_not_exist(self):
3535 with self .assertRaises (PackageNotFoundError ):
3636 Distribution .from_name ('does-not-exist' )
3737
38+ def test_package_not_found_mentions_metadata (self ):
39+ """
40+ When a package is not found, that could indicate that the
41+ packgae is not installed or that it is installed without
42+ metadata. Ensure the exception mentions metadata to help
43+ guide users toward the cause. See #124.
44+ """
45+ with self .assertRaises (PackageNotFoundError ) as ctx :
46+ Distribution .from_name ('does-not-exist' )
47+
48+ assert "metadata" in str (ctx .exception )
49+
3850 def test_new_style_classes (self ):
3951 self .assertIsInstance (Distribution , type )
4052 self .assertIsInstance (MetadataPathFinder , type )
You can’t perform that action at this time.
0 commit comments