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

More vendor bumps #5522

Merged
merged 7 commits into from
Dec 7, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions news/5522.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Bump version of requirementslib to 2.2.1
* Bump version of vistir to 0.7.5
* Bump version of colorama to 0.4.6
27 changes: 16 additions & 11 deletions pipenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,26 @@
if "urllib3" in sys.modules:
del sys.modules["urllib3"]

from pipenv.vendor.vistir.misc import get_text_stream

stdout = get_text_stream("stdout")
stderr = get_text_stream("stderr")

if os.name == "nt":
from pipenv.vendor.vistir.misc import _can_use_color, _wrap_for_color
from pipenv.vendor import colorama

if _can_use_color(stdout):
stdout = _wrap_for_color(stdout)
if _can_use_color(stderr):
stderr = _wrap_for_color(stderr)
# Backward compatability with vistir
no_color = False
for item in ("ANSI_COLORS_DISABLED", "VISTIR_DISABLE_COLORS", "CI"):
warnings.warn(
(
f"Please do not use {item}, as it will be removed in future versions."
"\nUse NO_COLOR instead."
),
DeprecationWarning,
stacklevel=2,
)
if os.getenv(item):
no_color = True

sys.stdout = stdout
sys.stderr = stderr
if not os.getenv("NO_COLOR") or no_color:
colorama.just_fix_windows_console()

from . import resolver # noqa
from .cli import cli
Expand Down
5 changes: 3 additions & 2 deletions pipenv/vendor/colorama/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
from .initialise import init, deinit, reinit, colorama_text
from .initialise import init, deinit, reinit, colorama_text, just_fix_windows_console
from .ansi import Fore, Back, Style, Cursor
from .ansitowin32 import AnsiToWin32

__version__ = '0.4.4'
__version__ = '0.4.6'

27 changes: 23 additions & 4 deletions pipenv/vendor/colorama/ansitowin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os

from .ansi import AnsiFore, AnsiBack, AnsiStyle, Style, BEL
from .winterm import WinTerm, WinColor, WinStyle
from .winterm import enable_vt_processing, WinTerm, WinColor, WinStyle
from .win32 import windll, winapi_test


Expand Down Expand Up @@ -37,6 +37,12 @@ def __enter__(self, *args, **kwargs):
def __exit__(self, *args, **kwargs):
return self.__wrapped.__exit__(*args, **kwargs)

def __setstate__(self, state):
self.__dict__ = state

def __getstate__(self):
return self.__dict__

def write(self, text):
self.__convertor.write(text)

Expand All @@ -57,7 +63,9 @@ def closed(self):
stream = self.__wrapped
try:
return stream.closed
except AttributeError:
# AttributeError in the case that the stream doesn't support being closed
# ValueError for the case that the stream has already been detached when atexit runs
except (AttributeError, ValueError):
return True


Expand Down Expand Up @@ -86,15 +94,22 @@ def __init__(self, wrapped, convert=None, strip=None, autoreset=False):
# (e.g. Cygwin Terminal). In this case it's up to the terminal
# to support the ANSI codes.
conversion_supported = on_windows and winapi_test()
try:
fd = wrapped.fileno()
except Exception:
fd = -1
system_has_native_ansi = not on_windows or enable_vt_processing(fd)
have_tty = not self.stream.closed and self.stream.isatty()
need_conversion = conversion_supported and not system_has_native_ansi

# should we strip ANSI sequences from our output?
if strip is None:
strip = conversion_supported or (not self.stream.closed and not self.stream.isatty())
strip = need_conversion or not have_tty
self.strip = strip

# should we should convert ANSI sequences into win32 calls?
if convert is None:
convert = conversion_supported and not self.stream.closed and self.stream.isatty()
convert = need_conversion and have_tty
self.convert = convert

# dict of ansi codes to win32 functions and parameters
Expand Down Expand Up @@ -256,3 +271,7 @@ def convert_osc(self, text):
if params[0] in '02':
winterm.set_title(params[1])
return text


