MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_exec_path

Function get_exec_path

Lib/os.py:649–690  ·  view source on GitHub ↗

Returns the sequence of directories that will be searched for the named executable (similar to a shell) when launching a process. *env* must be an environment variable dict or None. If *env* is None, os.environ will be used.

(env=None)

Source from the content-addressed store, hash-verified

647
648
649def get_exec_path(env=None):
650 """Returns the sequence of directories that will be searched for the
651 named executable (similar to a shell) when launching a process.
652
653 *env* must be an environment variable dict or None. If *env* is None,
654 os.environ will be used.
655 """
656 # Use a local import instead of a global import to limit the number of
657 # modules loaded at startup: the os module is always loaded at startup by
658 # Python. It may also avoid a bootstrap issue.
659 import warnings
660
661 if env is None:
662 env = environ
663
664 # {b'PATH': ...}.get('PATH') and {'PATH': ...}.get(b'PATH') emit a
665 # BytesWarning when using python -b or python -bb: ignore the warning
666 with warnings.catch_warnings():
667 warnings.simplefilter("ignore", BytesWarning)
668
669 try:
670 path_list = env.get('PATH')
671 except TypeError:
672 path_list = None
673
674 if supports_bytes_environ:
675 try:
676 path_listb = env[b'PATH']
677 except (KeyError, TypeError):
678 pass
679 else:
680 if path_list is not None:
681 raise ValueError(
682 "env cannot contain 'PATH' and b'PATH' keys")
683 path_list = path_listb
684
685 if path_list is not None and isinstance(path_list, bytes):
686 path_list = fsdecode(path_list)
687
688 if path_list is None:
689 path_list = defpath
690 return path_list.split(pathsep)
691
692
693# Change environ to automatically call putenv() and unsetenv()

Callers 1

_execvpeFunction · 0.85

Calls 4

isinstanceFunction · 0.85
fsdecodeFunction · 0.85
getMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected