Skip to content

Commit 297d3a0

Browse files
authored
Merge pull request #2269 from pypa/bugfix/windows-relpaths
Update requirementslib to fix windows paths
2 parents 9550056 + d55e400 commit 297d3a0

File tree

5 files changed

+73
-31
lines changed

5 files changed

+73
-31
lines changed

pipenv/patched/notpip/_internal/pep425tags.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import warnings
1111
from collections import OrderedDict
1212

13-
try:
14-
import pip._internal.utils.glibc
15-
except ImportError:
16-
import pip.utils.glibc
13+
import pipenv.patched.notpip._internal.utils.glibc
1714

1815
logger = logging.getLogger(__name__)
1916

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

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

162159

163160
def get_darwin_arches(major, minor, machine):
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding=utf-8 -*-
2-
__version__ = "0.0.4"
2+
__version__ = "0.0.7.dev0"
33

44
from .requirements import Requirement

pipenv/vendor/requirementslib/requirements.py

+46-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import six
99
from attr import attrs, attrib, Factory, validators
1010
import attr
11-
from ._compat import Link, path_to_url, _strip_extras
11+
from ._compat import Link, path_to_url, _strip_extras, InstallRequirement, Wheel
1212
from distlib.markers import Evaluator
1313
from packaging.markers import Marker, InvalidMarker
1414
from packaging.specifiers import SpecifierSet, InvalidSpecifier
@@ -30,6 +30,11 @@
3030
except ImportError:
3131
from pathlib2 import Path
3232

33+
try:
34+
from urllib.parse import urlparse
35+
except ImportError:
36+
from urlparse import urlparse
37+
3338
HASH_STRING = " --hash={0}"
3439

3540

@@ -261,7 +266,7 @@ def line_part(self):
261266

262267
@property
263268
def pipfile_part(self):
264-
pipfile_dict = attr.asdict(self, filter=_filter_none)
269+
pipfile_dict = attr.asdict(self, filter=_filter_none).copy()
265270
if "version" not in pipfile_dict:
266271
pipfile_dict["version"] = "*"
267272
name = pipfile_dict.pop("name")
@@ -301,20 +306,23 @@ def get_name(self):
301306
@link.default
302307
def get_link(self):
303308
target = "{0}#egg={1}".format(self.uri, self.name)
304-
return Link(target)
309+
link = Link(target)
310+
if link.is_wheel and self._has_hashed_name:
311+
self.name = os.path.basename(Wheel(link.path).name)
312+
return link
305313

306314
@req.default
307315
def get_requirement(self):
308-
base = "{0}".format(self.link)
309-
req = first(requirements.parse(base))
316+
prefix = "-e " if self.editable else ""
317+
line = "{0}{1}".format(prefix, self.link.url)
318+
req = first(requirements.parse(line))
319+
if self.path and self.link and self.link.scheme.startswith("file"):
320+
req.local_file = True
321+
req.path = self.path
322+
req.uri = None
323+
self._uri_scheme = "file"
310324
if self.editable:
311325
req.editable = True
312-
if self.link and self.link.scheme.startswith("file"):
313-
if self.path:
314-
req.path = self.path
315-
req.local_file = True
316-
self._uri_scheme = "file"
317-
req.uri = None
318326
req.link = self.link
319327
return req
320328

@@ -338,15 +346,24 @@ def from_line(cls, line):
338346
"Supplied requirement is not installable: {0!r}".format(line)
339347
)
340348

