|
8 | 8 | import shutil
|
9 | 9 | import subprocess
|
10 | 10 | import sys
|
| 11 | +import textwrap |
11 | 12 | import typing
|
12 | 13 | import uuid
|
13 | 14 | from collections.abc import Mapping, Sequence
|
|
17 | 18 | from types import TracebackType
|
18 | 19 | from typing import IO, Dict, Literal
|
19 | 20 |
|
20 |
| -from packaging.version import InvalidVersion, Version |
21 |
| - |
22 | 21 | from ._compat.typing import Self, assert_never
|
23 | 22 | from .errors import OCIEngineTooOldError
|
24 | 23 | from .logger import log
|
25 | 24 | from .typing import PathOrStr, PopenBytes
|
26 | 25 | from .util import (
|
27 | 26 | CIProvider,
|
| 27 | + FlexibleVersion, |
28 | 28 | call,
|
29 | 29 | detect_ci_provider,
|
30 | 30 | parse_key_value_string,
|
@@ -103,25 +103,45 @@ def _check_engine_version(engine: OCIContainerEngineConfig) -> None:
|
103 | 103 | version_string = call(engine.name, "version", "-f", "{{json .}}", capture_stdout=True)
|
104 | 104 | version_info = json.loads(version_string.strip())
|
105 | 105 | if engine.name == "docker":
|
106 |
| - # --platform support was introduced in 1.32 as experimental |
107 |
| - # docker cp, as used by cibuildwheel, has been fixed in v24 => API 1.43, https://github.com/moby/moby/issues/38995 |
108 |
| - client_api_version = Version(version_info["Client"]["ApiVersion"]) |
109 |
| - engine_api_version = Version(version_info["Server"]["ApiVersion"]) |
110 |
| - version_supported = min(client_api_version, engine_api_version) >= Version("1.43") |
| 106 | + client_api_version = FlexibleVersion(version_info["Client"]["ApiVersion"]) |
| 107 | + server_api_version = FlexibleVersion(version_info["Server"]["ApiVersion"]) |
| 108 | + # --platform support was introduced in 1.32 as experimental, 1.41 removed the experimental flag |
| 109 | + version = min(client_api_version, server_api_version) |
| 110 | + minimum_version = FlexibleVersion("1.41") |
| 111 | + minimum_version_str = "20.10.0" # docker version |
| 112 | + error_msg = textwrap.dedent( |
| 113 | + f""" |
| 114 | + Build failed because {engine.name} is too old. |
| 115 | +
|
| 116 | + cibuildwheel requires {engine.name}>={minimum_version_str} running API version {minimum_version}. |
| 117 | + The API version found by cibuildwheel is {version}. |
| 118 | + """ |
| 119 | + ) |
111 | 120 | elif engine.name == "podman":
|
112 |
| - client_api_version = Version(version_info["Client"]["APIVersion"]) |
| 121 | + # podman uses the same version string for "Version" & "ApiVersion" |
| 122 | + client_version = FlexibleVersion(version_info["Client"]["Version"]) |
113 | 123 | if "Server" in version_info:
|
114 |
| - engine_api_version = Version(version_info["Server"]["APIVersion"]) |
| 124 | + server_version = FlexibleVersion(version_info["Server"]["Version"]) |
115 | 125 | else:
|
116 |
| - engine_api_version = client_api_version |
| 126 | + server_version = client_version |
117 | 127 | # --platform support was introduced in v3
|
118 |
| - version_supported = min(client_api_version, engine_api_version) >= Version("3") |
| 128 | + version = min(client_version, server_version) |
| 129 | + minimum_version = FlexibleVersion("3") |
| 130 | + error_msg = textwrap.dedent( |
| 131 | + f""" |
| 132 | + Build failed because {engine.name} is too old. |
| 133 | +
|
| 134 | + cibuildwheel requires {engine.name}>={minimum_version}. |
| 135 | + The version found by cibuildwheel is {version}. |
| 136 | + """ |
| 137 | + ) |
119 | 138 | else:
|
120 | 139 | assert_never(engine.name)
|
121 |
| - if not version_supported: |
122 |
| - raise OCIEngineTooOldError() from None |
123 |
| - except (subprocess.CalledProcessError, KeyError, InvalidVersion) as e: |
124 |
| - raise OCIEngineTooOldError() from e |
| 140 | + if version < minimum_version: |
| 141 | + raise OCIEngineTooOldError(error_msg) from None |
| 142 | + except (subprocess.CalledProcessError, KeyError, ValueError) as e: |
| 143 | + msg = f"Build failed because {engine.name} is too old or is not working properly." |
| 144 | + raise OCIEngineTooOldError(msg) from e |
125 | 145 |
|
126 | 146 |
|
127 | 147 | class OCIContainer:
|
|
0 commit comments