From 4b9cf46af6451c0ebc2003f489430f31f291238d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sun, 21 Feb 2021 12:20:51 +0000 Subject: [PATCH] Fixes installation of standalone roles - correct two bugs that prevented standalone roles symlinks from being correctly created - adds extra logging - assure pre-run steps log to stderr --- src/ansiblelint/_prerun.py | 14 ++++++++++---- test/test_prerun.py | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/ansiblelint/_prerun.py b/src/ansiblelint/_prerun.py index 21427ba8bb..6a89e609c1 100644 --- a/src/ansiblelint/_prerun.py +++ b/src/ansiblelint/_prerun.py @@ -110,7 +110,7 @@ def prepare_environment() -> None: "requirements.yml", ] - print("Running %s" % " ".join(cmd)) + print("Running %s" % " ".join(cmd), file=sys.stderr) run = subprocess.run( cmd, universal_newlines=True, @@ -135,7 +135,7 @@ def prepare_environment() -> None: "requirements.yml", ] - print("Running %s" % " ".join(cmd)) + print("Running %s" % " ".join(cmd), file=sys.stderr) run = subprocess.run( cmd, universal_newlines=True, @@ -157,7 +157,7 @@ def _install_galaxy_role() -> None: if not os.path.exists("meta/main.yml"): return yaml = yaml_from_file("meta/main.yml") - if 'galaxy_info' not in 'yaml': + if 'galaxy_info' not in yaml: return role_name = yaml['galaxy_info'].get('role_name', None) role_author = yaml['galaxy_info'].get('author', None) @@ -170,8 +170,14 @@ def _install_galaxy_role() -> None: p = pathlib.Path(".cache/roles") p.mkdir(parents=True, exist_ok=True) link_path = p / f"{role_author}.{role_name}" - if not link_path.exists: + # despite documentation stating that is_file() reports true for symlinks, + # it appears that is_dir() reports true instead, so we rely on exits(). + if not link_path.exists(): link_path.symlink_to(pathlib.Path("../..", target_is_directory=True)) + print( + f"Using {link_path} symlink to current repository in order to enable Ansible to find the role using its expected full name.", + file=sys.stderr, + ) def _prepare_ansible_paths() -> None: diff --git a/test/test_prerun.py b/test/test_prerun.py index 6786c48141..a4d04db6d6 100644 --- a/test/test_prerun.py +++ b/test/test_prerun.py @@ -12,8 +12,8 @@ def test_prerun_reqs_v1() -> None: ) ) result = run_ansible_lint(".", cwd=cwd) - assert "Running ansible-galaxy role install" in result.stdout - assert "Running ansible-galaxy collection install" not in result.stdout + assert "Running ansible-galaxy role install" in result.stderr + assert "Running ansible-galaxy collection install" not in result.stderr assert result.returncode == 0 @@ -25,6 +25,6 @@ def test_prerun_reqs_v2() -> None: ) ) result = run_ansible_lint(".", cwd=cwd) - assert "Running ansible-galaxy role install" in result.stdout - assert "Running ansible-galaxy collection install" in result.stdout + assert "Running ansible-galaxy role install" in result.stderr + assert "Running ansible-galaxy collection install" in result.stderr assert result.returncode == 0