Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for ansible binary in the same path as we are #3903

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 and argv[0] else "")

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:
"""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