From 804fb13e20cb88db6343ffd4c23b139539f1626e Mon Sep 17 00:00:00 2001 From: gmuloc Date: Wed, 13 Nov 2024 11:04:16 +0100 Subject: [PATCH 1/3] Feat(plugins): Verify pyavd extras again --- .../arista/avd/plugins/action/verify_requirements.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ansible_collections/arista/avd/plugins/action/verify_requirements.py b/ansible_collections/arista/avd/plugins/action/verify_requirements.py index f7677eccb4c..0c1d97b4eac 100644 --- a/ansible_collections/arista/avd/plugins/action/verify_requirements.py +++ b/ansible_collections/arista/avd/plugins/action/verify_requirements.py @@ -112,6 +112,13 @@ def _validate_python_requirements(requirements: list, info: dict) -> bool: msg = f"Wrong format for requirement {raw_req}" raise AnsibleActionFail(msg) from exc + if req.extras: + import importlib_metadata + + for subreq_name in importlib_metadata.metadata(req.name).get_all("Requires-Dist"): + subreq = Requirement(subreq_name) + if subreq.marker: + requirements.extend(subreq_name for marker in subreq.marker._markers if str(marker[0]) == "extra" and str(marker[2]) in req.extras) if RUNNING_FROM_SOURCE and req.name == "pyavd": display.vvv("AVD is running from source, *not* checking pyavd version.", "Verify Requirements") requirements_dict["valid"][req.name] = { From 15342e66f72912d8ea1b6149992798a8bf754ba5 Mon Sep 17 00:00:00 2001 From: gmuloc Date: Wed, 13 Nov 2024 11:27:19 +0100 Subject: [PATCH 2/3] Fix: Use standard lib Duh --- .../arista/avd/plugins/action/verify_requirements.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ansible_collections/arista/avd/plugins/action/verify_requirements.py b/ansible_collections/arista/avd/plugins/action/verify_requirements.py index 0c1d97b4eac..d2076c6f7a1 100644 --- a/ansible_collections/arista/avd/plugins/action/verify_requirements.py +++ b/ansible_collections/arista/avd/plugins/action/verify_requirements.py @@ -113,9 +113,9 @@ def _validate_python_requirements(requirements: list, info: dict) -> bool: raise AnsibleActionFail(msg) from exc if req.extras: - import importlib_metadata + from importlib import metadata - for subreq_name in importlib_metadata.metadata(req.name).get_all("Requires-Dist"): + for subreq_name in metadata.metadata(req.name).get_all("Requires-Dist"): subreq = Requirement(subreq_name) if subreq.marker: requirements.extend(subreq_name for marker in subreq.marker._markers if str(marker[0]) == "extra" and str(marker[2]) in req.extras) From 471b5c02bda756bec8d1aab538262a4dfdd76e49 Mon Sep 17 00:00:00 2001 From: gmuloc Date: Wed, 13 Nov 2024 11:52:47 +0100 Subject: [PATCH 3/3] Refactor: Fix importing --- .../arista/avd/plugins/action/verify_requirements.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ansible_collections/arista/avd/plugins/action/verify_requirements.py b/ansible_collections/arista/avd/plugins/action/verify_requirements.py index d2076c6f7a1..f7010183819 100644 --- a/ansible_collections/arista/avd/plugins/action/verify_requirements.py +++ b/ansible_collections/arista/avd/plugins/action/verify_requirements.py @@ -4,7 +4,7 @@ import json import sys -from importlib.metadata import Distribution, PackageNotFoundError, version +from importlib.metadata import Distribution, PackageNotFoundError, metadata, version from pathlib import Path from subprocess import PIPE, Popen from typing import Any @@ -113,12 +113,11 @@ def _validate_python_requirements(requirements: list, info: dict) -> bool: raise AnsibleActionFail(msg) from exc if req.extras: - from importlib import metadata - - for subreq_name in metadata.metadata(req.name).get_all("Requires-Dist"): + for subreq_name in metadata(req.name).get_all("Requires-Dist"): subreq = Requirement(subreq_name) if subreq.marker: requirements.extend(subreq_name for marker in subreq.marker._markers if str(marker[0]) == "extra" and str(marker[2]) in req.extras) + if RUNNING_FROM_SOURCE and req.name == "pyavd": display.vvv("AVD is running from source, *not* checking pyavd version.", "Verify Requirements") requirements_dict["valid"][req.name] = {