Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,13 @@ Miscellaneous options

.. versionadded:: 3.14

* :samp:`-X pathconfig_warnings={0,1}` if true (``1``) then
:ref:`sys-path-init` is allowed to log warnings into stderr.
If false (``0``) suppress these warnings. Set to true by default.
See also :envvar:`PYTHON_PATHCONFIG_WARNINGS`.

.. versionadded:: next

* :samp:`-X tlbc={0,1}` enables (1, the default) or disables (0) thread-local
bytecode in builds configured with :option:`--disable-gil`. When disabled,
this also disables the specializing interpreter. See also
Expand Down Expand Up @@ -1350,6 +1357,14 @@ conflict.

.. versionadded:: 3.14

.. envvar:: PYTHON_PATHCONFIG_WARNINGS

If true (``1``) then :ref:`sys-path-init` is allowed to log warnings into
stderr. If false (``0``) suppress these warnings. Set to true by default.
See also :option:`-X pathconfig_warnings<-X>`.

.. versionadded:: next

.. envvar:: PYTHON_JIT

On builds where experimental just-in-time compilation is available, this
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added the :option:`-X pathconfig_warnings<-X>` and
:envvar:`PYTHON_PATHCONFIG_WARNINGS` options, allowing to disable warnings
from :ref:`sys-path-init`.
34 changes: 34 additions & 0 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ The following implementation-specific options are available:\n\
use module globals, which is not concurrent-safe; set to true for\n\
free-threaded builds and false otherwise; also\n\
PYTHON_CONTEXT_AWARE_WARNINGS\n\
-X pathconfig_warnings=[0|1]: if true (1) then path configuration is allowed\n\
to log warnings into stderr; if false (0) suppress these warnings;\n\
set to true by default; also PYTHON_PATHCONFIG_WARNINGS\n\
-X tracemalloc[=N]: trace Python memory allocations; N sets a traceback limit\n \
of N frames (default: 1); also PYTHONTRACEMALLOC=N\n\
-X utf8[=0|1]: enable (1) or disable (0) UTF-8 mode; also PYTHONUTF8\n\
Expand Down Expand Up @@ -2350,6 +2353,32 @@ config_init_lazy_imports(PyConfig *config)
return _PyStatus_OK();
}

static PyStatus
config_init_pathconfig_warnings(PyConfig *config)
{
const char *env = config_get_env(config, "PYTHON_PATHCONFIG_WARNINGS");
if (env) {
int enabled;
if (_Py_str_to_int(env, &enabled) < 0 || (enabled < 0) || (enabled > 1)) {
return _PyStatus_ERR(
"PYTHON_PATHCONFIG_WARNINGS=N: N is missing or invalid");
}
config->pathconfig_warnings = enabled;
}

const wchar_t *xoption = config_get_xoption(config, L"pathconfig_warnings");
if (xoption) {
int enabled;
const wchar_t *sep = wcschr(xoption, L'=');
if (!sep || (config_wstr_to_int(sep + 1, &enabled) < 0) || (enabled < 0) || (enabled > 1)) {
return _PyStatus_ERR(
"-X pathconfig_warnings=n: n is missing or invalid");
}
config->pathconfig_warnings = enabled;
}
return _PyStatus_OK();
}

static PyStatus
config_read_complex_options(PyConfig *config)
{
Expand Down Expand Up @@ -2446,6 +2475,11 @@ config_read_complex_options(PyConfig *config)
return status;
}

status = config_init_pathconfig_warnings(config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}

return _PyStatus_OK();
}

Expand Down
Loading