Skip to content

Commit

Permalink
Update requirementslib to fix windows paths
Browse files Browse the repository at this point in the history
 - Fixes #2256

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy committed May 26, 2018
1 parent 9550056 commit 513bdfb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pipenv/vendor/requirementslib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding=utf-8 -*-
__version__ = "0.0.4"
__version__ = "0.0.6"

from .requirements import Requirement
58 changes: 42 additions & 16 deletions pipenv/vendor/requirementslib/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import six
from attr import attrs, attrib, Factory, validators
import attr
from ._compat import Link, path_to_url, _strip_extras
from ._compat import Link, path_to_url, _strip_extras, InstallRequirement
from distlib.markers import Evaluator
from packaging.markers import Marker, InvalidMarker
from packaging.specifiers import SpecifierSet, InvalidSpecifier
Expand All @@ -30,6 +30,11 @@
except ImportError:
from pathlib2 import Path

try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse

HASH_STRING = " --hash={0}"


Expand Down Expand Up @@ -261,7 +266,7 @@ def line_part(self):

@property
def pipfile_part(self):
pipfile_dict = attr.asdict(self, filter=_filter_none)
pipfile_dict = attr.asdict(self, filter=_filter_none).copy()
if "version" not in pipfile_dict:
pipfile_dict["version"] = "*"
name = pipfile_dict.pop("name")
Expand Down Expand Up @@ -305,16 +310,16 @@ def get_link(self):

@req.default
def get_requirement(self):
base = "{0}".format(self.link)
req = first(requirements.parse(base))
prefix = "-e " if self.editable else ""
line = "{0}{1}".format(prefix, self.link.url)
req = first(requirements.parse(line))
if self.path and self.link and self.link.scheme.startswith("file"):
req.local_file = True
req.path = self.path
req.uri = None
self._uri_scheme = "file"
if self.editable:
req.editable = True
if self.link and self.link.scheme.startswith("file"):
if self.path:
req.path = self.path
req.local_file = True
self._uri_scheme = "file"
req.uri = None
req.link = self.link
return req

Expand All @@ -338,15 +343,24 @@ def from_line(cls, line):
"Supplied requirement is not installable: {0!r}".format(line)
)

if is_valid_url(line):
if is_valid_url(line) and not is_installable_file(line):
link = Link(line)
else:
_path = Path(line)
link = Link(_path.absolute().as_uri())
if _path.is_absolute() or _path.as_posix() == ".":
path = _path.as_posix()
if is_valid_url(line):
parsed = urlparse(line)
link = Link('{0}'.format(line))
if parsed.scheme == "file":
path = Path(parsed.path).absolute().as_posix()
if get_converted_relative_path(path) == ".":
path = "."
line = path
else:
path = get_converted_relative_path(line)
_path = Path(line)
link = Link(_path.absolute().as_uri())
if _path.is_absolute() or _path.as_posix() == ".":
path = _path.as_posix()
else:
path = get_converted_relative_path(line)
arg_dict = {
"path": path,
"uri": link.url_without_fragment,
Expand Down Expand Up @@ -571,6 +585,7 @@ class Requirement(object):
editable = attrib(default=None)
hashes = attrib(default=Factory(list), converter=list)
extras = attrib(default=Factory(list))
_ireq = None
_INCLUDE_FIELDS = ("name", "markers", "index", "editable", "hashes", "extras")

@name.default
Expand Down Expand Up @@ -749,6 +764,17 @@ def as_pipfile(self, include_index=False):
def pipfile_entry(self):
return self.as_pipfile().copy().popitem()

@property
def ireq(self):
if not self._ireq:
ireq_line = self.as_line()
if ireq_line.startswith("-e "):
ireq_line = ireq_line[len("-e "):]
self._ireq = InstallRequirement.from_editable(ireq_line)
else:
self._ireq = InstallRequirement.from_line(ireq_line)
return self._ireq


def _extras_to_string(extras):
"""Turn a list of extras into a string"""
Expand Down
11 changes: 9 additions & 2 deletions pipenv/vendor/requirementslib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def is_vcs(pipfile_entry):

def get_converted_relative_path(path, relative_to=os.curdir):
"""Given a vague relative path, return the path relative to the given location"""
return os.path.join(".", os.path.relpath(path, start=relative_to))
relpath = os.path.relpath(path, start=relative_to)
if os.name == 'nt':
return os.altsep.join([".", relpath])
return os.path.join(".", relpath)


def multi_split(s, split):
Expand Down Expand Up @@ -73,6 +76,10 @@ def is_installable_file(path):
else:
return False

parsed = urlparse(path)
if parsed.scheme == 'file':
path = parsed.path

if not os.path.exists(os.path.abspath(path)):
return False

Expand All @@ -90,7 +97,7 @@ def is_installable_file(path):
def is_valid_url(url):
"""Checks if a given string is an url"""
pieces = urlparse(url)
return all([pieces.scheme, pieces.netloc])
return all([pieces.scheme, any([pieces.netloc, pieces.path])])


def pep423_name(name):
Expand Down

0 comments on commit 513bdfb

Please # to comment.