Skip to content

Commit fded808

Browse files
authored
Merge pull request #11872 from sbidoul/rm-no-binary-disables-wheel-cache-sbi
Remove `--no-binary` disabling wheel cache
2 parents 10d9cbc + 2617ccd commit fded808

File tree

9 files changed

+40
-86
lines changed

9 files changed

+40
-86
lines changed

news/11453.removal.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``--no-binary`` does not disable the cache of locally built wheels anymore. It only
2+
means "don't download wheels".

src/pip/_internal/cache.py

Lines changed: 10 additions & 31 deletions
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)

src/pip/_internal/cli/base_command.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ def _main(self, args: List[str]) -> int:
122122
user_log_file=options.log,
123123
)
124124

125+
always_enabled_features = set(options.features_enabled) & set(
126+
cmdoptions.ALWAYS_ENABLED_FEATURES
127+
)
128+
if always_enabled_features:
129+
logger.warning(
130+
"The following features are always enabled: %s. ",
131+
", ".join(sorted(always_enabled_features)),
132+
)
133+
125134
# TODO: Try to get these passing down from the command?
126135
# without resorting to os.environ to hold these.
127136
# This also affects isolated builds and it should.

src/pip/_internal/cli/cmdoptions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,11 @@ def check_list_path_option(options: Values) -> None:
994994
)
995995

996996

997+
# Features that are now always on. A warning is printed if they are used.
998+
ALWAYS_ENABLED_FEATURES = [
999+
"no-binary-enable-wheel-cache", # always on since 23.1
1000+
]
1001+
9971002
use_new_feature: Callable[..., Option] = partial(
9981003
Option,
9991004
"--use-feature",
@@ -1004,8 +1009,8 @@ def check_list_path_option(options: Values) -> None:
10041009
choices=[
10051010
"fast-deps",
10061011
"truststore",
1007-
"no-binary-enable-wheel-cache",
1008-
],
1012+
]
1013+
+ ALWAYS_ENABLED_FEATURES,
10091014
help="Enable new functionality, that may be backward incompatible.",
10101015
)
10111016

src/pip/_internal/commands/install.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
check_legacy_setup_py_options,
3131
)
3232
from pip._internal.utils.compat import WINDOWS
33-
from pip._internal.utils.deprecation import (
34-
LegacyInstallReasonFailedBdistWheel,
35-
deprecated,
36-
)
33+
from pip._internal.utils.deprecation import LegacyInstallReasonFailedBdistWheel
3734
from pip._internal.utils.filesystem import test_writable_dir
3835
from pip._internal.utils.logging import getLogger
3936
from pip._internal.utils.misc import (
@@ -346,24 +343,7 @@ def run(self, options: Values, args: List[str]) -> int:
346343
reqs = self.get_requirements(args, options, finder, session)
347344
check_legacy_setup_py_options(options, reqs)
348345

349-
if "no-binary-enable-wheel-cache" in options.features_enabled:
350-
# TODO: remove format_control from WheelCache when the deprecation cycle
351-
# is over
352-
wheel_cache = WheelCache(options.cache_dir)
353-
else:
354-
if options.format_control.no_binary:
355-
deprecated(
356-
reason=(
357-
"--no-binary currently disables reading from "
358-
"the cache of locally built wheels. In the future "
359-
"--no-binary will not influence the wheel cache."
360-
),
361-
replacement="to use the --no-cache-dir option",
362-
feature_flag="no-binary-enable-wheel-cache",
363-
issue=11453,
364-
gone_in="23.1",
365-
)
366-
wheel_cache = WheelCache(options.cache_dir, options.format_control)
346+
wheel_cache = WheelCache(options.cache_dir)
367347

368348
# Only when installing is it permitted to use PEP 660.
369349
# In other circumstances (pip wheel, pip download) we generate

src/pip/_internal/commands/wheel.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
InstallRequirement,
1515
check_legacy_setup_py_options,
1616
)
17-
from pip._internal.utils.deprecation import deprecated
1817
from pip._internal.utils.misc import ensure_dir, normalize_path
1918
from pip._internal.utils.temp_dir import TempDirectory
2019
from pip._internal.wheel_builder import build, should_build_for_wheel_command
@@ -106,7 +105,6 @@ def run(self, options: Values, args: List[str]) -> int:
106105
session = self.get_default_session(options)
107106

108107
finder = self._build_package_finder(options, session)
109-
wheel_cache = WheelCache(options.cache_dir, options.format_control)
110108

111109
options.wheel_dir = normalize_path(options.wheel_dir)
112110
ensure_dir(options.wheel_dir)
@@ -122,24 +120,7 @@ def run(self, options: Values, args: List[str]) -> int:
122120
reqs = self.get_requirements(args, options, finder, session)
123121
check_legacy_setup_py_options(options, reqs)
124122

125-
if "no-binary-enable-wheel-cache" in options.features_enabled:
126-
# TODO: remove format_control from WheelCache when the deprecation cycle
127-
# is over
128-
wheel_cache = WheelCache(options.cache_dir)
129-
else:
130-
if options.format_control.no_binary:
131-
deprecated(
132-
reason=(
133-
"--no-binary currently disables reading from "
134-
"the cache of locally built wheels. In the future "
135-
"--no-binary will not influence the wheel cache."
136-
),
137-
replacement="to use the --no-cache-dir option",
138-
feature_flag="no-binary-enable-wheel-cache",
139-
issue=11453,
140-
gone_in="23.1",
141-
)
142-
wheel_cache = WheelCache(options.cache_dir, options.format_control)
123+
wheel_cache = WheelCache(options.cache_dir)
143124

144125
preparer = self.make_requirement_preparer(
145126
temp_build_dir=directory,

tests/functional/test_install.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,7 @@ def test_install_no_binary_uses_local_backend(
16561656
assert os.path.isfile(marker), "Local PEP 517 backend not used"
16571657

16581658

1659-
def test_install_no_binary_disables_cached_wheels(
1659+
def test_install_no_binary_uses_cached_wheels(
16601660
script: PipTestEnvironment, data: TestData
16611661
) -> None:
16621662
# Seed the cache
@@ -1673,7 +1673,7 @@ def test_install_no_binary_disables_cached_wheels(
16731673
)
16741674
assert "Successfully installed upper-2.0" in str(res), str(res)
16751675
# upper is built and not obtained from cache
1676-
assert "Building wheel for upper" in str(res), str(res)
1676+
assert "Building wheel for upper" not in str(res), str(res)
16771677

16781678

16791679
def test_install_editable_with_wrong_egg_name(

tests/unit/test_cache.py

Lines changed: 5 additions & 6 deletions
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

Lines changed: 2 additions & 3 deletions
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)