@@ -117,6 +117,9 @@ static const PyConfigSpec PYCONFIG_SPEC[] = {
117117 SPEC (_is_python_build , UINT ),
118118#ifdef Py_STATS
119119 SPEC (_pystats , UINT ),
120+ #endif
121+ #ifdef Py_DEBUG
122+ SPEC (run_presite , WSTR_OPT ),
120123#endif
121124 {NULL , 0 , 0 },
122125};
@@ -241,6 +244,11 @@ The following implementation-specific options are available:\n\
241244\n\
242245-X pystats: Enable pystats collection at startup."
243246#endif
247+ #ifdef Py_DEBUG
248+ "\n \
249+ \n \
250+ - X presite = package .module : import this module before site .py is run ."
251+ #endif
244252;
245253
246254/* Envvars that don't have equivalent command-line options are listed first */
@@ -790,6 +798,9 @@ PyConfig_Clear(PyConfig *config)
790798 CLEAR (config -> run_module );
791799 CLEAR (config -> run_filename );
792800 CLEAR (config -> check_hash_pycs_mode );
801+ #ifdef Py_DEBUG
802+ CLEAR (config -> run_presite );
803+ #endif
793804
794805 _PyWideStringList_Clear (& config -> orig_argv );
795806#undef CLEAR
@@ -1806,6 +1817,36 @@ config_init_pycache_prefix(PyConfig *config)
18061817}
18071818
18081819
1820+ #ifdef Py_DEBUG
1821+ static PyStatus
1822+ config_init_run_presite (PyConfig * config )
1823+ {
1824+ assert (config -> run_presite == NULL );
1825+
1826+ const wchar_t * xoption = config_get_xoption (config , L"presite" );
1827+ if (xoption ) {
1828+ const wchar_t * sep = wcschr (xoption , L'=' );
1829+ if (sep && wcslen (sep ) > 1 ) {
1830+ config -> run_presite = _PyMem_RawWcsdup (sep + 1 );
1831+ if (config -> run_presite == NULL ) {
1832+ return _PyStatus_NO_MEMORY ();
1833+ }
1834+ }
1835+ else {
1836+ // PYTHON_PRESITE env var ignored
1837+ // if "-X presite=" option is used
1838+ config -> run_presite = NULL ;
1839+ }
1840+ return _PyStatus_OK ();
1841+ }
1842+
1843+ return CONFIG_GET_ENV_DUP (config , & config -> run_presite ,
1844+ L"PYTHON_PRESITE" ,
1845+ "PYTHON_PRESITE" );
1846+ }
1847+ #endif
1848+
1849+
18091850static PyStatus
18101851config_read_complex_options (PyConfig * config )
18111852{
@@ -1861,6 +1902,16 @@ config_read_complex_options(PyConfig *config)
18611902 return status ;
18621903 }
18631904 }
1905+
1906+ #ifdef Py_DEBUG
1907+ if (config -> run_presite == NULL ) {
1908+ status = config_init_run_presite (config );
1909+ if (_PyStatus_EXCEPTION (status )) {
1910+ return status ;
1911+ }
1912+ }
1913+ #endif
1914+
18641915 return _PyStatus_OK ();
18651916}
18661917
0 commit comments