bpo-45211: Remember the stdlib dir during startup. (gh-28586)

During runtime startup we figure out the stdlib dir but currently throw that information away. This change preserves it and exposes it via PyConfig.stdlib_dir, _Py_GetStdlibDir(), and sys._stdlib_dir.

https://bugs.python.org/issue45211
This commit is contained in:
Eric Snow 2021-09-28 12:18:28 -06:00 committed by GitHub
parent 84975146a7
commit 0c50b8c0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 93 additions and 3 deletions

View file

@ -13,6 +13,7 @@ from test import support
from test.support import os_helper
from test.support.script_helper import assert_python_ok, assert_python_failure
from test.support import threading_helper
from test.support import import_helper
import textwrap
import unittest
import warnings
@ -994,6 +995,15 @@ class SysModuleTest(unittest.TestCase):
for name in sys.stdlib_module_names:
self.assertIsInstance(name, str)
def test_stdlib_dir(self):
os = import_helper.import_fresh_module('os')
marker = getattr(os, '__file__', None)
if marker and not os.path.exists(marker):
marker = None
expected = os.path.dirname(marker) if marker else None
actual = sys._stdlib_dir
self.assertEqual(actual, expected)
@test.support.cpython_only
class UnraisableHookTest(unittest.TestCase):