fix: more reliably validate Podman API version (#2016)
* fix: parse version strings that include dashes It's possible for some container engines to report their versions with a dash (e.g., "4.9.4-rhel"), which breaks packaging.version.Version's ability to parse the string. This commit introduces a version_from_string method which santizies the version string and returns an instance of Version. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * cleanup: pacify ruff * cleanup: further pacify ruff * fix: properly define _version_from_string method Also, lift the method up and prefix with a "_" to better match the existing conventions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor: more robust podman ver check Use the "podman --version" command instead of "podman version -f {{json .}}" for better reliability across distributions. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: oci engine version check Lower Docker API check to 1.41 Podman versions are not PEP440 compliant, remove distro specific suffixes before parsing. Add tests with real-world outputs and some made up ones. * fix: UX on OCIEngineTooOldError * Add FlexibleVersion per review comment --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: mayeut <mayeut@users.noreply.github.com>
This commit is contained in:
co-authored by
pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
mayeut
parent
735e88deba
commit
dfd01af9aa
@@ -6,6 +6,7 @@ from pathlib import PurePath
|
||||
import pytest
|
||||
|
||||
from cibuildwheel.util import (
|
||||
FlexibleVersion,
|
||||
find_compatible_wheel,
|
||||
fix_ansi_codes_for_github_actions,
|
||||
format_safe,
|
||||
@@ -206,3 +207,17 @@ def test_parse_key_value_string():
|
||||
"name": ["docker"],
|
||||
"create_args": [],
|
||||
}
|
||||
|
||||
|
||||
def test_flexible_version_comparisons():
|
||||
assert FlexibleVersion("2.0") == FlexibleVersion("2")
|
||||
assert FlexibleVersion("2.0") < FlexibleVersion("2.1")
|
||||
assert FlexibleVersion("2.1") > FlexibleVersion("2")
|
||||
assert FlexibleVersion("1.9.9") < FlexibleVersion("2.0")
|
||||
assert FlexibleVersion("1.10") > FlexibleVersion("1.9.9")
|
||||
assert FlexibleVersion("3.0.1") > FlexibleVersion("3.0")
|
||||
assert FlexibleVersion("3.0") < FlexibleVersion("3.0.1")
|
||||
# Suffix should not affect comparisons
|
||||
assert FlexibleVersion("1.0.1-rhel") > FlexibleVersion("1.0")
|
||||
assert FlexibleVersion("1.0.1-rhel") < FlexibleVersion("1.1")
|
||||
assert FlexibleVersion("1.0.1") == FlexibleVersion("v1.0.1")
|
||||
|
||||
Reference in New Issue
Block a user