mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Move helper functions into Link
This commit is contained in:
parent
dd62731107
commit
892b58f244
3 changed files with 15 additions and 22 deletions
|
@ -100,7 +100,7 @@ if MYPY_CHECK_RUNNING:
|
|||
__all__ = ['get_file_content',
|
||||
'path_to_url',
|
||||
'unpack_vcs_link',
|
||||
'unpack_file_url', 'is_file_url',
|
||||
'unpack_file_url',
|
||||
'unpack_http_url', 'unpack_url',
|
||||
'parse_content_disposition', 'sanitize_content_filename']
|
||||
|
||||
|
@ -602,23 +602,6 @@ def _get_used_vcs_backend(link):
|
|||
return None
|
||||
|
||||
|
||||
def is_file_url(link):
|
||||
# type: (Link) -> bool
|
||||
return link.url.lower().startswith('file:')
|
||||
|
||||
|
||||
def is_dir_url(link):
|
||||
# type: (Link) -> bool
|
||||
"""Return whether a file:// Link points to a directory.
|
||||
|
||||
``link`` must not have any other scheme but file://. Call is_file_url()
|
||||
first.
|
||||
|
||||
"""
|
||||
link_path = link.file_path
|
||||
return os.path.isdir(link_path)
|
||||
|
||||
|
||||
def _progress_indicator(iterable, *args, **kwargs):
|
||||
return iterable
|
||||
|
||||
|
@ -849,7 +832,7 @@ def unpack_file_url(
|
|||
"""
|
||||
link_path = link.file_path
|
||||
# If it's a url to a local directory
|
||||
if is_dir_url(link):
|
||||
if link.is_existing_dir():
|
||||
if os.path.isdir(location):
|
||||
rmtree(location)
|
||||
_copy_source_tree(link_path, location)
|
||||
|
@ -945,7 +928,7 @@ def unpack_url(
|
|||
unpack_vcs_link(link, location)
|
||||
|
||||
# file urls
|
||||
elif is_file_url(link):
|
||||
elif link.is_file:
|
||||
unpack_file_url(link, location, download_dir, hashes=hashes)
|
||||
|
||||
# http urls
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import os
|
||||
import posixpath
|
||||
import re
|
||||
|
||||
|
@ -180,6 +181,15 @@ class Link(KeyBasedCompareMixin):
|
|||
# type: () -> Optional[str]
|
||||
return posixpath.basename(self._url.split('#', 1)[0].split('?', 1)[0])
|
||||
|
||||
@property
|
||||
def is_file(self):
|
||||
# type: () -> bool
|
||||
return self.scheme == 'file'
|
||||
|
||||
def is_existing_dir(self):
|
||||
# type: () -> bool
|
||||
return self.is_file and os.path.isdir(self.file_path)
|
||||
|
||||
@property
|
||||
def is_wheel(self):
|
||||
# type: () -> bool
|
||||
|
|
|
@ -13,7 +13,7 @@ from pip._internal.distributions import (
|
|||
make_distribution_for_install_requirement,
|
||||
)
|
||||
from pip._internal.distributions.installed import InstalledDistribution
|
||||
from pip._internal.download import is_dir_url, is_file_url, unpack_url
|
||||
from pip._internal.download import unpack_url
|
||||
from pip._internal.exceptions import (
|
||||
DirectoryUrlHashUnsupported,
|
||||
HashUnpinned,
|
||||
|
@ -160,7 +160,7 @@ class RequirementPreparer(object):
|
|||
# hash provided.
|
||||
if link.is_vcs:
|
||||
raise VcsHashUnsupported()
|
||||
elif is_file_url(link) and is_dir_url(link):
|
||||
elif link.is_existing_dir():
|
||||
raise DirectoryUrlHashUnsupported()
|
||||
if not req.original_link and not req.is_pinned:
|
||||
# Unpinned packages are asking for trouble when a new
|
||||
|
|
Loading…
Reference in a new issue