Execute a command in a sub-process. Parameters ---------- cmd : str The command to execute. display : str or sequence of str, optional The text to add to the log file kept by `numpy.distutils`. If not given, `display` is equal to `cmd`. env : a dicti
(self, cmd, display=None, env=None)
| 112 | |
| 113 | # Using customized CCompiler.spawn. |
| 114 | def CCompiler_spawn(self, cmd, display=None, env=None): |
| 115 | """ |
| 116 | Execute a command in a sub-process. |
| 117 | |
| 118 | Parameters |
| 119 | ---------- |
| 120 | cmd : str |
| 121 | The command to execute. |
| 122 | display : str or sequence of str, optional |
| 123 | The text to add to the log file kept by `numpy.distutils`. |
| 124 | If not given, `display` is equal to `cmd`. |
| 125 | env : a dictionary for environment variables, optional |
| 126 | |
| 127 | Returns |
| 128 | ------- |
| 129 | None |
| 130 | |
| 131 | Raises |
| 132 | ------ |
| 133 | DistutilsExecError |
| 134 | If the command failed, i.e. the exit status was not 0. |
| 135 | |
| 136 | """ |
| 137 | env = env if env is not None else dict(os.environ) |
| 138 | if display is None: |
| 139 | display = cmd |
| 140 | if is_sequence(display): |
| 141 | display = ' '.join(list(display)) |
| 142 | log.info(display) |
| 143 | try: |
| 144 | if self.verbose: |
| 145 | subprocess.check_output(cmd, env=env) |
| 146 | else: |
| 147 | subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) |
| 148 | except subprocess.CalledProcessError as exc: |
| 149 | o = exc.output |
| 150 | s = exc.returncode |
| 151 | except OSError as e: |
| 152 | # OSError doesn't have the same hooks for the exception |
| 153 | # output, but exec_command() historically would use an |
| 154 | # empty string for EnvironmentError (base class for |
| 155 | # OSError) |
| 156 | # o = b'' |
| 157 | # still that would make the end-user lost in translation! |
| 158 | o = f"\n\n{e}\n\n\n" |
| 159 | try: |
| 160 | o = o.encode(sys.stdout.encoding) |
| 161 | except AttributeError: |
| 162 | o = o.encode('utf8') |
| 163 | # status previously used by exec_command() for parent |
| 164 | # of OSError |
| 165 | s = 127 |
| 166 | else: |
| 167 | # use a convenience return here so that any kind of |
| 168 | # caught exception will execute the default code after the |
| 169 | # try / except block, which handles various exceptions |
| 170 | return None |
| 171 |
nothing calls this directly
no test coverage detected