From e993ee874dfb2579a30de0cdcbdc616a77a287a1 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 27 May 2018 13:52:39 -0400 Subject: [PATCH] Use filesystem compatible encodings for strings Signed-off-by: Dan Ryan --- pipenv/_compat.py | 7 +++++-- pipenv/core.py | 18 +++++++++++------- pipenv/utils.py | 19 ++++++++++++++++--- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/pipenv/_compat.py b/pipenv/_compat.py index 8ccf025a..68d8069d 100644 --- a/pipenv/_compat.py +++ b/pipenv/_compat.py @@ -29,6 +29,11 @@ except ImportError: _types.add(type(arg)) return _types.pop() +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path + try: from weakref import finalize @@ -51,8 +56,6 @@ if six.PY2: class ResourceWarning(Warning): pass -# -*- coding=utf-8 -*- - def pip_import(module_path, subimport=None, old_path=None): internal = 'pip._internal.{0}'.format(module_path) diff --git a/pipenv/core.py b/pipenv/core.py index f8d03b9e..a14d85bd 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -46,10 +46,12 @@ from .utils import ( rmtree, split_argument, extract_uri_from_vcs_dep, + fs_str, ) from ._compat import ( TemporaryDirectory, - vcs + vcs, + Path ) from .import pep508checker, progress from .environments import ( @@ -1495,20 +1497,22 @@ def pip_install( ) if verbose: click.echo('$ {0}'.format(pip_command), err=True) + cache_dir = Path(PIPENV_CACHE_DIR) pip_config = { - 'PIP_CACHE_DIR': PIPENV_CACHE_DIR, - 'PIP_WHEEL_DIR': os.path.join(PIPENV_CACHE_DIR, 'wheels'), - 'PIP_DESTINATION_DIR': os.path.join(PIPENV_CACHE_DIR, 'pkgs'), + 'PIP_CACHE_DIR': fs_str(cache_dir.as_posix()), + 'PIP_WHEEL_DIR': fs_str(cache_dir.joinpath('wheels').as_posix()), + 'PIP_DESTINATION_DIR': fs_str(cache_dir.joinpath('pkgs').as_posix()), } c = delegator.run(pip_command, block=block, env=pip_config) return c def pip_download(package_name): + cache_dir = Path(PIPENV_CACHE_DIR) pip_config = { - 'PIP_CACHE_DIR': PIPENV_CACHE_DIR, - 'PIP_WHEEL_DIR': os.path.join(PIPENV_CACHE_DIR, 'wheels'), - 'PIP_DESTINATION_DIR': os.path.join(PIPENV_CACHE_DIR, 'pkgs'), + 'PIP_CACHE_DIR': fs_str(cache_dir.as_posix()), + 'PIP_WHEEL_DIR': fs_str(cache_dir.joinpath('wheels').as_posix()), + 'PIP_DESTINATION_DIR': fs_str(cache_dir.joinpath('pkgs').as_posix()), } for source in project.sources: cmd = '{0} download "{1}" -i {2} -d {3}'.format( diff --git a/pipenv/utils.py b/pipenv/utils.py index e084d6c1..051123d6 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -1189,10 +1189,9 @@ def get_vcs_deps( lockfiles.append({pipfile_name: installed.pipfile_entry[1]}) pipfile_srcdir = escape_grouped_arguments((src_dir / pipfile_name).as_posix()) lockfile_srcdir = escape_grouped_arguments( - (src_dir / installed.normalized_name).as_posix() - ) + (src_dir / installed.normalized_name)) lines.append(line) - if pipfile_srcdir.exists(): + if os.path.exists(pipfile_srcdir): lockfiles.extend( venv_resolve_deps( ["-e {0}".format(pipfile_srcdir)], @@ -1217,3 +1216,17 @@ def get_vcs_deps( ) ) return lines, lockfiles + + +def fs_str(string): + """Encodes a string into the proper filesystem encoding + + Borrowed from pip-tools + """ + if isinstance(string, str): + return string + assert not isinstance(string, bytes) + return string.encode(_fs_encoding) + + +_fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()