From 90fb69aed7be912f50e07ec0fd5ec5a02008a8fa Mon Sep 17 00:00:00 2001 From: FliegenKLATSCH Date: Wed, 29 Nov 2023 14:06:51 +0100 Subject: [PATCH] Look for ansible binary in the same path the linter (#3903) --- src/ansiblelint/__main__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index 648c682f95..d3f48e49cf 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -285,7 +285,7 @@ def fix(runtime_options: Options, result: LintResult, rules: RulesCollection) -> def main(argv: list[str] | None = None) -> int: """Linter CLI entry point.""" # alter PATH if needed (venv support) - path_inject() + path_inject(argv[0] if argv and argv[0] else "") if argv is None: # pragma: no cover argv = sys.argv @@ -410,7 +410,7 @@ def _run_cli_entrypoint() -> None: raise SystemExit(exc) from exc -def path_inject() -> None: +def path_inject(own_location: str = "") -> None: """Add python interpreter path to top of PATH to fix outside venv calling.""" # This make it possible to call ansible-lint that was installed inside a # virtualenv without having to pre-activate it. Otherwise subprocess will @@ -451,6 +451,14 @@ def path_inject() -> None: ): inject_paths.append(str(py_path)) + # last option, if nothing else is found, just look next to ourselves... + if ( + own_location + and (Path(own_location).parent / "ansible").exists() + and str(Path(own_location).parent) not in paths + ): + inject_paths.append(str(Path(own_location).parent)) + if not os.environ.get("PYENV_VIRTUAL_ENV", None): if inject_paths: print( # noqa: T201