Skip to content

Commit

Permalink
Finish updating vendored deps
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Ryan <[email protected]>

Update delegator patch

Signed-off-by: Dan Ryan <[email protected]>

Update patches for pip

Signed-off-by: Dan Ryan <[email protected]>

Update vendored deps

Signed-off-by: Dan Ryan <[email protected]>

Update patches

Signed-off-by: Dan Ryan <[email protected]>

Fix imports to use pip shims instead of direct imports

Signed-off-by: Dan Ryan <[email protected]>

Update vendoring scripts and pip shims

Signed-off-by: Dan Ryan <[email protected]>

Log to stdout in real time during verbose logging

Signed-off-by: Dan Ryan <[email protected]>

Don’t log environment

Fix unicode decoding issues

Signed-off-by: Dan Ryan <[email protected]>

Only set buffers on ttys

Signed-off-by: Dan Ryan <[email protected]>

Fix typo

Signed-off-by: Dan Ryan <[email protected]>

Use default encodings

Signed-off-by: Dan Ryan <[email protected]>

Fix encodings and run only failing tests

Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Oct 30, 2018
1 parent b8db36e commit 0cefb5e
Show file tree
Hide file tree
Showing 114 changed files with 3,362 additions and 2,258 deletions.
4 changes: 2 additions & 2 deletions .vsts-ci/steps/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ steps:
pip install certifi
python -m certifi > cacert.txt
Write-Host "##vso[task.setvariable variable=GIT_SSL_CAINFO]$(Get-Content cacert.txt)"
$env:GIT_SSL_CAINFO="$(Get-Content cacert.txt)"
# Shorten paths to get under MAX_PATH or else integration tests will fail
# https://bugs.python.org/issue18199
subst T: "$env:TEMP"
Write-Host "##vso[task.setvariable variable=TEMP]T:\"
$env:TEMP='T:\'
Write-Host "##vso[task.setvariable variable=TMP]T:\"
$env:TEMP='T:\'
Get-ChildItem Env:
D:\.venv\Scripts\pipenv run pytest -n 4 -ra --ignore=pipenv\patched --ignore=pipenv\vendor --junitxml=test-results.xml tests
D:\.venv\Scripts\pipenv run pytest -ra --ignore=pipenv\patched --ignore=pipenv\vendor -k 'test_get_vcs_refs or test_install_editable_git_tag' --junitxml=test-results.xml tests
displayName: Run integration tests

- task: PublishTestResults@2
Expand Down
20 changes: 19 additions & 1 deletion pipenv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# -*- coding=utf-8 -*-
# |~~\' |~~
# |__/||~~\|--|/~\\ /
# | ||__/|__| |\/
# |

import os
import sys
import warnings

from .__version__ import __version__

PIPENV_ROOT = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -13,14 +17,28 @@
sys.path.insert(0, PIPENV_VENDOR)
# Inject patched directory into system path.
sys.path.insert(0, PIPENV_PATCHED)
from vistir.compat import fs_str

from pipenv.vendor.urllib3.exceptions import DependencyWarning
from pipenv.vendor.vistir.compat import ResourceWarning, fs_str
warnings.filterwarnings("ignore", category=DependencyWarning)
warnings.filterwarnings("ignore", category=ResourceWarning)

if sys.version_info >= (3, 1) and sys.version_info <= (3, 6):
if sys.stdout.isatty() and sys.stderr.isatty():
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf8')

os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = fs_str("1")
os.environ["PIP_SHIMS_BASE_MODULE"] = fs_str("pipenv.patched.notpip")

# Hack to make things work better.
try:
if "concurrency" in sys.modules:
del sys.modules["concurrency"]
except Exception:
pass

from .cli import cli
from . import resolver

