Skip to content

Commit 8087831

Browse files
asottilewarsaw
authored andcommitted
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
1 parent 29cb21d commit 8087831

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Lib/importlib/metadata/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ def __init__(self, path):
320320
self._path = path
321321

322322
def read_text(self, filename):
323-
with suppress(FileNotFoundError, NotADirectoryError, KeyError):
323+
with suppress(FileNotFoundError, IsADirectoryError, KeyError,
324+
NotADirectoryError, PermissionError):
324325
return self._path.joinpath(filename).read_text(encoding='utf-8')
325326
read_text.__doc__ = Distribution.read_text.__doc__
326327

Lib/test/test_importlib/test_main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,11 @@ def test_package_discovery(self):
156156
dist.metadata['Name'] == 'distinfo-pkg'
157157
for dist in dists
158158
)
159+
160+
161+
class DirectoryTest(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
162+
def test(self):
163+
# make an `EGG-INFO` directory that's unrelated
164+
self.site_dir.joinpath('EGG-INFO').mkdir()
165+
# used to crash with `IsADirectoryError`
166+
self.assertIsNone(version('unknown-package'))

0 commit comments

Comments
 (0)