Skip to content

Commit

Permalink
Fix failing tests for roles inside collection repository
Browse files Browse the repository at this point in the history
  • Loading branch information
audgirka committed Jul 18, 2023
1 parent 0b72772 commit 293281f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 13 additions & 4 deletions src/ansible_compat/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import contextlib
import glob
import fnmatch
import importlib
import json
import logging
Expand Down Expand Up @@ -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,
Expand All @@ -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":
Expand Down

0 comments on commit 293281f

Please sign in to comment.