@@ -427,13 +427,13 @@ def path_inject(own_location: str = "") -> None:
427
427
#
428
428
# This must be run before we do run any subprocesses, and loading config
429
429
# does this as part of the ansible detection.
430
- paths = [x for x in os .environ .get ("PATH" , "" ).split (os .pathsep ) if x ]
430
+ paths = [Path ( x ) for x in os .environ .get ("PATH" , "" ).split (os .pathsep ) if x ]
431
431
432
432
# Expand ~ in PATH as it known to break many tools
433
433
expanded = False
434
434
for idx , path in enumerate (paths ):
435
- if path .startswith ("~" ): # pragma: no cover
436
- paths [idx ] = str ( Path (path ).expanduser () )
435
+ if str ( path ) .startswith ("~" ): # pragma: no cover
436
+ paths [idx ] = Path (path ).expanduser ()
437
437
expanded = True
438
438
if expanded : # pragma: no cover
439
439
print ( # noqa: T201
@@ -446,35 +446,37 @@ def path_inject(own_location: str = "") -> None:
446
446
userbase_bin_path = Path (site .getuserbase ()) / "bin"
447
447
448
448
if (
449
- str ( userbase_bin_path ) not in paths
449
+ userbase_bin_path not in paths
450
450
and (userbase_bin_path / "bin" / "ansible" ).exists ()
451
451
):
452
- inject_paths .append (str ( userbase_bin_path ) )
452
+ inject_paths .append (userbase_bin_path )
453
453
454
454
py_path = Path (sys .executable ).parent
455
455
pipx_path = os .environ .get ("PIPX_HOME" , "pipx" )
456
456
if (
457
- str ( py_path ) not in paths
457
+ py_path not in paths
458
458
and (py_path / "ansible" ).exists ()
459
459
and pipx_path not in str (py_path )
460
460
):
461
- inject_paths .append (str ( py_path ) )
461
+ inject_paths .append (py_path )
462
462
463
463
# last option, if nothing else is found, just look next to ourselves...
464
464
if own_location :
465
465
own_location = os .path .realpath (own_location )
466
466
parent = Path (own_location ).parent
467
- if (parent / "ansible" ).exists () and str ( parent ) not in paths :
468
- inject_paths .append (str ( parent ) )
467
+ if (parent / "ansible" ).exists () and parent not in paths :
468
+ inject_paths .append (parent )
469
469
470
- if not os .environ .get ("PYENV_VIRTUAL_ENV" , None ):
471
- if inject_paths and not all ("pipx" in p for p in inject_paths ):
470
+ if not os .environ .get ("PYENV_VIRTUAL_ENV" ):
471
+ if inject_paths and not all ("pipx" in str ( p ) for p in inject_paths ):
472
472
print ( # noqa: T201
473
- f"WARNING: PATH altered to include { ', ' .join (inject_paths )} :: This is usually a sign of broken local setup, which can cause unexpected behaviors." ,
473
+ f"WARNING: PATH altered to include { ', ' .join (map ( str , inject_paths ) )} :: This is usually a sign of broken local setup, which can cause unexpected behaviors." ,
474
474
file = sys .stderr ,
475
475
)
476
476
if inject_paths or expanded :
477
- os .environ ["PATH" ] = os .pathsep .join ([* inject_paths , * paths ])
477
+ os .environ ["PATH" ] = os .pathsep .join (
478
+ [* map (str , inject_paths ), * map (str , paths )],
479
+ )
478
480
479
481
# We do know that finding ansible in PATH does not guarantee that it is
480
482
# functioning or that is in fact the same version that was installed as
0 commit comments