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