]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/_distutils/spawn.py
3 Provides the 'spawn()' function, a front-end to various platform-
4 specific functions for launching another program in a sub-process.
5 Also provides the 'find_executable()' to search the path for a given
13 from .errors
import DistutilsExecError
14 from .debug
import DEBUG
18 def spawn(cmd
, search_path
=1, verbose
=0, dry_run
=0, env
=None): # noqa: C901
19 """Run another program, specified as a command list 'cmd', in a new process.
21 'cmd' is just the argument list for the new process, ie.
22 cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
23 There is no way to run a program with a name different from that of its
26 If 'search_path' is true (the default), the system's executable
27 search path will be used to find the program; otherwise, cmd[0]
28 must be the exact path to the executable. If 'dry_run' is true,
29 the command will not actually be run.
31 Raise DistutilsExecError if running the program fails in any way; just
34 # cmd is documented as a list, but just in case some code passes a tuple
35 # in, protect our %-formatting code against horrible death
38 log
.info(subprocess
.list2cmdline(cmd
))
43 executable
= find_executable(cmd
[0])
44 if executable
is not None:
47 env
= env
if env
is not None else dict(os
.environ
)
49 if sys
.platform
== 'darwin':
50 from distutils
.util
import MACOSX_VERSION_VAR
, get_macosx_target_ver
52 macosx_target_ver
= get_macosx_target_ver()
54 env
[MACOSX_VERSION_VAR
] = macosx_target_ver
57 proc
= subprocess
.Popen(cmd
, env
=env
)
59 exitcode
= proc
.returncode
60 except OSError as exc
:
63 raise DistutilsExecError(
64 "command {!r} failed: {}".format(cmd
, exc
.args
[-1])
70 raise DistutilsExecError(
71 "command {!r} failed with exit code {}".format(cmd
, exitcode
)
75 def find_executable(executable
, path
=None):
76 """Tries to find 'executable' in the directories listed in 'path'.
78 A string listing directories separated by 'os.pathsep'; defaults to
79 os.environ['PATH']. Returns the complete filename or None if not found.
81 _
, ext
= os
.path
.splitext(executable
)
82 if (sys
.platform
== 'win32') and (ext
!= '.exe'):
83 executable
= executable
+ '.exe'
85 if os
.path
.isfile(executable
):
89 path
= os
.environ
.get('PATH', None)
92 path
= os
.confstr("CS_PATH")
93 except (AttributeError, ValueError):
94 # os.confstr() or CS_PATH is not available
96 # bpo-35755: Don't use os.defpath if the PATH environment variable is
97 # set to an empty string
99 # PATH='' doesn't match, whereas PATH=':' looks in the current directory
103 paths
= path
.split(os
.pathsep
)
105 f
= os
.path
.join(p
, executable
)
106 if os
.path
.isfile(f
):
107 # the file exists, we have a shot at spawn working