def flush(self):
self.wrapped.flush()
51 changes: 46 additions & 5 deletions pipenv/vendor/colorama/initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@
from .ansitowin32 import AnsiToWin32


orig_stdout = None
orig_stderr = None
def _wipe_internal_state_for_tests():
global orig_stdout, orig_stderr
orig_stdout = None
orig_stderr = None

global wrapped_stdout, wrapped_stderr
wrapped_stdout = None
wrapped_stderr = None

wrapped_stdout = None
wrapped_stderr = None
global atexit_done
atexit_done = False

global fixed_windows_console
fixed_windows_console = False

atexit_done = False
try:
# no-op if it wasn't registered
atexit.unregister(reset_all)
except AttributeError:
# python 2: no atexit.unregister. Oh well, we did our best.
pass


def reset_all():
Expand Down Expand Up @@ -55,6 +69,29 @@ def deinit():
sys.stderr = orig_stderr


def just_fix_windows_console():
global fixed_windows_console

if sys.platform != "win32":
return
if fixed_windows_console:
return
if wrapped_stdout is not None or wrapped_stderr is not None:
# Someone already ran init() and it did stuff, so we won't second-guess them
return

# On newer versions of Windows, AnsiToWin32.__init__ will implicitly enable the
# native ANSI support in the console as a side-effect. We only need to actually
# replace sys.stdout/stderr if we're in the old-style conversion mode.
new_stdout = AnsiToWin32(sys.stdout, convert=None, strip=None, autoreset=False)
if new_stdout.convert:
sys.stdout = new_stdout
new_stderr = AnsiToWin32(sys.stderr, convert=None, strip=None, autoreset=False)
if new_stderr.convert:
sys.stderr = new_stderr

fixed_windows_console = True

@contextlib.contextmanager
def colorama_text(*args, **kwargs):
init(*args, **kwargs)
Expand All @@ -78,3 +115,7 @@ def wrap_stream(stream, convert, strip, autoreset, wrap):
if wrapper.should_wrap():
stream = wrapper.stream
return stream


# Use this for initial setup as well, to reduce code duplication
_wipe_internal_state_for_tests()
28 changes: 28 additions & 0 deletions pipenv/vendor/colorama/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
STDOUT = -11
STDERR = -12

ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004

try:
import ctypes
from ctypes import LibraryLoader
Expand Down Expand Up @@ -89,6 +91,20 @@ def __str__(self):
]
_SetConsoleTitleW.restype = wintypes.BOOL

_GetConsoleMode = windll.kernel32.GetConsoleMode
_GetConsoleMode.argtypes = [
wintypes.HANDLE,
POINTER(wintypes.DWORD)
]
_GetConsoleMode.restype = wintypes.BOOL

_SetConsoleMode = windll.kernel32.SetConsoleMode
_SetConsoleMode.argtypes = [
wintypes.HANDLE,
wintypes.DWORD
]
_SetConsoleMode.restype = wintypes.BOOL

