]> granicus.if.org Git - python/commitdiff
Don't crash if there exists an EGG-INFO directory on sys.path (#13667)
authorAnthony Sottile <asottile@umich.edu>
Thu, 30 May 2019 00:13:12 +0000 (17:13 -0700)
committerBarry Warsaw <barry@python.org>
Thu, 30 May 2019 00:13:11 +0000 (17:13 -0700)
* 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

Lib/importlib/metadata/__init__.py
Lib/test/test_importlib/test_main.py

index 24d45d2caad0ad13eb2f0466ff7ce3f62ceb52e4..a1abdd64815bff605deed53585505dbdadfe4a91 100644 (file)
@@ -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__
 
index b70f9440f6973a7f939ef65f03cdec3110b9d386..844ed26c3ec79f109a116e8223b833a8a3ef0ee9 100644 (file)
@@ -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'))