From 293281f21d099eb53c324787bf92067d9b432fb2 Mon Sep 17 00:00:00 2001 From: Ajinkya Udgirkar Date: Tue, 18 Jul 2023 18:00:55 +0530 Subject: [PATCH] Fix failing tests for roles inside collection repository --- requirements.txt | 2 +- src/ansible_compat/runtime.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index bb422305..28cba460 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.9 # by the following command: # -# pip-compile --extra=docs --extra=test --output-file=requirements.txt --resolver=backtracking --strip-extras --unsafe-package=ansible-core --unsafe-package=resolvelib --unsafe-package=typing_extensions pyproject.toml +# pip-compile --extra=docs --extra=test --output-file=requirements.txt --strip-extras --unsafe-package=ansible-core --unsafe-package=resolvelib --unsafe-package=typing_extensions pyproject.toml # argparse-manpage==4.2 # via ansible-compat (pyproject.toml) diff --git a/src/ansible_compat/runtime.py b/src/ansible_compat/runtime.py index bee748d6..b3237963 100644 --- a/src/ansible_compat/runtime.py +++ b/src/ansible_compat/runtime.py @@ -2,7 +2,7 @@ from __future__ import annotations import contextlib -import glob +import fnmatch import importlib import json import logging @@ -553,6 +553,17 @@ def install_requirements( # noqa: C901 _logger.error(result.stderr) raise AnsibleCommandError(result) + def search_galaxy_paths(self, search_dir: Path) -> list[str]: + """Search for galaxy paths recursively.""" + galaxy_paths: list[str] = [] + for file in os.listdir(search_dir): + file_path = Path(file) + if file_path.is_dir(): + galaxy_paths.extend(self.search_galaxy_paths(file_path)) + elif fnmatch.fnmatch(file, "galaxy.yml"): + galaxy_paths.append(str(search_dir / file)) + return galaxy_paths + # pylint: disable=too-many-locals def prepare_environment( # noqa: C901 self, @@ -575,9 +586,7 @@ def prepare_environment( # noqa: C901 for req_file in REQUIREMENT_LOCATIONS: self.install_requirements(Path(req_file), retry=retry, offline=offline) - galaxy_paths = glob.glob( - "**/galaxy.yml", root_dir=self.project_dir, recursive=True - ) + galaxy_paths = self.search_galaxy_paths(self.project_dir) if not galaxy_paths: galaxy_paths = ["galaxy.yml"] if len(galaxy_paths) > 1 and galaxy_paths[0] == "galaxy.yml":