Skip to content

Commit

Permalink
Look for ansible binary in the same path as we are
Browse files Browse the repository at this point in the history
  • Loading branch information
FliegenKLATSCH committed Nov 28, 2023
1 parent 634c639 commit ff7b3d6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,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 is None: # pragma: no cover
argv = sys.argv
Expand Down Expand Up @@ -399,7 +399,7 @@ def _run_cli_entrypoint() -> None:
raise SystemExit(exc) from exc


def path_inject() -> None:
def path_inject(own_location: str = None) -> 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 @@ -440,6 +440,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 ff7b3d6

Please sign in to comment.