Get the major/minor parts of the Docker/Podman version. Some of the operations we perform in this module rely on some Podman features that are not available across all of our platforms. In order to have a proper fallback, we need to know the Podman version. More specifically, we're fine
()
| 34 | |
| 35 | |
| 36 | def get_runtime_version() -> tuple[int, int]: |
| 37 | """Get the major/minor parts of the Docker/Podman version. |
| 38 | |
| 39 | Some of the operations we perform in this module rely on some Podman features |
| 40 | that are not available across all of our platforms. In order to have a proper |
| 41 | fallback, we need to know the Podman version. More specifically, we're fine with |
| 42 | just knowing the major and minor version, since writing/installing a full-blown |
| 43 | semver parser is an overkill. |
| 44 | """ |
| 45 | # Get the Docker/Podman version, using a Go template. |
| 46 | podman = init_podman_command() |
| 47 | query = "{{.Client.Version}}" |
| 48 | |
| 49 | try: |
| 50 | version = podman.run(["version", "-f", query]) |
| 51 | assert isinstance(version, str) |
| 52 | except Exception as e: |
| 53 | msg = f"Could not get the version of Podman: {e}" |
| 54 | raise RuntimeError(msg) from e |
| 55 | |
| 56 | # Parse this version and return the major/minor parts, since we don't need the |
| 57 | # rest. |
| 58 | try: |
| 59 | major, minor, _ = version.split(".", 3) |
| 60 | return (int(major), int(minor)) |
| 61 | except ValueError as e: |
| 62 | msg = ( |
| 63 | f"Could not parse the version of Podman (found: '{version}') due to the" |
| 64 | f" following error: {e}" |
| 65 | ) |
| 66 | raise RuntimeError(msg) |
| 67 | |
| 68 | |
| 69 | def get_podman_path() -> Path | None: |
no test coverage detected