Skip to content

Commit

Permalink
Merge pull request #2269 from pypa/bugfix/windows-relpaths
Browse files Browse the repository at this point in the history
Update requirementslib to fix windows paths
  • Loading branch information
techalchemy committed May 27, 2018
2 parents 9550056 + d55e400 commit 297d3a0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 31 deletions.
7 changes: 2 additions & 5 deletions pipenv/patched/notpip/_internal/pep425tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import warnings
from collections import OrderedDict

try:
import pip._internal.utils.glibc
except ImportError:
import pip.utils.glibc
import pipenv.patched.notpip._internal.utils.glibc

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -157,7 +154,7 @@ def is_manylinux1_compatible():
pass

# Check glibc version. CentOS 5 uses glibc 2.5.
return pip._internal.utils.glibc.have_compatible_glibc(2, 5)
return pipenv.patched.notpip._internal.utils.glibc.have_compatible_glibc(2, 5)


def get_darwin_arches(major, minor, machine):
Expand Down
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.7.dev0"

from .requirements import Requirement
63 changes: 46 additions & 17 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, Wheel
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 @@ -301,20 +306,23 @@ def get_name(self):
@link.default
def get_link(self):
target = "{0}#egg={1}".format(self.uri, self.name)
return Link(target)
link = Link(target)
if link.is_wheel and self._has_hashed_name:
self.name = os.path.basename(Wheel(link.path).name)
return link

@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 +346,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 +588,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 +767,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
21 changes: 15 additions & 6 deletions tasks/vendoring/patches/patched/_post-pip-update-pep425tags.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
diff --git a/pipenv/patched/notpip/_internal/pep425tags.py b/pipenv/patched/notpip/_internal/pep425tags.py
index bea31585..9e9609f3 100644
index bea31585..4205f6e0 100644
--- a/pipenv/patched/notpip/_internal/pep425tags.py
+++ b/pipenv/patched/notpip/_internal/pep425tags.py
@@ -11,9 +11,9 @@ import warnings
@@ -10,10 +10,7 @@ import sysconfig
import warnings
from collections import OrderedDict

try:
-try:
- import pip._internal.utils.glibc
+ import pipenv.patched.notpip._internal.utils.glibc
except ImportError:
-except ImportError:
- import pip.utils.glibc
+ import pipenv.patched.notpip.utils.glibc
+import pipenv.patched.notpip._internal.utils.glibc

logger = logging.getLogger(__name__)

@@ -157,7 +154,7 @@ def is_manylinux1_compatible():
pass

# Check glibc version. CentOS 5 uses glibc 2.5.
- return pip._internal.utils.glibc.have_compatible_glibc(2, 5)
+ return pipenv.patched.notpip._internal.utils.glibc.have_compatible_glibc(2, 5)


def get_darwin_arches(major, minor, machine):

0 comments on commit 297d3a0

Please sign in to comment.