Skip to content

Commit

Permalink
Update requirementslib
Browse files Browse the repository at this point in the history
- Fixes #2260

Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Jun 4, 2018
1 parent e937d85 commit 75b40c2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 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.7.dev0"
__version__ = "0.0.9"

from .requirements import Requirement
12 changes: 11 additions & 1 deletion pipenv/vendor/requirementslib/_compat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# -*- coding=utf-8 -*-
# -*- coding=utf-8 -*-
import importlib

# Use these imports as compatibility imports
try:
from pathlib import Path
except ImportError:
from pathlib2 import Path

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


def do_import(module_path, subimport=None, old_path=None):
internal = "pip._internal.{0}".format(module_path)
Expand Down
70 changes: 52 additions & 18 deletions pipenv/vendor/requirementslib/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
import six
from attr import attrs, attrib, Factory, validators
import attr
from ._compat import Link, path_to_url, _strip_extras, InstallRequirement, Wheel
from ._compat import (
Link,
path_to_url,
_strip_extras,
InstallRequirement,
Path,
urlparse,
unquote,
Wheel,
)
from distlib.markers import Evaluator
from packaging.markers import Marker, InvalidMarker
from packaging.specifiers import SpecifierSet, InvalidSpecifier
Expand All @@ -25,15 +34,11 @@
)
from first import first

try:
from pathlib import Path
except ImportError:
from pathlib2 import Path

try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
if six.PY2:
class FileNotFoundError(IOError):
pass


HASH_STRING = " --hash={0}"

Expand Down Expand Up @@ -120,7 +125,7 @@ class Source(object):
verify_ssl = attrib(
default=True, validator=validators.optional(validators.instance_of(bool))
)
# : human name to refer to this source (can be referenced in packages or dev-packages)
#: human name to refer to this source (can be referenced in packages or dev-packages)
name = attrib(default="")


Expand Down Expand Up @@ -277,6 +282,7 @@ def pipfile_part(self):
class FileRequirement(BaseRequirement):
"""File requirements for tar.gz installable files or wheels or setup.py
containing directories."""
setup_path = attrib(default=None)
path = attrib(default=None, validator=validators.optional(_validate_path))
# : path to hit - without any of the VCS prefixes (like git+ / http+ / etc)
uri = attrib()
Expand All @@ -298,10 +304,30 @@ def get_name(self):
loc = self.path or self.uri
if loc:
self._uri_scheme = "path" if self.path else "uri"
name = None
if self._uri_scheme != "uri" and self.path and self.setup_path:
from distutils.core import run_setup
try:
dist = run_setup(self.setup_path.as_posix(), stop_after='init')
except (FileNotFoundError, IOError):
dist = None
except NameError:
from ._compat import InstallRequirement
try:
_ireq = InstallRequirement.from_line(self.setup_path.as_uri())
dist = _ireq.get_dist()
name = dist.project_name
except (TypeError, ValueError, AttributeError):
dist = None
else:
dist_name = dist.get_name()
name = dist_name if dist_name != 'UNKNOWN' else None
hashed_loc = hashlib.sha256(loc.encode("utf-8")).hexdigest()
hash_fragment = hashed_loc[-7:]
self._has_hashed_name = True
return hash_fragment
hashed_name = hashed_loc[-7:]
if not name:
self._has_hashed_name = True
name = hashed_name
return name

@link.default
def get_link(self):
Expand Down Expand Up @@ -341,6 +367,7 @@ def from_line(cls, line):
path = None
editable = line.startswith("-e ")
line = line.split(" ", 1)[1] if editable else line
setup_path = None
if not any([is_installable_file(line), is_valid_url(line)]):
raise ValueError(
"Supplied requirement is not installable: {0!r}".format(line)
Expand All @@ -353,13 +380,16 @@ def from_line(cls, line):
parsed = urlparse(line)
link = Link('{0}'.format(line))
if parsed.scheme == "file":
path = Path(parsed.path).absolute().as_posix()
path = Path(parsed.path)
setup_path = path / 'setup.py'
path = path.absolute().as_posix()
if get_converted_relative_path(path) == ".":
path = "."
line = path
else:
_path = Path(line)
link = Link(_path.absolute().as_uri())
setup_path = _path / 'setup.py'
link = Link(unquote(_path.absolute().as_uri()))
if _path.is_absolute() or _path.as_posix() == ".":
path = _path.as_posix()
else:
Expand All @@ -369,6 +399,7 @@ def from_line(cls, line):
"uri": link.url_without_fragment,
"link": link,
"editable": editable,
"setup_path": setup_path,
}
if link.egg_fragment:
arg_dict["name"] = link.egg_fragment
Expand All @@ -382,11 +413,11 @@ def from_pipfile(cls, name, pipfile):
if not uri_key:
abs_path = os.path.abspath(uri)
uri = path_to_url(abs_path) if os.path.exists(abs_path) else None
link = Link(uri) if uri else None
link = Link(unquote(uri)) if uri else None
arg_dict = {
"name": name,
"path": pipfile.get("path"),
"uri": link.url_without_fragment,
"uri": unquote(link.url_without_fragment if link else uri),
"editable": pipfile.get("editable"),
"link": link,
}
Expand All @@ -405,6 +436,8 @@ def line_part(self):
def pipfile_part(self):
pipfile_dict = {k: v for k, v in attr.asdict(self, filter=_filter_none).items()}
name = pipfile_dict.pop("name")
if "setup_path" in pipfile_dict:
_ = pipfile_dict.pop("setup_path")
req = self.req
# For local paths and remote installable artifacts (zipfiles, etc)
if self.is_remote_artifact:
Expand Down Expand Up @@ -451,7 +484,8 @@ def get_link(self):

@name.default
def get_name(self):
return self.link.egg_fragment or self.req.name if self.req else ""
return self.link.egg_fragment or self.req.name \
if self.req else super(VCSRequirement, self).get_name()

@property
def vcs_uri(self):
Expand Down

0 comments on commit 75b40c2

Please sign in to comment.