88import logging
99import os
1010import re
11+ import shutil
1112import subprocess
1213import sys
1314import typing as t
@@ -203,14 +204,6 @@ class tmux_cmd:
203204 """
204205 :term:`tmux(1)` command via :py:mod:`subprocess`.
205206
206- Parameters
207- ----------
208- tmux_search_paths : list, optional
209- Default PATHs to search tmux for, defaults to ``default_paths`` used
210- in :func:`which`.
211- append_env_path : bool
212- Append environment PATHs to tmux search paths. True by default.
213-
214207 Examples
215208 --------
216209
@@ -239,14 +232,7 @@ class tmux_cmd:
239232 """
240233
241234 def __init__ (self , * args : t .Any , ** kwargs : t .Any ) -> None :
242- tmux_bin = which (
243- "tmux" ,
244- default_paths = kwargs .get (
245- "tmux_search_paths" ,
246- ["/bin" , "/sbin" , "/usr/bin" , "/usr/sbin" , "/usr/local/bin" ],
247- ),
248- append_env_path = kwargs .get ("append_env_path" , True ),
249- )
235+ tmux_bin = shutil .which ("tmux" )
250236 if not tmux_bin :
251237 raise (exc .TmuxCommandNotFound )
252238
@@ -461,73 +447,6 @@ def get_by_id(self, id: str) -> Optional[O]:
461447 return None
462448
463449
464- def which (
465- exe : str ,
466- default_paths : t .List [str ] = [
467- "/bin" ,
468- "/sbin" ,
469- "/usr/bin" ,
470- "/usr/sbin" ,
471- "/usr/local/bin" ,
472- ],
473- append_env_path : bool = True ,
474- ) -> t .Optional [str ]:
475- """
476- Return path of bin. Python clone of /usr/bin/which.
477-
478- Parameters
479- ----------
480- exe : str
481- Application to search PATHs for.
482- default_paths : list
483- Paths to check inside of
484- append_env_path : bool, optional
485- Append list of directories to check in from PATH environment variable.
486- Default True. Setting False only for testing / diagnosing.
487-
488- Returns
489- -------
490- str
491- path of application, if found in paths.
492-
493- Notes
494- -----
495- from salt.util - https://www.github.com/saltstack/salt - license apache
496- """
497-
498- def _is_executable_file_or_link (exe : str ) -> bool :
499- # check for os.X_OK doesn't suffice because directory may executable
500- return os .access (exe , os .X_OK ) and (os .path .isfile (exe ) or os .path .islink (exe ))
501-
502- if _is_executable_file_or_link (exe ):
503- # executable in cwd or fullpath
504- return exe
505-
506- # Enhance POSIX path for the reliability at some environments, when
507- # $PATH is changing. This also keeps order, where 'first came, first
508- # win' for cases to find optional alternatives
509- if append_env_path :
510- search_path = (
511- os .environ .get ("PATH" ) and os .environ ["PATH" ].split (os .pathsep ) or list ()
512- )
513- else :
514- search_path = []
515-
516- for default_path in default_paths :
517- if default_path not in search_path :
518- search_path .append (default_path )
519- for path in search_path :
520- full_path = os .path .join (path , exe )
521- if _is_executable_file_or_link (full_path ):
522- return full_path
523- logger .info (
524- "'{}' could not be found in the following search path: "
525- "'{}'" .format (exe , search_path )
526- )
527-
528- return None
529-
530-
531450def get_version () -> LooseVersion :
532451 """
533452 Return tmux version.
@@ -541,7 +460,7 @@ def get_version() -> LooseVersion:
541460 Returns
542461 -------
543462 :class:`distutils.version.LooseVersion`
544- tmux version according to :func:`libtmux.common .which`'s tmux
463+ tmux version according to :func:`shtuil .which`'s tmux
545464 """
546465 proc = tmux_cmd ("-V" )
547466 if proc .stderr :
0 commit comments