def _winapi_test(handle):
csbi = CONSOLE_SCREEN_BUFFER_INFO()
success = _GetConsoleScreenBufferInfo(
Expand Down Expand Up @@ -150,3 +166,15 @@ def FillConsoleOutputAttribute(stream_id, attr, length, start):

def SetConsoleTitle(title):
return _SetConsoleTitleW(title)

def GetConsoleMode(handle):
mode = wintypes.DWORD()
success = _GetConsoleMode(handle, byref(mode))
if not success:
raise ctypes.WinError()
return mode.value

def SetConsoleMode(handle, mode):
success = _SetConsoleMode(handle, mode)
if not success:
raise ctypes.WinError()
28 changes: 27 additions & 1 deletion pipenv/vendor/colorama/winterm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Copyright Jonathan Hartley 2013. BSD 3-Clause license, see LICENSE file.
from . import win32
try:
from msvcrt import get_osfhandle
except ImportError:
def get_osfhandle(_):
raise OSError("This isn't windows!")


from . import win32

# from wincon.h
class WinColor(object):
Expand Down Expand Up @@ -167,3 +173,23 @@ def erase_line(self, mode=0, on_stderr=False):

def set_title(self, title):
win32.SetConsoleTitle(title)


def enable_vt_processing(fd):
if win32.windll is None or not win32.winapi_test():
return False

try:
handle = get_osfhandle(fd)
mode = win32.GetConsoleMode(handle)
win32.SetConsoleMode(
handle,
mode | win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING,
)

mode = win32.GetConsoleMode(handle)
if mode & win32.ENABLE_VIRTUAL_TERMINAL_PROCESSING:
return True
# Can get TypeError in testsuite where 'fd' is a Mock()
except (OSError, TypeError):
return False
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.0"
__version__ = "2.2.1"


logger = logging.getLogger(__name__)
Expand Down
33 changes: 9 additions & 24 deletions pipenv/vendor/requirementslib/models/setup_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import contextlib
import os
import shutil
import subprocess as sp
import sys
from collections.abc import Iterable, Mapping
from contextlib import ExitStack
Expand All @@ -30,7 +31,6 @@
)
from pipenv.patched.pip._vendor.platformdirs import user_cache_dir
from pipenv.vendor.vistir.contextmanagers import cd, temp_path
from pipenv.vendor.vistir.misc import run
from pipenv.vendor.vistir.path import create_tracked_tempdir, rmtree

from ..environment import MYPY_RUNNING
Expand Down Expand Up @@ -94,16 +94,8 @@ def pep517_subprocess_runner(cmd, cwd=None, extra_environ=None):
if extra_environ:
env.update(extra_environ)

run(
cmd,
cwd=cwd,
env=env,
block=True,
combine_stderr=True,
return_object=False,
write_to_stdout=False,
nospin=True,
)
cmd_as_str = " ".join(cmd)
sp.run(cmd_as_str, cwd=cwd, env=env, stdout=sp.PIPE, stderr=sp.STDOUT, shell=True)


class BuildEnv(envbuild.BuildEnvironment):
Expand All @@ -117,14 +109,8 @@ def pip_install(self, reqs):
"--prefix",
self.path,
] + list(reqs)
run(
cmd,
block=True,
combine_stderr=True,
return_object=False,
write_to_stdout=False,
nospin=True,
)

sp.run(cmd, shell=True, stderr=sp.PIPE, stdout=sp.PIPE)


class HookCaller(wrappers.Pep517HookCaller):
Expand Down Expand Up @@ -892,13 +878,12 @@ def run_setup(script_path, egg_base=None):
# We couldn't import everything needed to run setup
except Exception:
python = os.environ.get("PIP_PYTHON_PATH", sys.executable)
out, _ = run(

sp.run(
[python, "setup.py"] + args,
cwd=target_cwd,
block=True,
combine_stderr=False,
return_object=False,
nospin=True,
stdout=sp.PIPE,
stderr=sp.PIPE,
)
finally:
_setup_stop_after = None
Expand Down
6 changes: 3 additions & 3 deletions pipenv/vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ attrs==22.1.0
cerberus==1.3.4
click-didyoumean==0.0.3
click==8.0.3
colorama==0.4.4
colorama==0.4.6
dparse==0.6.2
markupsafe==2.0.1
pexpect==4.8.0
Expand All @@ -12,9 +12,9 @@ ptyprocess==0.7.0
pyparsing==3.0.9
python-dotenv==0.19.0
pythonfinder==1.3.1
requirementslib==2.2.0
requirementslib==2.2.1
ruamel.yaml==0.17.21
shellingham==1.5.0
toml==0.10.2
tomlkit==0.9.2
vistir==0.7.4
vistir==0.7.5
Loading