From e4adbc6f5a0417261f35b3f7bd8cdaf158001c07 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 29 Nov 2023 14:58:05 +0000 Subject: [PATCH] Avoid warnings about PATH with pipx installations (#3920) --- src/ansiblelint/__main__.py | 3 ++- tox.ini | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ansiblelint/__main__.py b/src/ansiblelint/__main__.py index d3f48e49cf..c567237a4d 100755 --- a/src/ansiblelint/__main__.py +++ b/src/ansiblelint/__main__.py @@ -452,6 +452,7 @@ def path_inject(own_location: str = "") -> None: inject_paths.append(str(py_path)) # last option, if nothing else is found, just look next to ourselves... + own_location = os.path.realpath(own_location) if ( own_location and (Path(own_location).parent / "ansible").exists() @@ -460,7 +461,7 @@ def path_inject(own_location: str = "") -> None: inject_paths.append(str(Path(own_location).parent)) if not os.environ.get("PYENV_VIRTUAL_ENV", None): - if inject_paths: + if inject_paths and not all("pipx" in p for p in inject_paths): print( # noqa: T201 f"WARNING: PATH altered to include {', '.join(inject_paths)} :: This is usually a sign of broken local setup, which can cause unexpected behaviors.", file=sys.stderr, diff --git a/tox.ini b/tox.ini index b75b7e0144..b19a4beb2c 100644 --- a/tox.ini +++ b/tox.ini @@ -80,6 +80,7 @@ allowlist_externals = sh tox ./tools/test-hook.sh + {toxworkdir}/.pipx/bin/ansible-lint # https://tox.wiki/en/latest/upgrading.html#editable-mode package = editable @@ -191,10 +192,15 @@ description = deps = build >= 0.9.0 twine >= 4.0.1 + pipx skip_install = true # Ref: https://twitter.com/di_codes/status/1044358639081975813 commands_pre = commands = + # Testing pipx usage + bash -c "PIPX_BIN_DIR={toxworkdir}/.pipx/bin PIPX_HOME={toxworkdir}/.pipx pipx install --force -e ." + # Testing that calling the pipx installation does return 0 return code and no output in stderr + bash -c "if stderr=$({toxworkdir}/.pipx/bin/ansible-lint --version >/dev/null) && test -z \"$stderr\"; then echo "ok"; fi" # build wheel and sdist using PEP-517 {envpython} -c 'import os.path, shutil, sys; \ dist_dir = os.path.join("{toxinidir}", "dist"); \