mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Remove now unused FormatControl in WheelCache
This commit is contained in:
parent
8f0201f67a
commit
93e6dd7184
|
@ -6,14 +6,13 @@ import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Set
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
||||||
from pip._vendor.packaging.utils import canonicalize_name
|
from pip._vendor.packaging.utils import canonicalize_name
|
||||||
|
|
||||||
from pip._internal.exceptions import InvalidWheelFilename
|
from pip._internal.exceptions import InvalidWheelFilename
|
||||||
from pip._internal.models.direct_url import DirectUrl
|
from pip._internal.models.direct_url import DirectUrl
|
||||||
from pip._internal.models.format_control import FormatControl
|
|
||||||
from pip._internal.models.link import Link
|
from pip._internal.models.link import Link
|
||||||
from pip._internal.models.wheel import Wheel
|
from pip._internal.models.wheel import Wheel
|
||||||
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
||||||
|
@ -33,25 +32,13 @@ def _hash_dict(d: Dict[str, str]) -> str:
|
||||||
class Cache:
|
class Cache:
|
||||||
"""An abstract class - provides cache directories for data from links
|
"""An abstract class - provides cache directories for data from links
|
||||||
|
|
||||||
|
|
||||||
:param cache_dir: The root of the cache.
|
:param cache_dir: The root of the cache.
|
||||||
:param format_control: An object of FormatControl class to limit
|
|
||||||
binaries being read from the cache.
|
|
||||||
:param allowed_formats: which formats of files the cache should store.
|
|
||||||
('binary' and 'source' are the only allowed values)
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, cache_dir: str) -> None:
|
||||||
self, cache_dir: str, format_control: FormatControl, allowed_formats: Set[str]
|
|
||||||
) -> None:
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
assert not cache_dir or os.path.isabs(cache_dir)
|
assert not cache_dir or os.path.isabs(cache_dir)
|
||||||
self.cache_dir = cache_dir or None
|
self.cache_dir = cache_dir or None
|
||||||
self.format_control = format_control
|
|
||||||
self.allowed_formats = allowed_formats
|
|
||||||
|
|
||||||
_valid_formats = {"source", "binary"}
|
|
||||||
assert self.allowed_formats.union(_valid_formats) == _valid_formats
|
|
||||||
|
|
||||||
def _get_cache_path_parts(self, link: Link) -> List[str]:
|
def _get_cache_path_parts(self, link: Link) -> List[str]:
|
||||||
"""Get parts of part that must be os.path.joined with cache_dir"""
|
"""Get parts of part that must be os.path.joined with cache_dir"""
|
||||||
|
@ -91,10 +78,6 @@ class Cache:
|
||||||
if can_not_cache:
|
if can_not_cache:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
formats = self.format_control.get_allowed_formats(canonical_package_name)
|
|
||||||
if not self.allowed_formats.intersection(formats):
|
|
||||||
return []
|
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
path = self.get_path_for_link(link)
|
path = self.get_path_for_link(link)
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
|
@ -121,8 +104,8 @@ class Cache:
|
||||||
class SimpleWheelCache(Cache):
|
class SimpleWheelCache(Cache):
|
||||||
"""A cache of wheels for future installs."""
|
"""A cache of wheels for future installs."""
|
||||||
|
|
||||||
def __init__(self, cache_dir: str, format_control: FormatControl) -> None:
|
def __init__(self, cache_dir: str) -> None:
|
||||||
super().__init__(cache_dir, format_control, {"binary"})
|
super().__init__(cache_dir)
|
||||||
|
|
||||||
def get_path_for_link(self, link: Link) -> str:
|
def get_path_for_link(self, link: Link) -> str:
|
||||||
"""Return a directory to store cached wheels for link
|
"""Return a directory to store cached wheels for link
|
||||||
|
@ -191,13 +174,13 @@ class SimpleWheelCache(Cache):
|
||||||
class EphemWheelCache(SimpleWheelCache):
|
class EphemWheelCache(SimpleWheelCache):
|
||||||
"""A SimpleWheelCache that creates it's own temporary cache directory"""
|
"""A SimpleWheelCache that creates it's own temporary cache directory"""
|
||||||
|
|
||||||
def __init__(self, format_control: FormatControl) -> None:
|
def __init__(self) -> None:
|
||||||
self._temp_dir = TempDirectory(
|
self._temp_dir = TempDirectory(
|
||||||
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
|
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
|
||||||
globally_managed=True,
|
globally_managed=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
super().__init__(self._temp_dir.path, format_control)
|
super().__init__(self._temp_dir.path)
|
||||||
|
|
||||||
|
|
||||||
class CacheEntry:
|
class CacheEntry:
|
||||||
|
@ -221,14 +204,10 @@ class WheelCache(Cache):
|
||||||
when a certain link is not found in the simple wheel cache first.
|
when a certain link is not found in the simple wheel cache first.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, cache_dir: str) -> None:
|
||||||
self, cache_dir: str, format_control: Optional[FormatControl] = None
|
super().__init__(cache_dir)
|
||||||
) -> None:
|
self._wheel_cache = SimpleWheelCache(cache_dir)
|
||||||
if format_control is None:
|
self._ephem_cache = EphemWheelCache()
|
||||||
format_control = FormatControl()
|
|
||||||
super().__init__(cache_dir, format_control, {"binary"})
|
|
||||||
self._wheel_cache = SimpleWheelCache(cache_dir, format_control)
|
|
||||||
self._ephem_cache = EphemWheelCache(format_control)
|
|
||||||
|
|
||||||
def get_path_for_link(self, link: Link) -> str:
|
def get_path_for_link(self, link: Link) -> str:
|
||||||
return self._wheel_cache.get_path_for_link(link)
|
return self._wheel_cache.get_path_for_link(link)
|
||||||
|
|
|
@ -4,13 +4,12 @@ from pathlib import Path
|
||||||
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
||||||
|
|
||||||
from pip._internal.cache import WheelCache, _hash_dict
|
from pip._internal.cache import WheelCache, _hash_dict
|
||||||
from pip._internal.models.format_control import FormatControl
|
|
||||||
from pip._internal.models.link import Link
|
from pip._internal.models.link import Link
|
||||||
from pip._internal.utils.misc import ensure_dir
|
from pip._internal.utils.misc import ensure_dir
|
||||||
|
|
||||||
|
|
||||||
def test_falsey_path_none() -> None:
|
def test_falsey_path_none() -> None:
|
||||||
wc = WheelCache("", FormatControl())
|
wc = WheelCache("")
|
||||||
assert wc.cache_dir is None
|
assert wc.cache_dir is None
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ def test_subdirectory_fragment() -> None:
|
||||||
"""
|
"""
|
||||||
Test the subdirectory URL fragment is part of the cache key.
|
Test the subdirectory URL fragment is part of the cache key.
|
||||||
"""
|
"""
|
||||||
wc = WheelCache("/tmp/.foo/", FormatControl())
|
wc = WheelCache("/tmp/.foo/")
|
||||||
link1 = Link("git+https://g.c/o/r#subdirectory=d1")
|
link1 = Link("git+https://g.c/o/r#subdirectory=d1")
|
||||||
link2 = Link("git+https://g.c/o/r#subdirectory=d2")
|
link2 = Link("git+https://g.c/o/r#subdirectory=d2")
|
||||||
assert wc.get_path_for_link(link1) != wc.get_path_for_link(link2)
|
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:
|
||||||
Test the wheel cache filters on wheel name when several wheels
|
Test the wheel cache filters on wheel name when several wheels
|
||||||
for different package are stored under the same cache directory.
|
for different package are stored under the same cache directory.
|
||||||
"""
|
"""
|
||||||
wc = WheelCache(os.fspath(tmpdir), FormatControl())
|
wc = WheelCache(os.fspath(tmpdir))
|
||||||
link = Link("https://g.c/package.tar.gz")
|
link = Link("https://g.c/package.tar.gz")
|
||||||
cache_path = wc.get_path_for_link(link)
|
cache_path = wc.get_path_for_link(link)
|
||||||
ensure_dir(cache_path)
|
ensure_dir(cache_path)
|
||||||
|
@ -57,7 +56,7 @@ def test_link_to_cache(tmpdir: Path) -> None:
|
||||||
Test that Link.from_json() produces Links with consistent cache
|
Test that Link.from_json() produces Links with consistent cache
|
||||||
locations
|
locations
|
||||||
"""
|
"""
|
||||||
wc = WheelCache(os.fspath(tmpdir), FormatControl())
|
wc = WheelCache(os.fspath(tmpdir))
|
||||||
# Define our expectations for stable cache path.
|
# Define our expectations for stable cache path.
|
||||||
i_name = interpreter_name()
|
i_name = interpreter_name()
|
||||||
i_version = interpreter_version()
|
i_version = interpreter_version()
|
||||||
|
@ -95,7 +94,7 @@ def test_link_to_cache(tmpdir: Path) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_get_cache_entry(tmpdir: Path) -> None:
|
def test_get_cache_entry(tmpdir: Path) -> None:
|
||||||
wc = WheelCache(os.fspath(tmpdir), FormatControl())
|
wc = WheelCache(os.fspath(tmpdir))
|
||||||
persi_link = Link("https://g.c/o/r/persi")
|
persi_link = Link("https://g.c/o/r/persi")
|
||||||
persi_path = wc.get_path_for_link(persi_link)
|
persi_path = wc.get_path_for_link(persi_link)
|
||||||
ensure_dir(persi_path)
|
ensure_dir(persi_path)
|
||||||
|
|
|
@ -25,7 +25,6 @@ from pip._internal.exceptions import (
|
||||||
from pip._internal.index.package_finder import PackageFinder
|
from pip._internal.index.package_finder import PackageFinder
|
||||||
from pip._internal.metadata import select_backend
|
from pip._internal.metadata import select_backend
|
||||||
from pip._internal.models.direct_url import ArchiveInfo, DirectUrl, DirInfo, VcsInfo
|
from pip._internal.models.direct_url import ArchiveInfo, DirectUrl, DirInfo, VcsInfo
|
||||||
from pip._internal.models.format_control import FormatControl
|
|
||||||
from pip._internal.models.link import Link
|
from pip._internal.models.link import Link
|
||||||
from pip._internal.network.session import PipSession
|
from pip._internal.network.session import PipSession
|
||||||
from pip._internal.operations.build.build_tracker import get_build_tracker
|
from pip._internal.operations.build.build_tracker import get_build_tracker
|
||||||
|
@ -403,7 +402,7 @@ class TestRequirementSet:
|
||||||
"""Test download_info hash is not set for an archive with legacy cache entry."""
|
"""Test download_info hash is not set for an archive with legacy cache entry."""
|
||||||
url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
|
url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
|
||||||
finder = make_test_finder()
|
finder = make_test_finder()
|
||||||
wheel_cache = WheelCache(str(tmp_path / "cache"), FormatControl())
|
wheel_cache = WheelCache(str(tmp_path / "cache"))
|
||||||
cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
|
cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
|
||||||
Path(cache_entry_dir).mkdir(parents=True)
|
Path(cache_entry_dir).mkdir(parents=True)
|
||||||
wheel.make_wheel(name="simple", version="1.0").save_to_dir(cache_entry_dir)
|
wheel.make_wheel(name="simple", version="1.0").save_to_dir(cache_entry_dir)
|
||||||
|
@ -426,7 +425,7 @@ class TestRequirementSet:
|
||||||
url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
|
url = shared_data.packages.joinpath("simple-1.0.tar.gz").as_uri()
|
||||||
hash = "sha256=ad977496000576e1b6c41f6449a9897087ce9da6db4f15b603fe8372af4bf3c6"
|
hash = "sha256=ad977496000576e1b6c41f6449a9897087ce9da6db4f15b603fe8372af4bf3c6"
|
||||||
finder = make_test_finder()
|
finder = make_test_finder()
|
||||||
wheel_cache = WheelCache(str(tmp_path / "cache"), FormatControl())
|
wheel_cache = WheelCache(str(tmp_path / "cache"))
|
||||||
cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
|
cache_entry_dir = wheel_cache.get_path_for_link(Link(url))
|
||||||
Path(cache_entry_dir).mkdir(parents=True)
|
Path(cache_entry_dir).mkdir(parents=True)
|
||||||
Path(cache_entry_dir).joinpath("origin.json").write_text(
|
Path(cache_entry_dir).joinpath("origin.json").write_text(
|
||||||
|
|
Loading…
Reference in a new issue