Skip to content

Commit

Permalink
Install collections before linting (#1427)
Browse files Browse the repository at this point in the history
When run inside a collection, first install it to temp directory
in order to avoid errors from playbooks that assume it is installed,
like molecule scenarios.
  • Loading branch information
ssbarnea authored Mar 4, 2021
1 parent 532918d commit 0dd9a7f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/ansiblelint/_prerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,19 @@ def _perform_mockings() -> None:
if options.mock_modules:
for module_name in options.mock_modules:
_make_module_stub(module_name)

# if inside a collection repo, symlink it to simulate its installed state
if not os.path.exists("galaxy.yml"):
return
yaml = yaml_from_file("galaxy.yml")
namespace = yaml.get('namespace', None)
collection = yaml.get('name', None)
if not namespace or not collection:
return
p = pathlib.Path(
f"{options.project_dir}/.cache/collections/ansible_collections/{ namespace }"
)
p.mkdir(parents=True, exist_ok=True)
link_path = p / collection
if not link_path.exists():
link_path.symlink_to(pathlib.Path("../../../..", target_is_directory=True))

0 comments on commit 0dd9a7f

Please sign in to comment.