Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5635 from pypa/bump-vistir-0.8.0
Bump vistir and requirementslib
- Loading branch information
Showing
9 changed files
with
105 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Bump vistir to 0.8.0, requirementslib to 2.2.4. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"""A small collection of useful functional tools for working with iterables. | ||
unnest, chunked and take are used by pipenv. However, since pipenv | ||
relies on requirementslib, we can them here. | ||
""" | ||
from functools import partial | ||
from itertools import islice, tee | ||
from typing import Any, Iterable | ||
|
||
|
||
def _is_iterable(elem: Any) -> bool: | ||
if getattr(elem, "__iter__", False) or isinstance(elem, Iterable): | ||
return True | ||
return False | ||
|
||
|
||
def take(n: int, iterable: Iterable) -> Iterable: | ||
"""Take n elements from the supplied iterable without consuming it. | ||
:param int n: Number of unique groups | ||
:param iter iterable: An iterable to split up | ||
""" | ||
return list(islice(iterable, n)) | ||
|
||
|
||
def chunked(n: int, iterable: Iterable) -> Iterable: | ||
"""Split an iterable into lists of length *n*. | ||
:param int n: Number of unique groups | ||
:param iter iterable: An iterable to split up | ||
""" | ||
return iter(partial(take, n, iter(iterable)), []) | ||
|
||
|
||
def unnest(elem: Iterable) -> Any: | ||
# type: (Iterable) -> Any | ||
"""Flatten an arbitrarily nested iterable. | ||
:param elem: An iterable to flatten | ||
:type elem: :class:`~collections.Iterable` | ||
>>> nested_iterable = ( | ||
1234, (3456, 4398345, (234234)), ( | ||
2396, ( | ||
928379, 29384, ( | ||
293759, 2347, ( | ||
2098, 7987, 27599 | ||
) | ||
) | ||
) | ||
) | ||
) | ||
>>> list(unnest(nested_iterable)) | ||
[1234, 3456, 4398345, 234234, 2396, 928379, 29384, 293759, | ||
2347, 2098, 7987, 27599] | ||
""" | ||
|
||
if isinstance(elem, Iterable) and not isinstance(elem, str): | ||
elem, target = tee(elem, 2) | ||
else: | ||
target = elem | ||
if not target or not _is_iterable(target): | ||
yield target | ||
else: | ||
for el in target: | ||
if isinstance(el, Iterable) and not isinstance(el, str): | ||
el, el_copy = tee(el, 2) | ||
for sub in unnest(el_copy): | ||
yield sub | ||
else: | ||
yield el | ||
|
||
|
||
def dedup(iterable: Iterable) -> Iterable: | ||
# type: (Iterable) -> Iterable | ||
"""Deduplicate an iterable object like iter(set(iterable)) but order- | ||
preserved.""" | ||
return iter(dict.fromkeys(iterable)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,3 @@ | ||
# -*- coding=utf-8 -*- | ||
import importlib | ||
|
||
__newpaths = { | ||
'create_spinner': 'vistir.spin', | ||
'cd': 'vistir.contextmanagers', | ||
'atomic_open_for_write': 'vistir.contextmanagers', | ||
'open_file': 'vistir.contextmanagers', | ||
'replaced_stream': 'vistir.contextmanagers', | ||
'replaced_streams': 'vistir.contextmanagers', | ||
'spinner': 'vistir.contextmanagers', | ||
'temp_environ': 'vistir.contextmanagers', | ||
'temp_path': 'vistir.contextmanagers', | ||
'hide_cursor': 'vistir.cursor', | ||
'show_cursor': 'vistir.cursor', | ||
'StreamWrapper': 'vistir.misc', | ||
'chunked':'vistir.misc', | ||
'decode_for_output': 'vistir.misc', | ||
'divide': 'vistir.misc', | ||
'get_wrapped_stream': 'vistir.misc', | ||
'load_path': 'vistir.misc', | ||
'partialclass': 'vistir.misc', | ||
'run': 'vistir.misc', | ||
'shell_escape': 'vistir.misc', | ||
'take': 'vistir.misc', | ||
'to_bytes': 'vistir.misc', | ||
'to_text': 'vistir.misc', | ||
'create_tracked_tempdir': 'vistir.path', | ||
'create_tracked_tempfile': 'vistir.path', | ||
'mkdir_p': 'vistir.path', | ||
'rmtree': 'vistir.path', | ||
} | ||
|
||
from warnings import warn | ||
|
||
def __getattr__(name): | ||
warn((f"Importing {name} directly from vistir is deprecated.\nUse 'from {__newpaths[name]} import {name}' instead.\n" | ||
"This import path will be removed in vistir 0.8"), | ||
DeprecationWarning) | ||
return getattr(importlib.import_module(__newpaths[name]), name) | ||
|
||
__version__ = "0.7.5" | ||
__version__ = "0.8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.