From c8bfc1d5140d39654e1dd92ee4a6a9e66f9e1758 Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 21 Jul 2026 17:24:01 +0200 Subject: [PATCH 1/2] PEP 383: Add `python-version` to `pyvenv.cfg` Draft PR accompanying [PEP 838](https://peps.python.org/pep-0838/) --- Lib/test/test_venv.py | 3 +++ Lib/venv/__init__.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 58ae85fb268042e..e7d5e890c1c31a4 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -146,6 +146,9 @@ def _check_output_of_default_create(self): self.assertIn('home = %s' % path, data) self.assertIn('executable = %s' % os.path.realpath(sys.executable), data) + self.assertIn("python-version = %d.%d" % (sys.version_info.major, + sys.version_info.minor), + data) copies = '' if os.name=='nt' else ' --copies' cmd = (f'command = {sys.executable} -m venv{copies} --without-pip ' f'--without-scm-ignore-files {self.env_dir}') diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index bd2762d55ef6961..0a96d11cb9baa3e 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -232,6 +232,8 @@ def create_configuration(self, context): incl = 'false' f.write('include-system-site-packages = %s\n' % incl) f.write('version = %d.%d.%d\n' % sys.version_info[:3]) + f.write('python-version = %d.%d\n' % (sys.version_info.major, + sys.version_info.minor)) if self.prompt is not None: f.write(f'prompt = {self.prompt!r}\n') f.write('executable = %s\n' % os.path.realpath(sys.executable)) From 2856a2ecac18d7cb16534c8fb434161440be430e Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 21 Jul 2026 17:30:12 +0200 Subject: [PATCH 2/2] A newsfragment --- .../next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst b/Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst new file mode 100644 index 000000000000000..e760a6f436bd11f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-21-17-29-19.gh-issue-154377.pep838.rst @@ -0,0 +1,2 @@ +Add a ``python-version`` key to ``pyvenv.cfg`` files created by :mod:`venv`. +This implements :pep:`838`.