5252
5353_logger = logging .getLogger (__name__ )
5454# regex to extract the first version from a collection range specifier
55- version_re = re .compile (":[>=<]*([^,]*)" )
56- namespace_re = re .compile ("^[a-z][a-z0-9_]+$" )
55+ version_re = re .compile (r ":[>=<]*([^,]*)" )
56+ namespace_re = re .compile (r "^[a-z][a-z0-9_]+$" )
5757
5858
5959class AnsibleWarning (Warning ):
@@ -660,11 +660,10 @@ def prepare_environment( # noqa: C901
660660 if not install_local :
661661 return
662662
663- for gpath in search_galaxy_paths (self .project_dir ):
663+ for item in search_galaxy_paths (self .project_dir ):
664664 # processing all found galaxy.yml files
665- galaxy_path = Path (gpath )
666- if galaxy_path .exists ():
667- data = yaml_from_file (galaxy_path )
665+ if item .exists ():
666+ data = yaml_from_file (item )
668667 if isinstance (data , dict ) and "dependencies" in data :
669668 for name , required_version in data ["dependencies" ].items ():
670669 _logger .info (
@@ -685,7 +684,8 @@ def prepare_environment( # noqa: C901
685684 destination = destination ,
686685 )
687686
688- if (self .project_dir / "galaxy.yml" ).exists ():
687+ galaxy_path = self .project_dir / "galaxy.yml"
688+ if (galaxy_path ).exists ():
689689 if destination :
690690 # while function can return None, that would not break the logic
691691 colpath = Path (
@@ -979,20 +979,27 @@ def _get_galaxy_role_name(galaxy_infos: dict[str, Any]) -> str:
979979 return result
980980
981981
982- def search_galaxy_paths (search_dir : Path ) -> list [str ]:
983- """Search for galaxy paths (only one level deep)."""
984- galaxy_paths : list [str ] = []
985- for file in ["." , * os .listdir (search_dir )]:
982+ def search_galaxy_paths (search_dir : Path ) -> list [Path ]:
983+ """Search for galaxy paths (only one level deep).
984+
985+ Returns:
986+ list[Path]: List of galaxy.yml found.
987+ """
988+ galaxy_paths : list [Path ] = []
989+ for item in [Path (), * search_dir .iterdir ()]:
986990 # We ignore any folders that are not valid namespaces, just like
987991 # ansible galaxy does at this moment.
988- if file != "." and not namespace_re .match (file ):
992+ file_path = item .resolve ()
993+ if file_path .is_file () and file_path .name == "galaxy.yml" :
994+ galaxy_paths .append (file_path )
989995 continue
990- file_path = search_dir / file / "galaxy.yml"
991- if file_path .is_file ():
992- galaxy_paths .append (str (file_path ))
996+ if file_path .is_dir () and namespace_re .match (file_path .name ):
997+ file_path /= "galaxy.yml"
998+ if file_path .exists ():
999+ galaxy_paths .append (file_path )
9931000 return galaxy_paths
9941001
9951002
9961003def is_url (name : str ) -> bool :
9971004 """Return True if a dependency name looks like an URL."""
998- return bool (re .match ("^git[+@]" , name ))
1005+ return bool (re .match (r "^git[+@]" , name ))
0 commit comments