Skip to content
Merged
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
5 changes: 5 additions & 0 deletions Doc/library/venv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ creation according to their needs, the :class:`EnvBuilder` class.

* ``lib_path`` - The purelib path for the virtual environment.

* ``platlib_path`` - The platlib path for the virtual environment.

* ``bin_path`` - The script path for the virtual environment.

* ``bin_name`` - The name of the script path relative to the virtual
Expand All @@ -431,6 +433,9 @@ creation according to their needs, the :class:`EnvBuilder` class.
The attribute ``lib_path`` was added to the context, and the context
object was documented.

.. versionchanged:: 3.15
The attribute ``platlib_path`` was added to the context.

.. method:: create_configuration(context)

Creates the ``pyvenv.cfg`` configuration file in the environment.
Expand Down
11 changes: 11 additions & 0 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,17 @@ unittest
(Contributed by Garry Cairns in :gh:`134567`.)


venv
----

* On POSIX platforms, platlib directories will be created if needed when
creating virtual environments, instead of using ``lib64 -> lib`` symlink.
This means purelib and platlib of virtual environments no longer share the
same ``lib`` directory on platforms where :data:`sys.platlibdir` is not
equal to ``lib``.
(Contributed by Rui Xi in :gh:`133951`.)


xml.parsers.expat
-----------------

Expand Down
16 changes: 14 additions & 2 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5034,7 +5034,8 @@ def test_no_site_package_flavour(self):

self.assertIn(
(b"Site initialization is disabled, did you forget to "
b"add the site-packages directory to sys.path?"), stderr
b"add the site-packages directory to sys.path "
b"or to enable your virtual environment?"), stderr
)

code = """
Expand All @@ -5046,9 +5047,20 @@ def test_no_site_package_flavour(self):

self.assertNotIn(
(b"Site initialization is disabled, did you forget to "
b"add the site-packages directory to sys.path?"), stderr
b"add the site-packages directory to sys.path "
b"or to enable your virtual environment?"), stderr
)

def test_missing_stdlib_package(self):
code = """
import sys
sys.stdlib_module_names |= {'spam'}
import spam
"""
_, _, stderr = assert_python_failure('-S', '-c', code)

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


class TestColorizedTraceback(unittest.TestCase):
maxDiff = None
Expand Down
13 changes: 8 additions & 5 deletions Lib/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,11 +1107,14 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
suggestion = _compute_suggestion_error(exc_value, exc_traceback, wrong_name)
if suggestion:
self._str += f". Did you mean: '{suggestion}'?"
elif exc_type and issubclass(exc_type, ModuleNotFoundError) and \
sys.flags.no_site and \
getattr(exc_value, "name", None) not in sys.stdlib_module_names:
self._str += (". Site initialization is disabled, did you forget to "
+ "add the site-packages directory to sys.path?")
elif exc_type and issubclass(exc_type, ModuleNotFoundError):
module_name = getattr(exc_value, "name", None)
if module_name in sys.stdlib_module_names:
self._str = f"Standard library module '{module_name}' was not found"
elif sys.flags.no_site:
self._str += (". Site initialization is disabled, did you forget to "
+ "add the site-packages directory to sys.path "
+ "or to enable your virtual environment?")
elif exc_type and issubclass(exc_type, (NameError, AttributeError)) and \
getattr(exc_value, "name", None) is not None:
wrong_name = getattr(exc_value, "name", None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix memory leaks in :mod:`readline` functions
:func:`~readline.read_init_file`, :func:`~readline.read_history_file`,
:func:`~readline.write_history_file`, and
:func:`~readline.append_history_file` when :c:func:`PySys_Audit` fails.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve :exc:`ModuleNotFoundError` error message when a :term:`standard library`
module is missing.
4 changes: 4 additions & 0 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ readline_read_init_file_impl(PyObject *module, PyObject *filename_obj)
if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
return NULL;
if (PySys_Audit("open", "OCi", filename_obj, 'r', 0) < 0) {
Py_DECREF(filename_bytes);
return NULL;
}
errno = rl_read_init_file(PyBytes_AS_STRING(filename_bytes));
Expand Down Expand Up @@ -298,6 +299,7 @@ readline_read_history_file_impl(PyObject *module, PyObject *filename_obj)
if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
return NULL;
if (PySys_Audit("open", "OCi", filename_obj, 'r', 0) < 0) {
Py_DECREF(filename_bytes);
return NULL;
}
errno = read_history(PyBytes_AS_STRING(filename_bytes));
Expand Down Expand Up @@ -343,6 +345,7 @@ readline_write_history_file_impl(PyObject *module, PyObject *filename_obj)
return NULL;
filename = PyBytes_AS_STRING(filename_bytes);
if (PySys_Audit("open", "OCi", filename_obj, 'w', 0) < 0) {
Py_DECREF(filename_bytes);
return NULL;
}
} else {
Expand Down Expand Up @@ -400,6 +403,7 @@ readline_append_history_file_impl(PyObject *module, int nelements,
return NULL;
filename = PyBytes_AS_STRING(filename_bytes);
if (PySys_Audit("open", "OCi", filename_obj, 'a', 0) < 0) {
Py_DECREF(filename_bytes);
return NULL;
}
} else {
Expand Down
Loading