|
16 | 16 |
|
17 | 17 | import subprocess_tee |
18 | 18 | from packaging.version import Version |
19 | | -from packaging.version import parse as parse_version |
20 | 19 |
|
21 | 20 | from ansible_compat.config import ( |
22 | 21 | AnsibleConfig, |
@@ -58,6 +57,18 @@ class Collection: |
58 | 57 | path: Path |
59 | 58 |
|
60 | 59 |
|
| 60 | +class CollectionVersion(Version): |
| 61 | + """Collection version.""" |
| 62 | + |
| 63 | + def __init__(self, version: str) -> None: |
| 64 | + """Initialize collection version.""" |
| 65 | + # As packaging Version class does not support wildcard, we convert it |
| 66 | + # to "0", as this being the smallest version possible. |
| 67 | + if version == "*": |
| 68 | + version = "0" |
| 69 | + super().__init__(version) |
| 70 | + |
| 71 | + |
61 | 72 | # pylint: disable=too-many-instance-attributes |
62 | 73 | class Runtime: |
63 | 74 | """Ansible Runtime manager.""" |
@@ -191,7 +202,7 @@ def _ensure_module_available(self) -> None: |
191 | 202 | msg = "Unable to find Ansible python module." |
192 | 203 | raise RuntimeError(msg) |
193 | 204 |
|
194 | | - ansible_module_version = parse_version( |
| 205 | + ansible_module_version = Version( |
195 | 206 | ansible_release_module.__version__, |
196 | 207 | ) |
197 | 208 | if ansible_module_version != self.version: |
@@ -326,7 +337,7 @@ def install_collection( |
326 | 337 | # if the range requires a pre-release, we need to manuall add the --pre |
327 | 338 | # flag when needed. |
328 | 339 | matches = version_re.search(str(collection)) |
329 | | - if matches and Version(matches[1]).is_prerelease: |
| 340 | + if matches and CollectionVersion(matches[1]).is_prerelease: |
330 | 341 | cmd.append("--pre") |
331 | 342 |
|
332 | 343 | cpaths: list[str] = self.config.collections_paths |
@@ -592,10 +603,10 @@ def require_collection( |
592 | 603 |
|
593 | 604 | with mpath.open(encoding="utf-8") as f: |
594 | 605 | manifest = json.loads(f.read()) |
595 | | - found_version = parse_version( |
| 606 | + found_version = CollectionVersion( |
596 | 607 | manifest["collection_info"]["version"], |
597 | 608 | ) |
598 | | - if version and found_version < parse_version(version): |
| 609 | + if version and found_version < CollectionVersion(version): |
599 | 610 | if install: |
600 | 611 | self.install_collection(f"{name}:>={version}") |
601 | 612 | self.require_collection(name, version, install=False) |
|
0 commit comments