Skip to content

Commit

Permalink
Avoid warnings about PATH with pipx installations (#3920)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Nov 29, 2023
1 parent 90fb69a commit e4adbc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"); \
Expand Down

0 comments on commit e4adbc6

Please sign in to comment.