Executes an externally spawned Python interpreter. If capture_stdout is set to True, returns anything that was emitted in the standard output as a single string. Otherwise, returns the exit code.
(cmd, env=None, capture_stdout=True)
| 43 | |
| 44 | |
| 45 | def __exec_python_cmd(cmd, env=None, capture_stdout=True): |
| 46 | """ |
| 47 | Executes an externally spawned Python interpreter. If capture_stdout is set to True, returns anything that was |
| 48 | emitted in the standard output as a single string. Otherwise, returns the exit code. |
| 49 | """ |
| 50 | # 'PyInstaller.config' cannot be imported as other top-level modules. |
| 51 | from PyInstaller.config import CONF |
| 52 | if env is None: |
| 53 | env = {} |
| 54 | # Update environment. Defaults to 'os.environ' |
| 55 | pp_env = copy.deepcopy(os.environ) |
| 56 | pp_env.update(env) |
| 57 | # Prepend PYTHONPATH with pathex. |
| 58 | # Some functions use some PyInstaller code in subprocess, so add PyInstaller HOMEPATH to sys.path as well. |
| 59 | pp = os.pathsep.join(CONF['pathex'] + [HOMEPATH]) |
| 60 | |
| 61 | # PYTHONPATH might be already defined in the 'env' argument or in the original 'os.environ'. Prepend it. |
| 62 | if 'PYTHONPATH' in pp_env: |
| 63 | pp = os.pathsep.join([pp_env.get('PYTHONPATH'), pp]) |
| 64 | pp_env['PYTHONPATH'] = pp |
| 65 | |
| 66 | if capture_stdout: |
| 67 | txt = compat.exec_python(*cmd, env=pp_env) |
| 68 | return txt.strip() |
| 69 | else: |
| 70 | return compat.exec_python_rc(*cmd, env=pp_env) |
| 71 | |
| 72 | |
| 73 | def __exec_statement(statement, capture_stdout=True): |
no test coverage detected
searching dependent graphs…