Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Lockfile #7023

Merged
merged 7 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions news/lockfile.vendor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove Lockfile as a vendored dependency.
57 changes: 43 additions & 14 deletions src/pip/_internal/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

from pip._vendor import requests, six, urllib3
from pip._vendor.cachecontrol import CacheControlAdapter
from pip._vendor.cachecontrol.cache import BaseCache
from pip._vendor.cachecontrol.caches import FileCache
from pip._vendor.lockfile import LockError
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
from pip._vendor.requests.auth import AuthBase, HTTPBasicAuth
from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response
Expand All @@ -33,7 +33,12 @@
# Import ssl from compat so the initial import occurs in only one place.
from pip._internal.utils.compat import HAS_TLS, ipaddress, ssl
from pip._internal.utils.encoding import auto_decode
from pip._internal.utils.filesystem import check_path_owner, copy2_fixed
from pip._internal.utils.filesystem import (
adjacent_tmp_file,
check_path_owner,
copy2_fixed,
replace,
)
from pip._internal.utils.glibc import libc_ver
from pip._internal.utils.misc import (
ask,
Expand All @@ -44,6 +49,7 @@
build_url_from_netloc,
consume,
display_path,
ensure_dir,
format_size,
get_installed_version,
hide_url,
Expand Down Expand Up @@ -532,31 +538,54 @@ def suppressed_cache_errors():
"""
try:
yield
except (LockError, OSError, IOError):
except (OSError, IOError):
pass


class SafeFileCache(FileCache):
class SafeFileCache(BaseCache):
"""
A file based cache which is safe to use even when the target directory may
not be accessible or writable.
chrahunt marked this conversation as resolved.
Show resolved Hide resolved
"""

def __init__(self, directory, *args, **kwargs):
def __init__(self, directory):
# type: (str) -> None
assert directory is not None, "Cache directory must not be None."
super(SafeFileCache, self).__init__(directory, *args, **kwargs)

def get(self, *args, **kwargs):
super(SafeFileCache, self).__init__()
self.directory = directory

def _get_cache_path(self, name):
# type: (str) -> str
# From cachecontrol.caches.file_cache.FileCache._fn, brought into our
# class for backwards-compatibility and to avoid using a non-public
# method.
hashed = FileCache.encode(name)
parts = list(hashed[:5]) + [hashed]
return os.path.join(self.directory, *parts)

def get(self, key):
# type: (str) -> Optional[bytes]
path = self._get_cache_path(key)
with suppressed_cache_errors():
return super(SafeFileCache, self).get(*args, **kwargs)
with open(path, 'rb') as f:
return f.read()

def set(self, *args, **kwargs):
def set(self, key, value):
# type: (str, bytes) -> None
path = self._get_cache_path(key)
with suppressed_cache_errors():
return super(SafeFileCache, self).set(*args, **kwargs)
ensure_dir(os.path.dirname(path))

with adjacent_tmp_file(path) as f:
f.write(value)

replace(f.name, path)

def delete(self, *args, **kwargs):
def delete(self, key):
# type: (str) -> None
path = self._get_cache_path(key)
with suppressed_cache_errors():
return super(SafeFileCache, self).delete(*args, **kwargs)
os.remove(path)


class InsecureHTTPAdapter(HTTPAdapter):
Expand Down Expand Up @@ -631,7 +660,7 @@ def __init__(self, *args, **kwargs):
# require manual eviction from the cache to fix it.
if cache:
secure_adapter = CacheControlAdapter(
cache=SafeFileCache(cache, use_dir_lock=True),
cache=SafeFileCache(cache),
max_retries=retries,
)
else:
Expand Down
1 change: 0 additions & 1 deletion src/pip/_vendor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def vendored(modulename):
vendored("distlib")
vendored("distro")
vendored("html5lib")
vendored("lockfile")
vendored("six")
vendored("six.moves")
vendored("six.moves.urllib")
Expand Down
1 change: 0 additions & 1 deletion src/pip/_vendor/lockfile.pyi

This file was deleted.

21 changes: 0 additions & 21 deletions src/pip/_vendor/lockfile/LICENSE

This file was deleted.

Loading