Expand Down
76 changes: 76 additions & 0 deletions pipenv/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,79 @@ def NamedTemporaryFile(
os.unlink(name)
os.close(fd)
raise


def getpreferredencoding():
import locale
# Borrowed from Invoke
# (see https://github.com/pyinvoke/invoke/blob/93af29d/invoke/runners.py#L881)
_encoding = locale.getpreferredencoding(False)
if six.PY2 and not sys.platform == "win32":
_default_encoding = locale.getdefaultlocale()[1]
if _default_encoding is not None:
_encoding = _default_encoding
return _encoding


DEFAULT_ENCODING = getpreferredencoding()


# From https://github.com/CarlFK/veyepar/blob/5c5de47/dj/scripts/fixunicode.py
# MIT LIcensed, thanks Carl!
def force_encoding():
try:
stdout_isatty = sys.stdout.isatty
stderr_isatty = sys.stderr.isatty
except AttributeError:
return DEFAULT_ENCODING, DEFAULT_ENCODING
else:
if not (stdout_isatty() and stderr_isatty()):
return DEFAULT_ENCODING, DEFAULT_ENCODING
stdout_encoding = sys.stdout.encoding
stderr_encoding = sys.stderr.encoding
if sys.platform == "win32" and sys.version_info >= (3, 1):
return DEFAULT_ENCODING, DEFAULT_ENCODING
if stdout_encoding.lower() != "utf-8" or stderr_encoding.lower() != "utf-8":

from ctypes import pythonapi, py_object, c_char_p
try:
PyFile_SetEncoding = pythonapi.PyFile_SetEncoding
except AttributeError:
return DEFAULT_ENCODING, DEFAULT_ENCODING
else:
PyFile_SetEncoding.argtypes = (py_object, c_char_p)
if stdout_encoding.lower() != "utf-8":
try:
was_set = PyFile_SetEncoding(sys.stdout, "utf-8")
except OSError:
was_set = False
if not was_set:
stdout_encoding = DEFAULT_ENCODING
else:
stdout_encoding = "utf-8"

if stderr_encoding.lower() != "utf-8":
try:
was_set = PyFile_SetEncoding(sys.stderr, "utf-8")
except OSError:
was_set = False
if not was_set:
stderr_encoding = DEFAULT_ENCODING
else:
stderr_encoding = "utf-8"

return stdout_encoding, stderr_encoding


OUT_ENCODING, ERR_ENCODING = force_encoding()


def decode_output(output):
if not isinstance(output, six.string_types):
return output
try:
output = output.encode(DEFAULT_ENCODING)
except AttributeError:
pass
output = output.decode(DEFAULT_ENCODING)
return output
19 changes: 10 additions & 9 deletions pipenv/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding=utf-8 -*-

import contextlib
import logging
import os
Expand Down Expand Up @@ -105,9 +106,13 @@
def fix_utf8(text):
if not isinstance(text, six.string_types):
return text
if six.PY2:
text = unicode.translate(vistir.misc.to_text(text), UNICODE_TO_ASCII_TRANSLATION_MAP)
return u"{0}".format(text)
from ._compat import decode_output
try:
text = decode_output(text)
except UnicodeDecodeError:
if six.PY2:
text = unicode.translate(vistir.misc.to_text(text), UNICODE_TO_ASCII_TRANSLATION_MAP)
return text


@contextlib.contextmanager
Expand Down Expand Up @@ -230,7 +235,7 @@ def cleanup_virtualenv(bare=True):

def import_requirements(r=None, dev=False):
from .patched.notpip._vendor import requests as pip_requests
from .patched.notpip._internal.req.req_file import parse_requirements
from .vendor.pip_shims.shims import parse_requirements

# Parse requirements.txt file with Pip's parser.
# Pip requires a `PipSession` which is a subclass of requests.Session.
Expand Down Expand Up @@ -1754,7 +1759,7 @@ def do_install(
selective_upgrade=False,
):
from .environments import PIPENV_VIRTUALENV, PIPENV_USE_SYSTEM
from notpip._internal.exceptions import PipError
from .vendor.pip_shims.shims import PipError

requirements_directory = vistir.path.create_tracked_tempdir(
suffix="-requirements", prefix="pipenv-"
Expand Down Expand Up @@ -2212,10 +2217,6 @@ def _launch_windows_subprocess(script):

command = system_which(script.command)
options = {"universal_newlines": True}
env_strings = [
vistir.compat.to_native_string("{0}: {1}".format(k, v)) for k, v in os.environ.items()
]
click.echo(vistir.compat.to_native_string("\n".join(env_strings)), err=True)

# Command not found, maybe this is a shell built-in?
if not command:
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/notpip/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "18.0"
__version__ = "18.1"
Loading

0 comments on commit 0cefb5e

Please sign in to comment.