Skip to content

Commit a1ab613

Browse files
committed
Remove now unused FormatControl in WheelCache
1 parent cf5cc1a commit a1ab613

File tree

3 files changed

+17
-40
lines changed

3 files changed

+17
-40
lines changed

src/pip/_internal/cache.py

+10-31
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import logging
77
import os
88
from pathlib import Path
9-
from typing import Any, Dict, List, Optional, Set
9+
from typing import Any, Dict, List, Optional
1010

1111
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
1212
from pip._vendor.packaging.utils import canonicalize_name
1313

1414
from pip._internal.exceptions import InvalidWheelFilename
1515
from pip._internal.models.direct_url import DirectUrl
16-
from pip._internal.models.format_control import FormatControl
1716
from pip._internal.models.link import Link
1817
from pip._internal.models.wheel import Wheel
1918
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
@@ -33,25 +32,13 @@ def _hash_dict(d: Dict[str, str]) -> str:
3332
class Cache:
3433
"""An abstract class - provides cache directories for data from links
3534
36-
3735
:param cache_dir: The root of the cache.
38-
:param format_control: An object of FormatControl class to limit
39-
binaries being read from the cache.
40-
:param allowed_formats: which formats of files the cache should store.
41-
('binary' and 'source' are the only allowed values)
4236
"""
4337

44-
def __init__(
45-
self, cache_dir: str, format_control: FormatControl, allowed_formats: Set[str]
46-
) -> None:
38+
def __init__(self, cache_dir: str) -> None:
4739
super().__init__()
4840
assert not cache_dir or os.path.isabs(cache_dir)
4941
self.cache_dir = cache_dir or None
50-
self.format_control = format_control
51-
self.allowed_formats = allowed_formats
52-
53-
_valid_formats = {"source", "binary"}
54-
assert self.allowed_formats.union(_valid_formats) == _valid_formats
5542

5643
def _get_cache_path_parts(self, link: Link) -> List[str]:
5744
"""Get parts of part that must be os.path.joined with cache_dir"""
@@ -91,10 +78,6 @@ def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
9178
if can_not_cache:
9279
return []
9380

