Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump vistir and requirementslib #5635

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5635.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump vistir to 0.8.0, requirementslib to 2.2.4.
2 changes: 1 addition & 1 deletion pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pipenv.vendor.requirementslib import Requirement
from pipenv.vendor.requirementslib.models.requirements import Line
from pipenv.vendor.requirementslib.models.utils import DIRECT_URL_RE
from pipenv.vendor.vistir import open_file
from pipenv.vendor.vistir.contextmanagers import open_file
from pipenv.vendor.vistir.path import create_tracked_tempdir

try:
Expand Down
2 changes: 1 addition & 1 deletion pipenv/vendor/requirementslib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .models.pipfile import Pipfile
from .models.requirements import Requirement

__version__ = "2.2.3"
__version__ = "2.2.4"


logger = logging.getLogger(__name__)
Expand Down
77 changes: 77 additions & 0 deletions pipenv/vendor/requirementslib/funktools.py
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))
4 changes: 2 additions & 2 deletions pipenv/vendor/requirementslib/models/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from pipenv.patched.pip._vendor.packaging.utils import canonicalize_name
from pipenv.patched.pip._vendor.packaging.version import parse
from pipenv.vendor.vistir.contextmanagers import temp_path
from pipenv.vendor.vistir.misc import dedup
from pipenv.vendor.vistir.path import (
create_tracked_tempdir,
get_converted_relative_path,
Expand All @@ -43,6 +42,7 @@

from ..environment import MYPY_RUNNING
from ..exceptions import RequirementError
from ..funktools import dedup
from ..utils import (
VCS_LIST,
add_ssh_scheme_to_git_uri,
Expand Down Expand Up @@ -213,7 +213,7 @@ def get_line(
line = self.line
extras_str = extras_to_string(self.extras)
with_hashes = False if self.editable or self.is_vcs else with_hashes
hash_list = ["--hash={0}".format(h) for h in self.hashes]
hash_list = ["--hash={0}".format(h) for h in sorted(self.hashes)]
if self.is_named:
line = self.name_and_specifier
elif self.is_direct_url:
Expand Down
4 changes: 2 additions & 2 deletions pipenv/vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ptyprocess==0.7.0
pyparsing==3.0.9
python-dotenv==0.19.0
pythonfinder==1.3.2
requirementslib==2.2.3
requirementslib==2.2.4
ruamel.yaml==0.17.21
shellingham==1.5.0
toml==0.10.2
tomlkit==0.9.2
vistir==0.7.5
vistir==0.8.0
41 changes: 1 addition & 40 deletions pipenv/vendor/vistir/__init__.py
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"
81 changes: 0 additions & 81 deletions pipenv/vendor/vistir/contextmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"cd",
"atomic_open_for_write",
"open_file",
"spinner",
"dummy_spinner",
"replaced_stream",
"replaced_streams",
]
Expand Down Expand Up @@ -127,85 +125,6 @@ def cd(path):
os.chdir(prev_cwd)


@contextmanager
def dummy_spinner(spin_type, text, **kwargs):
# type: (str, str, Any)
class FakeClass(object):
def __init__(self, text=""):
self.text = text

def fail(self, exitcode=1, text=None):
if text:
print(text)
raise SystemExit(exitcode, text)

def ok(self, text):
print(text)
return 0

def write(self, text):
print(text)

myobj = FakeClass(text)
yield myobj


@contextmanager
def spinner(
spinner_name=None, # type: Optional[str]
start_text=None, # type: Optional[str]
handler_map=None, # type: Optional[Dict[str, Callable]]
nospin=False, # type: bool
write_to_stdout=True, # type: bool
):
# type: (...) -> ContextManager[TSpinner]
"""Get a spinner object or a dummy spinner to wrap a context.

:param str spinner_name: A spinner type e.g. "dots" or "bouncingBar" (default: {"bouncingBar"})
:param str start_text: Text to start off the spinner with (default: {None})
:param dict handler_map: Handler map for signals to be handled gracefully (default: {None})
:param bool nospin: If true, use the dummy spinner (default: {False})
:param bool write_to_stdout: Writes to stdout if true, otherwise writes to stderr (default: True)
:return: A spinner object which can be manipulated while alive
:rtype: :class:`~vistir.spin.VistirSpinner`

Raises:
RuntimeError -- Raised if the spinner extra is not installed
"""

from .spin import create_spinner

has_yaspin = None
try:
import yaspin
except (ImportError, ModuleNotFoundError): # noqa
has_yaspin = False
if not nospin:
raise RuntimeError(
"Failed to import spinner! Reinstall vistir with command:"
" pip install --upgrade vistir[spinner]"
)
else:
spinner_name = ""
else:
has_yaspin = True
spinner_name = ""
use_yaspin = (has_yaspin is False) or (nospin is True)
if has_yaspin is None or has_yaspin is True and not nospin:
use_yaspin = True
if start_text is None and use_yaspin is True:
start_text = "Running..."
with create_spinner(
spinner_name=spinner_name,
text=start_text,
handler_map=handler_map,
nospin=nospin,
use_yaspin=use_yaspin,
write_to_stdout=write_to_stdout,
) as _spinner:
yield _spinner


@contextmanager
def atomic_open_for_write(target, binary=False, newline=None, encoding=None):
# type: (str, bool, Optional[str], Optional[str]) -> None
Expand Down