Skip to content

Commit

Permalink
Fix VCS installs
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Jun 25, 2019
1 parent 1d79bbf commit ce7cd8e
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 226 deletions.
36 changes: 10 additions & 26 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ def batch_install(deps_list, procs, failed_deps_queue,
os.environ["PIP_USER"] = vistir.compat.fs_str("0")
if "PYTHONHOME" in os.environ:
del os.environ["PYTHONHOME"]
if "GIT_CONFIG" in os.environ and dep.is_vcs:
del os.environ["GIT_CONFIG"]

c = pip_install(
dep,
Expand Down Expand Up @@ -1379,20 +1381,7 @@ def get_requirement_line(
requirement.line_instance._wheel_kwargs.update({
"src_dir": src_dir
})
# if requirement.vcs and requirement.editable:
# repo = requirement.req.get_vcs_repo(src_dir=src_dir)
# requirement.line_instance.vcsrepo
# line = repo.url
# name = requirement.name
# line = "{0}+".format(requirement.vcs) if requirement.vcs else ""
# if requirement.extras:
# name = "{0}{1}".format(name, requirement.extras_as_pip)
# line = "{0}{1}#egg={2}".format(
# line, vistir.path.path_to_url(repo.checkout_directory), requirement.name
# )
# if repo.subdirectory:
# line = "{0}&subdirectory={1}".format(line, repo.subdirectory)
# else:
requirement.line_instance.vcsrepo
line = requirement.line_instance.line
if requirement.line_instance.markers:
line = '{0}; {1}'.format(line, requirement.line_instance.markers)
Expand All @@ -1418,8 +1407,8 @@ def write_requirement_to_file(
if not requirements_dir:
requirements_dir = vistir.path.create_tracked_tempdir(
prefix="pipenv", suffix="requirements")
line = get_requirement_line(
requirement, src_dir, include_hashes=include_hashes, format_for_file=True
line = requirement.line_instance.get_line(
with_prefix=True, with_hashes=include_hashes, with_markers=True, as_list=False
)

f = vistir.compat.NamedTemporaryFile(
Expand Down Expand Up @@ -1470,8 +1459,10 @@ def pip_install(
elif not (requirement.is_vcs or requirement.editable or requirement.vcs):
ignore_hashes = False
line = None
if requirement.vcs and not requirement.line_instance.markers:
line = get_requirement_line(requirement, src_dir, include_hashes=not ignore_hashes, format_for_file=False)
if requirement.vcs:
line = requirement.line_instance.get_line(
with_prefix=True, with_hashes=False, with_markers=True, as_list=True
)
else:
r = write_requirement_to_file(
requirement, requirements_dir=requirements_dir, src_dir=src_dir,
Expand Down Expand Up @@ -1541,6 +1532,7 @@ def pip_install(
pip_command = cmd.cmdify()
c = None
c = delegator.run(pip_command, block=block, env=pip_config)
c.env = pip_config
return c


Expand Down Expand Up @@ -2109,14 +2101,6 @@ def do_install(
sys.exit(1)
if index_url:
pkg_requirement.index = index_url
# deps = []
# if pkg_requirement.is_vcs and PIPENV_RESOLVE_VCS:
# if not allow_global and (
# pkg_requirement.line_instance and pkg_requirement.line_instance.wheel_kwargs
# ):
# pkg_requirement.line_instance._wheel_kwargs["src_dir"] = project.virtualenv_src_location
# pkg_setupinfo = pkg_requirement.line_instance.setup_info
# deps = pkg_setupinfo.requires
no_deps = False
sp.text = "Installing..."
try:
Expand Down
1 change: 1 addition & 0 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def get_deps_from_req(cls, req, resolver=None):
from .vendor.requirementslib.models.utils import _requirement_to_str_lowercase_name
from .vendor.requirementslib.models.requirements import Requirement
from requirementslib.utils import is_installable_dir
# TODO: this is way too complex, refactor this
constraints = set() # type: Set[str]
locked_deps = dict() # type: Dict[str, Dict[str, Union[str, bool, List[str]]]]
if (req.is_file_or_url or req.is_vcs) and not req.is_wheel:
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 @@ -10,7 +10,7 @@
from .models.pipfile import Pipfile
from .models.requirements import Requirement

__version__ = "1.5.1"
__version__ = "1.5.2.dev0"


logger = logging.getLogger(__name__)
Expand Down
80 changes: 49 additions & 31 deletions pipenv/vendor/requirementslib/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import errno
import os
import six
import sys


import six
from vistir.compat import FileNotFoundError


if six.PY2:

class FileExistsError(OSError):
def __init__(self, *args, **kwargs):
self.errno = errno.EEXIST
super(FileExistsError, self).__init__(*args, **kwargs)


else:
from six.moves.builtins import FileExistsError

Expand All @@ -24,8 +26,15 @@ class RequirementError(Exception):

class MissingParameter(Exception):
def __init__(self, param):
Exception.__init__(self)
print("Missing parameter: %s" % param, file=sys.stderr, flush=True)
self.message = self.get_message(param)
super(MissingParameter, self).__init__(self.message)

@classmethod
def get_message(cls, param):
return "Missing Parameter: %s" % param

def show(self, param):
print(self.message, file=sys.stderr, flush=True)


class FileCorruptException(OSError):
Expand All @@ -35,58 +44,67 @@ def __init__(self, path, *args, **kwargs):
if not backup_path and args:
args = reversed(args)
backup_path = args.pop()
if not isinstance(backup_path, six.string_types) or not os.path.exists(os.path.abspath(os.path.dirname(backup_path))):
if not isinstance(backup_path, six.string_types) or not os.path.exists(
os.path.abspath(os.path.dirname(backup_path))
):
args.append(backup_path)
backup_path = None
if args:
args = reversed(args)
self.path = path
self.backup_path = backup_path
self.show(self.path, self.backup_path)
OSError.__init__(self, path, *args, **kwargs)
self.message = self.get_message(path, backup_path=backup_path)
super(FileCorruptException, self).__init__(self.message)

@classmethod
def show(cls, path, backup_path=None):
print("ERROR: Failed to load file at %s" % path, file=sys.stderr, flush=True)
def get_message(self, path, backup_path=None):
message = "ERROR: Failed to load file at %s" % path
if backup_path:
msg = "it will be backed up to %s and removed" % backup_path
else:
msg = "it will be removed and replaced."
print("The file is corrupt, %s" % msg, file=sys.stderr, flush=True)
msg = "it will be removed and replaced on the next lock."
message = "{0}\nYour lockfile is corrupt, {1}".format(message, msg)
return message

def show(self):
print(self.message, file=sys.stderr, flush=True)


class LockfileCorruptException(FileCorruptException):
def __init__(self, path, backup_path=None):
self.message = self.get_message(path, backup_path=backup_path)
super(LockfileCorruptException, self).__init__(self.message)

@classmethod
def show(cls, path, backup_path=None):
print("ERROR: Failed to load lockfile at %s" % path, file=sys.stderr, flush=True)
def get_message(self, path, backup_path=None):
message = "ERROR: Failed to load lockfile at %s" % path
if backup_path:
msg = "it will be backed up to %s and removed" % backup_path
else:
msg = "it will be removed and replaced on the next lock."
print("Your lockfile is corrupt, %s" % msg, file=sys.stderr, flush=True)
message = "{0}\nYour lockfile is corrupt, {1}".format(message, msg)
return message

def show(self, path, backup_path=None):
print(self.message, file=sys.stderr, flush=True)


class PipfileCorruptException(FileCorruptException):
def __init__(self, path, backup_path=None):
self.message = self.get_message(path, backup_path=backup_path)
super(PipfileCorruptException, self).__init__(self.message)

@classmethod
def show(cls, path, backup_path=None):
print("ERROR: Failed to load Pipfile at %s" % path, file=sys.stderr, flush=True)
def get_message(self, path, backup_path=None):
message = "ERROR: Failed to load Pipfile at %s" % path
if backup_path:
msg = "it will be backed up to %s and removed" % backup_path
else:
msg = "it will be removed and replaced on the next lock."
print("Your Pipfile is corrupt, %s" % msg, file=sys.stderr, flush=True)
message = "{0}\nYour Pipfile is corrupt, {1}".format(message, msg)
return message

def show(self, path, backup_path=None):
print(self.message, file=sys.stderr, flush=True)


class PipfileNotFound(FileNotFoundError):
def __init__(self, path, *args, **kwargs):
self.errno = errno.ENOENT
self.path = path
self.show(path)
super(PipfileNotFound, self).__init__(*args, **kwargs)

@classmethod
def show(cls, path):
print("ERROR: The file could not be found: %s" % path, file=sys.stderr, flush=True)
print("Aborting...", file=sys.stderr, flush=True)
self.filename = path
super(PipfileNotFound, self).__init__(self.filename)
Loading

0 comments on commit ce7cd8e

Please sign in to comment.