-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid galaxy install failure with already symlinked collections (#166)
* Avoid galaxy install failure with already symlinked collections Fixes: #165 * chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a986b49
commit eb771f5
Showing
3 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
"""Utilities for loading various files.""" | ||
from __future__ import annotations | ||
|
||
import os | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
from ansible_compat.errors import InvalidPrerequisiteError | ||
|
||
|
||
def yaml_from_file(filepath: str) -> Any: | ||
"""Return a loaded YAML file.""" | ||
with open(filepath, encoding="utf-8") as content: | ||
return yaml.load(content, Loader=yaml.FullLoader) | ||
|
||
|
||
def colpath_from_path(filepath: str) -> str | None: | ||
"""Return a FQCN from a path.""" | ||
galaxy_file = f"{filepath}/galaxy.yml" | ||
if os.path.exists(galaxy_file): | ||
galaxy = yaml_from_file(galaxy_file) | ||
for k in ("namespace", "name"): | ||
if k not in galaxy: | ||
raise InvalidPrerequisiteError( | ||
f"{galaxy_file} is missing the following mandatory field {k}" | ||
) | ||
return f"{galaxy['namespace']}/{galaxy['name']}" | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters