out = res.out.strip().decode("utf-8")
return tuple(int(i) for i in out.split())
+ def test_dump_path_config(self):
+ # gh-151253: At the first import (import encodings) during Python
+ # startup, if the import fails, dump the Python path configuration.
+ nonexistent = '/nonexistent-python-path'
+ # Use -X frozen_modules=off to disable frozen encodings module
+ # on release build.
+ cmd = ["-X", "frozen_modules=off", "-c", "pass"]
+ proc = assert_python_failure(*cmd, PYTHONHOME=nonexistent)
+ self.assertIn(b'Python path configuration:', proc.err)
+ self.assertIn(f"PYTHONHOME = '{nonexistent}'".encode(), proc.err)
+
@unittest.skipIf(interpreter_requires_environment(),
'Cannot run -I tests when PYTHON env vars are required.')
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
+#include "pycore_initconfig.h" // _Py_DumpPathConfig()
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
#include "pycore_lock.h" // PyMutex
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
// search functions, so this is done after everything else is initialized.
PyObject *mod = PyImport_ImportModule("encodings");
if (mod == NULL) {
+ PyThreadState *tstate = _PyThreadState_GET();
+ _Py_DumpPathConfig(tstate);
return PyStatus_Error("Failed to import encodings module");
}
Py_DECREF(mod);