Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 24 additions & 40 deletions pipenv/utils/requirementslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
SCHEME_LIST = ("http://", "https://", "ftp://", "ftps://", "file://")


VCS_SCHEMES = [
VCS_SCHEMES = {
"git",
"git+http",
"git+https",
Expand All @@ -57,7 +57,7 @@
"bzr+sftp",
"bzr+ftp",
"bzr+lp",
]
}


def strip_ssh_from_git_uri(uri):
Expand Down Expand Up @@ -106,6 +106,7 @@ def is_vcs(pipfile_entry):

def is_editable(pipfile_entry):
# type: (PipfileType) -> bool
"""Check if a Pipfile entry is editable."""
if isinstance(pipfile_entry, Mapping):
return pipfile_entry.get("editable", False) is True
if isinstance(pipfile_entry, str):
Expand All @@ -115,6 +116,7 @@ def is_editable(pipfile_entry):

def is_star(val):
# type: (PipfileType) -> bool
"""Check if a Pipfile entry has a version specified as '*'."""
return (isinstance(val, str) and val == "*") or (
isinstance(val, Mapping) and val.get("version", "") == "*"
)
Expand Down Expand Up @@ -183,6 +185,7 @@ def is_installable_file(path):

def get_setup_paths(base_path, subdirectory=None):
# type: (S, Optional[S]) -> Dict[S, Optional[S]]
"""Get paths to setup.py, setup.cfg, and pyproject.toml in the given directory."""
if base_path is None:
raise TypeError("must provide a path to derive setup paths from")
setup_py = os.path.join(base_path, "setup.py")
Expand All @@ -208,25 +211,22 @@ def get_setup_paths(base_path, subdirectory=None):

def prepare_pip_source_args(sources, pip_args=None):
# type: (List[Dict[S, Union[S, bool]]], Optional[List[S]]) -> List[S]
"""Prepare pip arguments for source indexes."""
if pip_args is None:
pip_args = []
if sources:
# Add the source to pip9.
pip_args.extend(["-i ", sources[0]["url"]]) # type: ignore
pip_args.extend(["-i", sources[0]["url"]]) # type: ignore
# Trust the host if it's not verified.
if not sources[0].get("verify_ssl", True):
pip_args.extend(
["--trusted-host", urlparse(sources[0]["url"]).hostname]
) # type: ignore
hostname = urlparse(sources[0]["url"]).hostname
if not sources[0].get("verify_ssl", True) and hostname:
pip_args.extend(["--trusted-host", hostname]) # type: ignore
# Add additional sources as extra indexes.
if len(sources) > 1:
for source in sources[1:]:
pip_args.extend(["--extra-index-url", source["url"]]) # type: ignore
# Trust the host if it's not verified.
if not source.get("verify_ssl", True):
pip_args.extend(
["--trusted-host", urlparse(source["url"]).hostname]
) # type: ignore
for source in sources[1:]:
pip_args.extend(["--extra-index-url", source["url"]]) # type: ignore
hostname = urlparse(source["url"]).hostname
if not source.get("verify_ssl", True) and hostname:
pip_args.extend(["--trusted-host", hostname]) # type: ignore
return pip_args


Expand All @@ -244,7 +244,7 @@ def get_package_finder(
py_version_info = None
if python_versions:
py_version_info_python = max(python_versions)
py_version_info = tuple([int(part) for part in py_version_info_python])
py_version_info = tuple(int(part) for part in py_version_info_python)
target_python = TargetPython(
platforms=[platform] if platform else None,
py_version_info=py_version_info,
Expand Down Expand Up @@ -360,7 +360,7 @@ def get_path(root, path, default=_UNSET):
seg = int(seg)
cur = cur[seg]
except (ValueError, KeyError, IndexError, TypeError):
if not getattr(cur, "__iter__", None):
if not hasattr(cur, "__iter__"):
exc = TypeError(f"{type(cur).__name__!r} object is not indexable")
raise PathAccessError(exc, seg, path)
except PathAccessError:
Expand Down Expand Up @@ -429,7 +429,7 @@ def dict_path_exit(path, key, old_parent, new_parent, new_items):
except AttributeError:
ret = new_parent.__class__(vals) # frozensets
else:
raise RuntimeError(f"unexpected iterable type: {type(new_parent)!r}")
raise RuntimeError(f"Unexpected iterable type: {type(new_parent)!r}")
return ret


Expand Down Expand Up @@ -526,7 +526,7 @@ def remap(
raise TypeError(f"exit expected callable, not: {exit!r}")
reraise_visit = kwargs.pop("reraise_visit", True)
if kwargs:
raise TypeError(f"unexpected keyword arguments: {kwargs.keys()!r}")
raise TypeError(f"Unexpected keyword arguments: {kwargs.keys()!r}")

path, registry, stack = (), {}, [(None, root)]
new_items_stack = []
Expand All @@ -550,8 +550,7 @@ def remap(
except TypeError:
# TODO: handle False?
raise TypeError(
"enter should return a tuple of (new_parent,"
f" items_iterator), not: {res!r}"
f"enter should return a tuple of (new_parent, items_iterator), not: {res!r}"
)
if new_items is not False:
# traverse unless False is explicitly passed
Expand Down Expand Up @@ -583,7 +582,7 @@ def remap(
try:
new_items_stack[-1][1].append(visited_item)
except IndexError:
raise TypeError(f"expected remappable root, not: {root!r}")
raise TypeError(f"Expected remappable root, not: {root!r}")
return value


Expand Down Expand Up @@ -629,6 +628,7 @@ def remerge_visit(path, key, value):


def get_pip_command() -> InstallCommand:
"""Get pip's InstallCommand for configuration management and defaults."""
# Use pip's parser for pip.conf management and defaults.
# General options (find_links, index_url, extra_index_url, trusted_host,
# and pre) are deferred to pip.
Expand All @@ -654,24 +654,7 @@ def unpack_url(
would ordinarily raise HashUnsupported) are allowed.
"""
# non-editable vcs urls
if link.scheme in [
"git+http",
"git+https",
"git+ssh",
"git+git",
"hg+http",
"hg+https",
"hg+ssh",
"svn+http",
"svn+https",
"svn+svn",
"bzr+http",
"bzr+https",
"bzr+ssh",
"bzr+sftp",
"bzr+ftp",
"bzr+lp",
]:
if link.scheme in VCS_SCHEMES:
unpack_vcs_link(link, location, verbosity=verbosity)
return File(location, content_type=None)

Expand Down Expand Up @@ -704,6 +687,7 @@ def get_http_url(
download_dir: Optional[str] = None,
hashes: Optional[Hashes] = None,
) -> File:
"""Download a file from an HTTP URL."""
temp_dir = TempDirectory(kind="unpack", globally_managed=False)
# If a download dir is specified, is the file already downloaded there?
already_downloaded_path = None
Expand Down
Loading