341-
if is_valid_url(line):
349+
if is_valid_url(line) and not is_installable_file(line):
342350
link = Link(line)
343351
else:
344-
_path = Path(line)
345-
link = Link(_path.absolute().as_uri())
346-
if _path.is_absolute() or _path.as_posix() == ".":
347-
path = _path.as_posix()
352+
if is_valid_url(line):
353+
parsed = urlparse(line)
354+
link = Link('{0}'.format(line))
355+
if parsed.scheme == "file":
356+
path = Path(parsed.path).absolute().as_posix()
357+
if get_converted_relative_path(path) == ".":
358+
path = "."
359+
line = path
348360
else:
349-
path = get_converted_relative_path(line)
361+
_path = Path(line)
362+
link = Link(_path.absolute().as_uri())
363+
if _path.is_absolute() or _path.as_posix() == ".":
364+
path = _path.as_posix()
365+
else:
366+
path = get_converted_relative_path(line)
350367
arg_dict = {
351368
"path": path,
352369
"uri": link.url_without_fragment,
@@ -571,6 +588,7 @@ class Requirement(object):
571588
editable = attrib(default=None)
572589
hashes = attrib(default=Factory(list), converter=list)
573590
extras = attrib(default=Factory(list))
591+
_ireq = None
574592
_INCLUDE_FIELDS = ("name", "markers", "index", "editable", "hashes", "extras")
575593

576594
@name.default
@@ -749,6 +767,17 @@ def as_pipfile(self, include_index=False):
749767
def pipfile_entry(self):
750768
return self.as_pipfile().copy().popitem()
751769

770+
@property
771+
def ireq(self):
772+
if not self._ireq:
773+
ireq_line = self.as_line()
774+
if ireq_line.startswith("-e "):
775+
ireq_line = ireq_line[len("-e "):]
776+
self._ireq = InstallRequirement.from_editable(ireq_line)
777+
else:
778+
self._ireq = InstallRequirement.from_line(ireq_line)
779+
return self._ireq
780+
752781

753782
def _extras_to_string(extras):
754783
"""Turn a list of extras into a string"""

pipenv/vendor/requirementslib/utils.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def is_vcs(pipfile_entry):
3535

3636
def get_converted_relative_path(path, relative_to=os.curdir):
3737
"""Given a vague relative path, return the path relative to the given location"""
38-
return os.path.join(".", os.path.relpath(path, start=relative_to))
38+
relpath = os.path.relpath(path, start=relative_to)
39+
if os.name == 'nt':
40+
return os.altsep.join([".", relpath])
41+
return os.path.join(".", relpath)
3942

4043

4144
def multi_split(s, split):
@@ -73,6 +76,10 @@ def is_installable_file(path):
7376
else:
7477
return False
7578

79+
parsed = urlparse(path)
80+
if parsed.scheme == 'file':
81+
path = parsed.path
82+
7683
if not os.path.exists(os.path.abspath(path)):
7784
return False
7885

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

95102

96103
def pep423_name(name):
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
diff --git a/pipenv/patched/notpip/_internal/pep425tags.py b/pipenv/patched/notpip/_internal/pep425tags.py
2-
index bea31585..9e9609f3 100644
2+
index bea31585..4205f6e0 100644
33
--- a/pipenv/patched/notpip/_internal/pep425tags.py
44
+++ b/pipenv/patched/notpip/_internal/pep425tags.py
5-
@@ -11,9 +11,9 @@ import warnings
5+
@@ -10,10 +10,7 @@ import sysconfig
6+
import warnings
67
from collections import OrderedDict
78

8-
try:
9+
-try:
910
- import pip._internal.utils.glibc
10-
+ import pipenv.patched.notpip._internal.utils.glibc
11-
except ImportError:
11+
-except ImportError:
1212
- import pip.utils.glibc
13-
+ import pipenv.patched.notpip.utils.glibc
13+
+import pipenv.patched.notpip._internal.utils.glibc
1414

1515
logger = logging.getLogger(__name__)
1616

17+
@@ -157,7 +154,7 @@ def is_manylinux1_compatible():
18+
pass
19+
20+
# Check glibc version. CentOS 5 uses glibc 2.5.
21+
- return pip._internal.utils.glibc.have_compatible_glibc(2, 5)
22+
+ return pipenv.patched.notpip._internal.utils.glibc.have_compatible_glibc(2, 5)
23+
24+
25+
def get_darwin_arches(major, minor, machine):

0 commit comments

Comments
 (0)