diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 11:45:29 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 11:45:29 -0400 |
commit | e9e4cf8c1b55c55f16337f31bbbadd44da615557 (patch) | |
tree | 01e3585eee837e9cdc268be21b381b9dae8a84dd /pkg_resources | |
parent | 5df09426c3cfae75257849dcc505f4258217bf62 (diff) | |
download | external_python_setuptools-e9e4cf8c1b55c55f16337f31bbbadd44da615557.tar.gz external_python_setuptools-e9e4cf8c1b55c55f16337f31bbbadd44da615557.tar.bz2 external_python_setuptools-e9e4cf8c1b55c55f16337f31bbbadd44da615557.zip |
Short circuit and dedent large block
Diffstat (limited to 'pkg_resources')
-rw-r--r-- | pkg_resources/__init__.py | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index d9664adc..3f7e5b66 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2028,39 +2028,40 @@ def find_on_path(importer, path_item, only=False): path_item, os.path.join(path_item, 'EGG-INFO') ) ) - else: - try: - entries = os.listdir(path_item) - except (PermissionError, NotADirectoryError): + return + + try: + entries = os.listdir(path_item) + except (PermissionError, NotADirectoryError): + return + except OSError as e: + # Ignore the directory if does not exist, not a directory or we + # don't have permissions + ignorable = ( + e.errno in (errno.ENOTDIR, errno.EACCES, errno.ENOENT) + # Python 2 on Windows needs to be handled this way :( + or getattr(e, "winerror", None) == 267 + ) + if ignorable: return - except OSError as e: - # Ignore the directory if does not exist, not a directory or we - # don't have permissions - ignorable = ( - e.errno in (errno.ENOTDIR, errno.EACCES, errno.ENOENT) - # Python 2 on Windows needs to be handled this way :( - or getattr(e, "winerror", None) == 267 - ) - if ignorable: - return - raise - # scan for .egg and .egg-info in directory - path_item_entries = _by_version_descending(entries) - for entry in path_item_entries: - lower = entry.lower() - fullpath = os.path.join(path_item, entry) - is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info'))) - dists = ( - distributions_from_metadata(fullpath) - if is_meta else - find_distributions(fullpath) - if not only and _is_egg_path(entry) else - resolve_egg_link(fullpath) - if not only and lower.endswith('.egg-link') else - () - ) - for dist in dists: - yield dist + raise + # scan for .egg and .egg-info in directory + path_item_entries = _by_version_descending(entries) + for entry in path_item_entries: + lower = entry.lower() + fullpath = os.path.join(path_item, entry) + is_meta = any(map(lower.endswith, ('.egg-info', '.dist-info'))) + dists = ( + distributions_from_metadata(fullpath) + if is_meta else + find_distributions(fullpath) + if not only and _is_egg_path(entry) else + resolve_egg_link(fullpath) + if not only and lower.endswith('.egg-link') else + () + ) + for dist in dists: + yield dist def distributions_from_metadata(path): |