Skip to content

Commit 7a36850

Browse files
Docs & test
1 parent a0dd99b commit 7a36850

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Doc/using/configure.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,27 @@ General Options
255255

256256
.. versionadded:: 3.11
257257

258+
.. option:: --with-missing-stdlib-config=FILE
259+
260+
Path to a `JSON <https://www.json.org/json-en.html>`_ configuration file
261+
containing custom error messages for missing :term:`standard library` modules.
262+
263+
This option is intended for Python distributors who wish to provide
264+
distribution-specific guidance when users encounter missing standard library
265+
modules that are packaged separately.
266+
267+
The JSON file should map missing module names to custom error message strings.
268+
For example, a configuration for the :mod:`tkinter` module:
269+
270+
.. code-block::json
271+
272+
{
273+
"tkinter": "Install the python-tk package to use tkinter",
274+
"_tkinter": "Install the python-tk package to use tkinter"
275+
}
276+
277+
.. versionadded:: next
278+
258279
.. option:: --enable-pystats
259280

260281
Turn on internal Python performance statistics gathering.

Doc/whatsnew/3.15.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ Improved error messages
229229
AttributeError: 'Container' object has no attribute 'area'. Did you mean: 'inner.area'?
230230
231231
232+
* The new configure option :option:`--with-missing-stdlib-config=FILE` allows
233+
distributors to pass a `JSON <https://www.json.org/json-en.html>`_
234+
configuration file containing custom error messages for missing
235+
:term:`standard library` modules.
236+
237+
232238
Other language changes
233239
======================
234240

Lib/test/test_traceback.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5051,7 +5051,7 @@ def test_no_site_package_flavour(self):
50515051
b"or to enable your virtual environment?"), stderr
50525052
)
50535053

5054-
def test_missing_stdlib_package(self):
5054+
def test_missing_stdlib_module(self):
50555055
code = """
50565056
import sys
50575057
sys.stdlib_module_names |= {'spam'}
@@ -5061,6 +5061,17 @@ def test_missing_stdlib_package(self):
50615061

50625062
self.assertIn(b"Standard library module 'spam' was not found", stderr)
50635063

5064+
code = """
5065+
import sys
5066+
import traceback
5067+
traceback.MISSING_STDLIB_MODULE_MESSAGES = {'spam': 'Install 'spam4life' for 'spam''}
5068+
sys.stdlib_module_names |= {'spam'}
5069+
import spam
5070+
"""
5071+
_, _, stderr = assert_python_failure('-S', '-c', code)
5072+
5073+
self.assertIn(b"Install 'spam4life' for 'spam'", stderr)
5074+
50645075

50655076
class TestColorizedTraceback(unittest.TestCase):
50665077
maxDiff = None

0 commit comments

Comments
 (0)