diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 12:04:12 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-09-09 12:07:50 -0400 |
| commit | 9ff9a0d6a79b8d4b610f8e8780586dd2114856d0 (patch) | |
| tree | 3c3fedf8bd026311ce6d066f111370f4530efbc8 | |
| parent | eea94d01a59f7f43dd41c271ff6849995a4d1e7e (diff) | |
| download | python-setuptools-git-9ff9a0d6a79b8d4b610f8e8780586dd2114856d0.tar.gz | |
Create a NoDists factory for returning no dists, whose boolean value is False.
| -rw-r--r-- | pkg_resources/__init__.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index d9154e6d..82b4ce51 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -2045,12 +2045,29 @@ def find_on_path(importer, path_item, only=False): if not only and _is_egg_path(entry) else resolve_egg_link(fullpath) if not only and lower.endswith('.egg-link') else - () + NoDists()(fullpath) ) for dist in dists: yield dist +class NoDists: + """ + >>> bool(NoDists()) + False + + >>> list(NoDists()('anything')) + [] + """ + def __bool__(self): + return False + if six.PY2: + __nonzero__ = __bool__ + + def __call__(self, fullpath): + return iter(()) + + def safe_listdir(path): """ Attempt to list contents of path, but suppress some exceptions. |
