Skip to content

Commit b0a6428

Browse files
authored
Merge pull request #7023 from chrahunt/maint/remove-lockfile-dependency
Remove Lockfile
2 parents 41ea07a + ddfe2be commit b0a6428

14 files changed

+54
-958
lines changed

news/lockfile.vendor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove Lockfile as a vendored dependency.

src/pip/_internal/download.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
from pip._vendor import requests, six, urllib3
1616
from pip._vendor.cachecontrol import CacheControlAdapter
17+
from pip._vendor.cachecontrol.cache import BaseCache
1718
from pip._vendor.cachecontrol.caches import FileCache
18-
from pip._vendor.lockfile import LockError
1919
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
2020
from pip._vendor.requests.auth import AuthBase, HTTPBasicAuth
2121
from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response
@@ -33,7 +33,12 @@
3333
# Import ssl from compat so the initial import occurs in only one place.
3434
from pip._internal.utils.compat import HAS_TLS, ipaddress, ssl
3535
from pip._internal.utils.encoding import auto_decode
36-
from pip._internal.utils.filesystem import check_path_owner, copy2_fixed
36+
from pip._internal.utils.filesystem import (
37+
adjacent_tmp_file,
38+
check_path_owner,
39+
copy2_fixed,
40+
replace,
41+
)
3742
from pip._internal.utils.glibc import libc_ver
3843
from pip._internal.utils.misc import (
3944
ask,
@@ -44,6 +49,7 @@
4449
build_url_from_netloc,
4550
consume,
4651
display_path,
52+
ensure_dir,
4753
format_size,
4854
get_installed_version,
4955
hide_url,
@@ -532,31 +538,54 @@ def suppressed_cache_errors():
532538
"""
533539
try:
534540
yield
535-
except (LockError, OSError, IOError):
541+
except (OSError, IOError):
536542
pass
537543

538544

539-
class SafeFileCache(FileCache):
545+
class SafeFileCache(BaseCache):
540546
"""
541547
A file based cache which is safe to use even when the target directory may
542548
not be accessible or writable.
543549
"""
544550

545-
def __init__(self, directory, *args, **kwargs):
551+
def __init__(self, directory):
552+
# type: (str) -> None
546553
assert directory is not None, "Cache directory must not be None."
547-
super(SafeFileCache, self).__init__(directory, *args, **kwargs)
548-
549-
def get(self, *args, **kwargs):
554+
super(SafeFileCache, self).__init__()
555+
self.directory = directory
556+
557+
def _get_cache_path(self, name):
558+
# type: (str) -> str
559+
# From cachecontrol.caches.file_cache.FileCache._fn, brought into our
560+
# class for backwards-compatibility and to avoid using a non-public
561+
# method.
562+
hashed = FileCache.encode(name)
563+
parts = list(hashed[:5]) + [hashed]
564+
return os.path.join(self.directory, *parts)
565+
566+
def get(self, key):
567+
# type: (str) -> Optional[bytes]
568+
path = self._get_cache_path(key)
550569
with suppressed_cache_errors():
551-
return super(SafeFileCache, self).get(*args, **kwargs)
570+
with open(path, 'rb') as f:
571+
return f.read()
552572

553-
def set(self, *args, **kwargs):
573+
def set(self, key, value):
574+
# type: (str, bytes) -> None
575+
path = self._get_cache_path(key)
554576
with suppressed_cache_errors():
555-
return super(SafeFileCache, self).set(*args, **kwargs)
577+
ensure_dir(os.path.dirname(path))
578+
579+
with adjacent_tmp_file(path) as f:
580+
f.write(value)
581+
582+
replace(f.name, path)
556583

557-
def delete(self, *args, **kwargs):
584+
def delete(self, key):
585+
# type: (str) -> None
586+
path = self._get_cache_path(key)
558587
with suppressed_cache_errors():
559-
return super(SafeFileCache, self).delete(*args, **kwargs)
588+
os.remove(path)
560589

561590

562591
class InsecureHTTPAdapter(HTTPAdapter):
@@ -631,7 +660,7 @@ def __init__(self, *args, **kwargs):
631660
# require manual eviction from the cache to fix it.
632661
if cache:
633662
secure_adapter = CacheControlAdapter(
634-
cache=SafeFileCache(cache, use_dir_lock=True),
663+
cache=SafeFileCache(cache),
635664
max_retries=retries,
636665
)
637666
else:

src/pip/_vendor/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def vendored(modulename):
6464
vendored("distlib")
6565
vendored("distro")
6666
vendored("html5lib")
67-
vendored("lockfile")
6867
vendored("six")
6968
vendored("six.moves")
7069
vendored("six.moves.urllib")

src/pip/_vendor/lockfile.pyi

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/pip/_vendor/lockfile/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)