Commit 80878312 authored by Anthony Sottile's avatar Anthony Sottile Committed by Barry Warsaw

Don't crash if there exists an EGG-INFO directory on sys.path (#13667)

* Don't crash if there exists an EGG-INFO directory on sys.path

cross-port of https://gitlab.com/python-devs/importlib_metadata/merge_requests/72

* Also catch PermissionError for windows
parent 29cb21dd
......@@ -320,7 +320,8 @@ class PathDistribution(Distribution):
self._path = path
def read_text(self, filename):
with suppress(FileNotFoundError, NotADirectoryError, KeyError):
with suppress(FileNotFoundError, IsADirectoryError, KeyError,
NotADirectoryError, PermissionError):
return self._path.joinpath(filename).read_text(encoding='utf-8')
read_text.__doc__ = Distribution.read_text.__doc__
......
......@@ -156,3 +156,11 @@ class DiscoveryTests(fixtures.EggInfoPkg,
dist.metadata['Name'] == 'distinfo-pkg'
for dist in dists
)
class DirectoryTest(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
def test(self):
# make an `EGG-INFO` directory that's unrelated
self.site_dir.joinpath('EGG-INFO').mkdir()
# used to crash with `IsADirectoryError`
self.assertIsNone(version('unknown-package'))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment