From 95f0df79e8a51d9fa3d4b956420dce70b64100d9 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 17 Jul 2018 03:25:18 -0400 Subject: [PATCH] Fix pythonfinder bug unnesting python versions Signed-off-by: Dan Ryan --- pipenv/vendor/pythonfinder/models/__init__.py | 4 ++-- pipenv/vendor/pythonfinder/utils.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pipenv/vendor/pythonfinder/models/__init__.py b/pipenv/vendor/pythonfinder/models/__init__.py index b1b56d43..4d906544 100644 --- a/pipenv/vendor/pythonfinder/models/__init__.py +++ b/pipenv/vendor/pythonfinder/models/__init__.py @@ -4,7 +4,7 @@ import abc import operator import six from itertools import chain -from ..utils import KNOWN_EXTS +from ..utils import KNOWN_EXTS, unnest @six.add_metaclass(abc.ABCMeta) @@ -88,7 +88,7 @@ class BasePath(object): if self.is_python and version_matcher(self.as_python): return self return - finder = ((child, child.as_python) for child in chain(*filter(None, self.pythons.values())) if child.as_python) + finder = ((child, child.as_python) for child in unnest(self.pythons.values()) if child.as_python) py_filter = filter( None, filter(lambda child: version_matcher(child[1]), finder) ) diff --git a/pipenv/vendor/pythonfinder/utils.py b/pipenv/vendor/pythonfinder/utils.py index df837ea9..fdc54381 100644 --- a/pipenv/vendor/pythonfinder/utils.py +++ b/pipenv/vendor/pythonfinder/utils.py @@ -8,6 +8,7 @@ import subprocess import sys from fnmatch import fnmatch from .exceptions import InvalidPythonVersion +from itertools import chain try: from pathlib import Path @@ -137,3 +138,9 @@ def fs_str(string): _fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() + + +def unnest(item): + if isinstance(next((i for i in item), None), (list, tuple)): + return chain(*filter(None, item)) + return chain(filter(None, item))