Skip to content

Commit c25fe60

Browse files
mayeutjoerick
authored andcommitted
fix: image deprecation warning (#2314)
1 parent a880bf5 commit c25fe60

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

cibuildwheel/options.py

+17-19
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ def __init__(
567567
self.command_line_arguments = command_line_arguments
568568
self.env = env
569569
self._defaults = defaults
570-
self._image_warnings = set[str]()
570+
self._image_warnings: set[str] = set()
571571

572572
self.reader = OptionsReader(
573573
None if defaults else self.config_file_path,
@@ -689,6 +689,20 @@ def globals(self) -> GlobalOptions:
689689
allow_empty=allow_empty,
690690
)
691691

692+
def _check_pinned_image(self, value: str, pinned_images: Mapping[str, str]) -> None:
693+
if (
694+
value in {"manylinux1", "manylinux2010", "manylinux_2_24", "musllinux_1_1"}
695+
and value not in self._image_warnings
696+
):
697+
self._image_warnings.add(value)
698+
msg = (
699+
f"Deprecated image {value!r}. This value will not work"
700+
" in a future version of cibuildwheel. Either upgrade to a supported"
701+
" image or continue using the deprecated image by pinning directly"
702+
f" to {pinned_images[value]!r}."
703+
)
704+
log.warning(msg)
705+
692706
def build_options(self, identifier: str | None) -> BuildOptions:
693707
"""
694708
Compute BuildOptions for a single run configuration.
@@ -786,24 +800,7 @@ def build_options(self, identifier: str | None) -> BuildOptions:
786800
# default to manylinux2014
787801
image = pinned_images["manylinux2014"]
788802
elif config_value in pinned_images:
789-
if (
790-
config_value
791-
in {
792-
"manylinux1",
793-
"manylinux2010",
794-
"manylinux_2_24",
795-
"musllinux_1_1",
796-
}
797-
and config_value not in self._image_warnings
798-
):
799-
self._image_warnings.add(config_value)
800-
msg = (
801-
f"Deprecated image {config_value!r}. This value will not work"
802-
" in a future version of cibuildwheel. Either upgrade to a supported"
803-
" image or continue using the deprecated image by pinning directly"
804-
f" to {pinned_images[config_value]!r}."
805-
)
806-
log.warning(msg)
803+
self._check_pinned_image(config_value, pinned_images)
807804
image = pinned_images[config_value]
808805
else:
809806
image = config_value
@@ -818,6 +815,7 @@ def build_options(self, identifier: str | None) -> BuildOptions:
818815
if not config_value:
819816
image = pinned_images["musllinux_1_2"]
820817
elif config_value in pinned_images:
818+
self._check_pinned_image(config_value, pinned_images)
821819
image = pinned_images[config_value]
822820
else:
823821
image = config_value

unit_test/options_test.py

+33
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,36 @@ def test_free_threaded_support(
459459
assert EnableGroups.CPythonFreeThreading in options.globals.build_selector.enable
460460
else:
461461
assert EnableGroups.CPythonFreeThreading not in options.globals.build_selector.enable
462+
463+
464+
@pytest.mark.parametrize(
465+
("image", "deprecated"),
466+
[
467+
("manylinux1", True),
468+
("manylinux2010", True),
469+
("manylinux2014", False),
470+
("manylinux_2_24", True),
471+
("manylinux_2_28", False),
472+
("manylinux_2_34", False),
473+
("musllinux_1_1", True),
474+
("musllinux_1_2", False),
475+
],
476+
)
477+
def test_deprecated_image(image: str, deprecated: bool, capsys: pytest.CaptureFixture[str]) -> None:
478+
args = CommandLineArguments.defaults()
479+
env = {
480+
"CIBW_ARCHS": "x86_64",
481+
"CIBW_MANYLINUX_X86_64_IMAGE": image if image.startswith("manylinux") else "",
482+
"CIBW_MUSLLINUX_X86_64_IMAGE": image if image.startswith("musllinux") else "",
483+
}
484+
options = Options(platform="linux", command_line_arguments=args, env=env)
485+
bo = options.build_options(None)
486+
images = bo.manylinux_images if image.startswith("manylinux") else bo.musllinux_images
487+
assert images is not None
488+
resolved_image = images["x86_64"]
489+
captured = capsys.readouterr()
490+
if deprecated:
491+
assert f"Deprecated image {image!r}" in captured.err
492+
assert f"{resolved_image!r}" in captured.err
493+
else:
494+
assert captured.err == ""

0 commit comments

Comments
 (0)