From 251fec31b439ce41eef4f32f4f54535bf8679f66 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Fri, 28 Nov 2025 23:28:53 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AADrop=20PkgReq=20stub=20@=20`ansible?= =?UTF-8?q?.galaxy.collection`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This tiny restructuring allows us to get rid of the type ignore. --- lib/ansible/galaxy/collection/__init__.py | 3 --- lib/ansible/galaxy/dependency_resolution/dataclasses.py | 7 ++++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py index 5656227e7e1..9633b6b690a 100644 --- a/lib/ansible/galaxy/collection/__init__.py +++ b/lib/ansible/galaxy/collection/__init__.py @@ -36,9 +36,6 @@ from itertools import chain try: from packaging.requirements import Requirement as PkgReq except ImportError: - class PkgReq: # type: ignore[no-redef] - pass - HAS_PACKAGING = False else: HAS_PACKAGING = True diff --git a/lib/ansible/galaxy/dependency_resolution/dataclasses.py b/lib/ansible/galaxy/dependency_resolution/dataclasses.py index 389eef7122a..d9b1a3a84c7 100644 --- a/lib/ansible/galaxy/dependency_resolution/dataclasses.py +++ b/lib/ansible/galaxy/dependency_resolution/dataclasses.py @@ -28,12 +28,13 @@ if t.TYPE_CHECKING: from ansible.errors import AnsibleError, AnsibleAssertionError from ansible.galaxy.api import GalaxyAPI -from ansible.galaxy.collection import HAS_PACKAGING, PkgReq from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text from ansible.module_utils.common.arg_spec import ArgumentSpecValidator from ansible.utils.collection_loader import AnsibleCollectionRef from ansible.utils.display import Display +from .. import collection as _glx_coll_mod + _ALLOW_CONCRETE_POINTER_IN_SOURCE = False # NOTE: This is a feature flag _GALAXY_YAML = b'galaxy.yml' @@ -306,10 +307,10 @@ class _ComputedReqKindsMixin: if not req['version']: del req['version'] else: - if not HAS_PACKAGING: + if not _glx_coll_mod.HAS_PACKAGING: raise AnsibleError("Failed to import packaging, check that a supported version is installed") try: - pkg_req = PkgReq(collection_input) + pkg_req = _glx_coll_mod.PkgReq(collection_input) except Exception as e: # packaging doesn't know what this is, let it fly, better errors happen in from_requirement_dict req['name'] = collection_input