94-
formats = self.format_control.get_allowed_formats(canonical_package_name)
95-
if not self.allowed_formats.intersection(formats):
96-
return []
97-
9881
candidates = []
9982
path = self.get_path_for_link(link)
10083
if os.path.isdir(path):
@@ -121,8 +104,8 @@ def get(
121104
class SimpleWheelCache(Cache):
122105
"""A cache of wheels for future installs."""
123106

124-
def __init__(self, cache_dir: str, format_control: FormatControl) -> None:
125-
super().__init__(cache_dir, format_control, {"binary"})
107+
def __init__(self, cache_dir: str) -> None:
108+
super().__init__(cache_dir)
126109

127110
def get_path_for_link(self, link: Link) -> str:
128111
"""Return a directory to store cached wheels for link
@@ -191,13 +174,13 @@ def get(
191174
class EphemWheelCache(SimpleWheelCache):
192175
"""A SimpleWheelCache that creates it's own temporary cache directory"""
193176

194-
def __init__(self, format_control: FormatControl) -> None:
177+
def __init__(self) -> None:
195178
self._temp_dir = TempDirectory(
196179
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
197180
globally_managed=True,
198181
)
199182

200-
super().__init__(self._temp_dir.path, format_control)
183+
super().__init__(self._temp_dir.path)
201184

202185

203186
class CacheEntry:
@@ -221,14 +204,10 @@ class WheelCache(Cache):
221204
when a certain link is not found in the simple wheel cache first.
222205
"""
223206

224-
def __init__(
225-
self, cache_dir: str, format_control: Optional[FormatControl] = None
226-
) -> None:
227-
if format_control is None:
228-
format_control = FormatControl()
229-
super().__init__(cache_dir, format_control, {"binary"})
230-
self._wheel_cache = SimpleWheelCache(cache_dir, format_control)
231-
self._ephem_cache = EphemWheelCache(format_control)
207+
def __init__(self, cache_dir: str) -> None:
208+
super().__init__(cache_dir)
209+
self._wheel_cache = SimpleWheelCache(cache_dir)
210+
self._ephem_cache = EphemWheelCache()
232211

233212
def get_path_for_link(self, link: Link) -> str:
234213
return self._wheel_cache.get_path_for_link(link)

tests/unit/test_cache.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@
44
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
55

66
from pip._internal.cache import WheelCache, _hash_dict
7-
from pip._internal.models.format_control import FormatControl
87
from pip._internal.models.link import Link
98
from pip._internal.utils.misc import ensure_dir
109

1110

1211
def test_falsey_path_none() -> None:
13-
wc = WheelCache("", FormatControl())
12+
wc = WheelCache("")
1413
assert wc.cache_dir is None
1514

1615

1716
def test_subdirectory_fragment() -> None:
1817
"""
1918
Test the subdirectory URL fragment is part of the cache key.
2019
"""
21-
wc = WheelCache("/tmp/.foo/", FormatControl())
20+
wc = WheelCache("/tmp/.foo/")
2221
link1 = Link("git+https://g.c/o/r#subdirectory=d1")
2322
link2 = Link("git+https://g.c/o/r#subdirectory=d2")
2423
assert wc.get_path_for_link(link1) != wc.get_path_for_link(link2)
@@ -29,7 +28,7 @@ def test_wheel_name_filter(tmpdir: Path) -> None:
2928
Test the wheel cache filters on wheel name when several wheels
3029
for different package are stored under the same cache directory.
3130
"""
32-
wc = WheelCache(os.fspath(tmpdir), FormatControl())
31+
wc = WheelCache(os.fspath(tmpdir))
3332
link = Link("https://g.c/package.tar.gz")
3433
cache_path = wc.get_path_for_link(link)
3534
ensure_dir(cache_path)
@@ -57,7 +56,7 @@ def test_link_to_cache(tmpdir: Path) -> None:
5756
Test that Link.from_json() produces Links with consistent cache
5857
locations
5958
"""
60-
wc = WheelCache(os.fspath(tmpdir), FormatControl())
59+
wc = WheelCache(os.fspath(tmpdir))
6160
# Define our expectations for stable cache path.
6261
i_name = interpreter_name()
6362
i_version = interpreter_version()
@@ -95,7 +94,7 @@ def test_link_to_cache(tmpdir: Path) -> None:
9594

9695

9796
def test_get_cache_entry(tmpdir: Path) -> None:
98-
wc = WheelCache(os.fspath(tmpdir), FormatControl())
97+
wc = WheelCache(os.fspath(tmpdir))
9998
persi_link = Link("https://g.c/o/r/persi")
10099
persi_path = wc.get_path_for_link(persi_link)
101100
ensure_dir(persi_path)

tests/unit/test_req.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from pip._internal.index.package_finder import PackageFinder
2626
from pip._internal.metadata import select_backend
2727
from pip._internal.models.direct_url import ArchiveInfo, DirectUrl, DirInfo, VcsInfo
28-
from pip._internal.models.format_control import FormatControl
2928
from pip._internal.models.link import Link
3029
from pip._internal.network.session import PipSession
3130
from pip._internal.operations.build.build_tracker import get_build_tracker
@@ -403,7 +402,7 @@ def test_download_info_archive_legacy_cache(
403402
"""Test download_info hash is not set for an archive with legacy cache entry."""
404403
url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
405404
finder = make_test_finder()
406-
wheel_cache = WheelCache(str(tmp_path / "cache"), FormatControl())
405+
wheel_cache = WheelCache(str(tmp_path / "cache"))
407406
cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
408407
Path(cache_entry_dir).mkdir(parents=True)
409408
wheel.make_wheel(name="simple", version="1.0").save_to_dir(cache_entry_dir)
@@ -426,7 +425,7 @@ def test_download_info_archive_cache_with_origin(
426425
url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
427426
hash = "sha256=ad977496000576e1b6c41f6449a9897087ce9da6db4f15b603fe8372af4bf3c6"
428427
finder = make_test_finder()
429-
wheel_cache = WheelCache(str(tmp_path / "cache"), FormatControl())
428+
wheel_cache = WheelCache(str(tmp_path / "cache"))
430429
cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
431430
Path(cache_entry_dir).mkdir(parents=True)
432431
Path(cache_entry_dir).joinpath("origin.json").write_text(

0 commit comments

Comments
 (0)