Skip to content

Commit

Permalink
Fix pythonfinder path search nesting bug
Browse files Browse the repository at this point in the history
- Fixes #3121

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed Oct 29, 2018
1 parent 912d9c5 commit b41bcfd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/3121.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated ``pythonfinder`` to correct an issue with unnesting of nested paths when searching for python versions.
1 change: 1 addition & 0 deletions news/3121.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated ``pythonfinder`` to correct an issue with unnesting of nested paths when searching for python versions.
24 changes: 21 additions & 3 deletions pipenv/vendor/pythonfinder/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function

import itertools
import locale
import os
import subprocess
Expand All @@ -21,6 +22,9 @@
except ImportError:
from backports.functools_lru_cache import lru_cache

six.add_move(six.MovedAttribute("Iterable", "collections", "collections.abc"))
from six.moves import Iterable


PYTHON_IMPLEMENTATIONS = (
"python", "ironpython", "jython", "pypy", "anaconda", "miniconda",
Expand Down Expand Up @@ -123,7 +127,21 @@ def filter_pythons(path):
return filter(lambda x: path_is_python(x), path.iterdir())


# def unnest(item):
# if isinstance(next((i for i in item), None), (list, tuple)):
# return chain(*filter(None, item))
# return chain(filter(None, item))


def unnest(item):
if isinstance(next((i for i in item), None), (list, tuple)):
return chain(*filter(None, item))
return chain(filter(None, item))
if isinstance(item, Iterable) and not isinstance(item, six.string_types):
item, target = itertools.tee(item, 2)
else:
target = item
for el in target:
if isinstance(el, Iterable) and not isinstance(el, six.string_types):
el, el_copy = itertools.tee(el, 2)
for sub in unnest(el_copy):
yield sub
else:
yield el

0 comments on commit b41bcfd

Please sign in to comment.