🧪Drop PkgReq stub @ `ansible.galaxy.collection`

This tiny restructuring allows us to get rid of the type ignore.
pull/86273/head
Sviatoslav Sydorenko 5 days ago committed by 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко)
parent cc839f013a
commit 251fec31b4

@ -36,9 +36,6 @@ from itertools import chain
try: try:
from packaging.requirements import Requirement as PkgReq from packaging.requirements import Requirement as PkgReq
except ImportError: except ImportError:
class PkgReq: # type: ignore[no-redef]
pass
HAS_PACKAGING = False HAS_PACKAGING = False
else: else:
HAS_PACKAGING = True HAS_PACKAGING = True

@ -28,12 +28,13 @@ if t.TYPE_CHECKING:
from ansible.errors import AnsibleError, AnsibleAssertionError from ansible.errors import AnsibleError, AnsibleAssertionError
from ansible.galaxy.api import GalaxyAPI 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.text.converters import to_bytes, to_native, to_text
from ansible.module_utils.common.arg_spec import ArgumentSpecValidator from ansible.module_utils.common.arg_spec import ArgumentSpecValidator
from ansible.utils.collection_loader import AnsibleCollectionRef from ansible.utils.collection_loader import AnsibleCollectionRef
from ansible.utils.display import Display 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 _ALLOW_CONCRETE_POINTER_IN_SOURCE = False # NOTE: This is a feature flag
_GALAXY_YAML = b'galaxy.yml' _GALAXY_YAML = b'galaxy.yml'
@ -306,10 +307,10 @@ class _ComputedReqKindsMixin:
if not req['version']: if not req['version']:
del req['version'] del req['version']
else: 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") raise AnsibleError("Failed to import packaging, check that a supported version is installed")
try: try:
pkg_req = PkgReq(collection_input) pkg_req = _glx_coll_mod.PkgReq(collection_input)
except Exception as e: except Exception as e:
# packaging doesn't know what this is, let it fly, better errors happen in from_requirement_dict # packaging doesn't know what this is, let it fly, better errors happen in from_requirement_dict
req['name'] = collection_input req['name'] = collection_input

Loading…
Cancel
Save