Skip to content

Commit

Permalink
Look for ansible binary in the same path the linter (#3903)
Browse files Browse the repository at this point in the history
  • Loading branch information
FliegenKLATSCH committed Nov 29, 2023
1 parent b0b1e69 commit 90fb69a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ansiblelint/__main__.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 90fb69a

Please sign in to comment.